View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    https://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.api.ldap.model.schema.registries;
21  
22  
23  import java.util.Iterator;
24  import java.util.Map;
25  
26  import org.apache.directory.api.i18n.I18n;
27  import org.apache.directory.api.ldap.model.exception.LdapException;
28  import org.apache.directory.api.ldap.model.exception.LdapNoSuchAttributeException;
29  import org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException;
30  import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
31  import org.apache.directory.api.ldap.model.schema.AttributeType;
32  import org.apache.directory.api.ldap.model.schema.SchemaObjectType;
33  import org.apache.directory.api.ldap.model.schema.normalizers.OidNormalizer;
34  
35  
36  /**
37   * An immutable wrapper of the AttributeType registry.
38   *
39   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
40   */
41  public class ImmutableAttributeTypeRegistry implements AttributeTypeRegistry
42  {
43      /** The wrapped AttributeType registry */
44      AttributeTypeRegistry immutableAttributeTypeRegistry;
45  
46  
47      /**
48       * Creates a new instance of ImmutableAttributeTypeRegistry.
49       *
50       * @param attributeTypeRegistry The wrapped AttributeType registry
51       */
52      public ImmutableAttributeTypeRegistry( AttributeTypeRegistry attributeTypeRegistry )
53      {
54          immutableAttributeTypeRegistry = attributeTypeRegistry;
55      }
56  
57  
58      /**
59       * {@inheritDoc}
60       */
61      @Override
62      public Map<String, OidNormalizer> getNormalizerMapping()
63      {
64          return immutableAttributeTypeRegistry.getNormalizerMapping();
65      }
66  
67  
68      /**
69       * {@inheritDoc}
70       */
71      @Override
72  public boolean hasDescendants( String ancestorId ) throws LdapException
73      {
74          return immutableAttributeTypeRegistry.hasDescendants( ancestorId );
75      }
76  
77  
78      /**
79       * {@inheritDoc}
80       */
81      @Override
82      public boolean hasDescendants( AttributeType ancestor ) throws LdapException
83      {
84          return immutableAttributeTypeRegistry.hasDescendants( ancestor );
85      }
86  
87  
88      /**
89       * {@inheritDoc}
90       */
91      @Override
92      public Iterator<AttributeType> descendants( String ancestorId ) throws LdapException
93      {
94          return immutableAttributeTypeRegistry.descendants( ancestorId );
95      }
96  
97  
98      /**
99       * {@inheritDoc}
100      */
101     @Override
102     public Iterator<AttributeType> descendants( AttributeType ancestor ) throws LdapException
103     {
104         return immutableAttributeTypeRegistry.descendants( ancestor );
105     }
106 
107 
108     /**
109      * {@inheritDoc}
110      */
111     @Override
112     public void register( AttributeType attributeType ) throws LdapException
113     {
114         throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_13701_CANNOT_MODIFY_AT_REGISTRY_COPY ) );
115     }
116 
117 
118     /**
119      * {@inheritDoc}
120      */
121     @Override
122     public void registerDescendants( AttributeType attributeType, AttributeType ancestor ) throws LdapException
123     {
124         throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_13701_CANNOT_MODIFY_AT_REGISTRY_COPY ) );
125     }
126 
127 
128     /**
129      * {@inheritDoc}
130      */
131     @Override
132     public void unregisterDescendants( AttributeType attributeType, AttributeType ancestor ) throws LdapException
133     {
134         throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_13701_CANNOT_MODIFY_AT_REGISTRY_COPY ) );
135     }
136 
137 
138     /**
139      * {@inheritDoc}
140      */
141     @Override
142     public AttributeType unregister( String numericOid ) throws LdapException
143     {
144         throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION,
145             I18n.err( I18n.ERR_13701_CANNOT_MODIFY_AT_REGISTRY_COPY ) );
146     }
147 
148 
149     /**
150      * {@inheritDoc}
151      */
152     @Override
153     public void addMappingFor( AttributeType attributeType ) throws LdapException
154     {
155         throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, 
156             I18n.err( I18n.ERR_13701_CANNOT_MODIFY_AT_REGISTRY_COPY ) );
157     }
158 
159 
160     /**
161      * {@inheritDoc}
162      */
163     @Override
164     public void removeMappingFor( AttributeType attributeType ) throws LdapException
165     {
166         throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_13701_CANNOT_MODIFY_AT_REGISTRY_COPY ) );
167     }
168 
169 
170     /**
171      * {@inheritDoc}
172      */
173     @Override
174     public AttributeType lookup( String oid ) throws LdapException
175     {
176         return immutableAttributeTypeRegistry.lookup( oid );
177     }
178 
179 
180     /**
181      * {@inheritDoc}
182      */
183     @Override
184     public String toString()
185     {
186         return immutableAttributeTypeRegistry.toString();
187     }
188 
189 
190     /**
191      * {@inheritDoc}
192      */
193     @Override
194     public AttributeTypeRegistry copy()
195     {
196         return immutableAttributeTypeRegistry.copy();
197     }
198 
199 
200     /**
201      * {@inheritDoc}
202      */
203     @Override
204     public int size()
205     {
206         return immutableAttributeTypeRegistry.size();
207     }
208 
209 
210     /**
211      * {@inheritDoc}
212      */
213     @Override
214     public Iterator<AttributeType> iterator()
215     {
216         return immutableAttributeTypeRegistry.iterator();
217     }
218 
219 
220     /**
221      * {@inheritDoc}
222      */
223     @Override
224     public Iterator<String> oidsIterator()
225     {
226         return immutableAttributeTypeRegistry.oidsIterator();
227     }
228 
229 
230     /**
231      * {@inheritDoc}
232      */
233     @Override
234     public boolean contains( String oid )
235     {
236         return immutableAttributeTypeRegistry.contains( oid );
237     }
238 
239 
240     /**
241      * {@inheritDoc}
242      */
243     @Override
244     public String getOidByName( String name ) throws LdapException
245     {
246         try
247         {
248             return immutableAttributeTypeRegistry.getOidByName( name );
249         }
250         catch ( LdapException le )
251         {
252             throw new LdapNoSuchAttributeException( le.getMessage(), le );
253         }
254     }
255 
256 
257     /**
258      * {@inheritDoc}
259      */
260     @Override
261     public String getSchemaName( String oid ) throws LdapException
262     {
263         return immutableAttributeTypeRegistry.getSchemaName( oid );
264     }
265 
266 
267     /**
268      * {@inheritDoc}
269      */
270     @Override
271     public SchemaObjectType getType()
272     {
273         return immutableAttributeTypeRegistry.getType();
274     }
275 
276 
277     /**
278      * {@inheritDoc}
279      */
280     @Override
281     public void renameSchema( String originalSchemaName, String newSchemaName )
282     {
283         // Do nothing
284     }
285 
286 
287     /**
288      * {@inheritDoc}
289      */
290     @Override
291     public void unregisterSchemaElements( String schemaName ) throws LdapException
292     {
293         throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_13701_CANNOT_MODIFY_AT_REGISTRY_COPY ) );
294     }
295 
296 
297     /**
298      * {@inheritDoc}
299      */
300     @Override
301     public AttributeType get( String oid )
302     {
303         return immutableAttributeTypeRegistry.get( oid );
304     }
305 
306 
307     /**
308      * {@inheritDoc}
309      */
310     @Override
311     public void clear() throws LdapException
312     {
313         throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_13701_CANNOT_MODIFY_AT_REGISTRY_COPY ) );
314     }
315 
316 
317     /**
318      * {@inheritDoc}
319      */
320     @Override
321     public AttributeType unregister( AttributeType schemaObject ) throws LdapException
322     {
323         throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_13701_CANNOT_MODIFY_AT_REGISTRY_COPY ) );
324     }
325 }