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   *    http://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      public Map<String, OidNormalizer> getNormalizerMapping()
62      {
63          return immutableAttributeTypeRegistry.getNormalizerMapping();
64      }
65  
66  
67      /**
68       * {@inheritDoc}
69       */
70      public boolean hasDescendants( String ancestorId ) throws LdapException
71      {
72          return immutableAttributeTypeRegistry.hasDescendants( ancestorId );
73      }
74  
75  
76      /**
77       * {@inheritDoc}
78       */
79      public boolean hasDescendants( AttributeType ancestor ) throws LdapException
80      {
81          return immutableAttributeTypeRegistry.hasDescendants( ancestor );
82      }
83  
84  
85      /**
86       * {@inheritDoc}
87       */
88      public Iterator<AttributeType> descendants( String ancestorId ) throws LdapException
89      {
90          return immutableAttributeTypeRegistry.descendants( ancestorId );
91      }
92  
93  
94      /**
95       * {@inheritDoc}
96       */
97      public Iterator<AttributeType> descendants( AttributeType ancestor ) throws LdapException
98      {
99          return immutableAttributeTypeRegistry.descendants( ancestor );
100     }
101 
102 
103     /**
104      * {@inheritDoc}
105      */
106     public void register( AttributeType attributeType ) throws LdapException
107     {
108         throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) );
109     }
110 
111 
112     /**
113      * {@inheritDoc}
114      */
115     public void registerDescendants( AttributeType attributeType, AttributeType ancestor ) throws LdapException
116     {
117         throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) );
118     }
119 
120 
121     /**
122      * {@inheritDoc}
123      */
124     public void unregisterDescendants( AttributeType attributeType, AttributeType ancestor ) throws LdapException
125     {
126         throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) );
127     }
128 
129 
130     /**
131      * {@inheritDoc}
132      */
133     public AttributeType unregister( String numericOid ) throws LdapException
134     {
135         throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION,
136             "Cannot modify the AttributeTypeRegistry copy" );
137     }
138 
139 
140     /**
141      * {@inheritDoc}
142      */
143     public void addMappingFor( AttributeType attributeType ) throws LdapException
144     {
145         throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) );
146     }
147 
148 
149     /**
150      * {@inheritDoc}
151      */
152     public void removeMappingFor( AttributeType attributeType ) throws LdapException
153     {
154         throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) );
155     }
156 
157 
158     /**
159      * {@inheritDoc}
160      */
161     public AttributeType lookup( String oid ) throws LdapException
162     {
163         return immutableAttributeTypeRegistry.lookup( oid );
164     }
165 
166 
167     /**
168      * {@inheritDoc}
169      */
170     public String toString()
171     {
172         return immutableAttributeTypeRegistry.toString();
173     }
174 
175 
176     /**
177      * {@inheritDoc}
178      */
179     public AttributeTypeRegistry copy()
180     {
181         return ( AttributeTypeRegistry ) immutableAttributeTypeRegistry.copy();
182     }
183 
184 
185     /**
186      * {@inheritDoc}
187      */
188     public int size()
189     {
190         return immutableAttributeTypeRegistry.size();
191     }
192 
193 
194     /**
195      * {@inheritDoc}
196      */
197     public Iterator<AttributeType> iterator()
198     {
199         return immutableAttributeTypeRegistry.iterator();
200     }
201 
202 
203     /**
204      * {@inheritDoc}
205      */
206     public Iterator<String> oidsIterator()
207     {
208         return immutableAttributeTypeRegistry.oidsIterator();
209     }
210 
211 
212     /**
213      * {@inheritDoc}
214      */
215     public boolean contains( String oid )
216     {
217         return immutableAttributeTypeRegistry.contains( oid );
218     }
219 
220 
221     /**
222      * {@inheritDoc}
223      */
224     public String getOidByName( String name ) throws LdapException
225     {
226         try
227         {
228             return immutableAttributeTypeRegistry.getOidByName( name );
229         }
230         catch ( LdapException le )
231         {
232             throw new LdapNoSuchAttributeException( le.getMessage(), le );
233         }
234     }
235 
236 
237     /**
238      * {@inheritDoc}
239      */
240     public String getSchemaName( String oid ) throws LdapException
241     {
242         return immutableAttributeTypeRegistry.getSchemaName( oid );
243     }
244 
245 
246     /**
247      * {@inheritDoc}
248      */
249     public SchemaObjectType getType()
250     {
251         return immutableAttributeTypeRegistry.getType();
252     }
253 
254 
255     /**
256      * {@inheritDoc}
257      */
258     public void renameSchema( String originalSchemaName, String newSchemaName )
259     {
260         // Do nothing
261     }
262 
263 
264     /**
265      * {@inheritDoc}
266      */
267     public void unregisterSchemaElements( String schemaName ) throws LdapException
268     {
269         throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) );
270     }
271 
272 
273     /**
274      * {@inheritDoc}
275      */
276     public AttributeType get( String oid )
277     {
278         return immutableAttributeTypeRegistry.get( oid );
279     }
280 
281 
282     /**
283      * {@inheritDoc}
284      */
285     public void clear() throws LdapException
286     {
287         throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) );
288     }
289 
290 
291     /**
292      * {@inheritDoc}
293      */
294     public AttributeType unregister( AttributeType schemaObject ) throws LdapException
295     {
296         throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) );
297     }
298 }