001    /*
002     *  Licensed to the Apache Software Foundation (ASF) under one
003     *  or more contributor license agreements.  See the NOTICE file
004     *  distributed with this work for additional information
005     *  regarding copyright ownership.  The ASF licenses this file
006     *  to you under the Apache License, Version 2.0 (the
007     *  "License"); you may not use this file except in compliance
008     *  with the License.  You may obtain a copy of the License at
009     *  
010     *    http://www.apache.org/licenses/LICENSE-2.0
011     *  
012     *  Unless required by applicable law or agreed to in writing,
013     *  software distributed under the License is distributed on an
014     *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     *  KIND, either express or implied.  See the License for the
016     *  specific language governing permissions and limitations
017     *  under the License. 
018     *  
019     */
020    package org.apache.directory.shared.ldap.schema.registries;
021    
022    
023    import java.util.Iterator;
024    import java.util.Map;
025    
026    import org.apache.directory.shared.i18n.I18n;
027    import org.apache.directory.shared.ldap.exception.LdapException;
028    import org.apache.directory.shared.ldap.exception.LdapUnwillingToPerformException;
029    import org.apache.directory.shared.ldap.message.ResultCodeEnum;
030    import org.apache.directory.shared.ldap.schema.AttributeType;
031    import org.apache.directory.shared.ldap.schema.SchemaObject;
032    import org.apache.directory.shared.ldap.schema.SchemaObjectType;
033    import org.apache.directory.shared.ldap.schema.normalizers.OidNormalizer;
034    
035    
036    /**
037     * An immutable wrapper of the AttributeType registry.
038     *
039     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
040     * @version $Rev: 828111 $
041     */
042    public class ImmutableAttributeTypeRegistry implements AttributeTypeRegistry
043    {
044        /** The wrapped AttributeType registry */
045        AttributeTypeRegistry immutableAttributeTypeRegistry;
046    
047    
048        /**
049         * Creates a new instance of ImmutableAttributeTypeRegistry.
050         *
051         * @param attributeTypeRegistry The wrapped AttributeType registry
052         */
053        public ImmutableAttributeTypeRegistry( AttributeTypeRegistry attributeTypeRegistry )
054        {
055            immutableAttributeTypeRegistry = attributeTypeRegistry;
056        }
057    
058    
059        /**
060         * {@inheritDoc}
061         */
062        public Map<String, OidNormalizer> getNormalizerMapping()
063        {
064            return immutableAttributeTypeRegistry.getNormalizerMapping();
065        }
066    
067    
068        /**
069         * {@inheritDoc}
070         */
071        public boolean hasDescendants( String ancestorId ) throws LdapException
072        {
073            return immutableAttributeTypeRegistry.hasDescendants( ancestorId );
074        }
075    
076    
077        /**
078         * {@inheritDoc}
079         */
080        public Iterator<AttributeType> descendants( String ancestorId ) throws LdapException
081        {
082            return immutableAttributeTypeRegistry.descendants( ancestorId );
083        }
084    
085    
086        /**
087         * {@inheritDoc}
088         */
089        public void register( AttributeType attributeType ) throws LdapException
090        {
091            throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) );
092        }
093    
094    
095        /**
096         * {@inheritDoc}
097         */
098        public void registerDescendants( AttributeType attributeType, AttributeType ancestor ) throws LdapException
099        {
100            throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) );
101        }
102    
103    
104        /**
105         * {@inheritDoc}
106         */
107        public void unregisterDescendants( AttributeType attributeType, AttributeType ancestor ) throws LdapException
108        {
109            throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) );
110        }
111    
112    
113        /**
114         * {@inheritDoc}
115         */
116        public AttributeType unregister( String numericOid ) throws LdapException
117        {
118            throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION,
119                "Cannot modify the AttributeTypeRegistry copy" );
120        }
121    
122    
123        /**
124         * {@inheritDoc}
125         */
126        public void addMappingFor( AttributeType attributeType ) throws LdapException
127        {
128            throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) );
129        }
130    
131    
132        /**
133         * {@inheritDoc}
134         */
135        public void removeMappingFor( AttributeType attributeType ) throws LdapException
136        {
137            throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) );
138        }
139    
140    
141        /**
142         * {@inheritDoc}
143         */
144        public AttributeType lookup( String oid ) throws LdapException
145        {
146            return immutableAttributeTypeRegistry.lookup( oid );
147        }
148    
149    
150        /**
151         * {@inheritDoc}
152         */
153        public String toString()
154        {
155            return immutableAttributeTypeRegistry.toString();
156        }
157    
158    
159        /**
160         * {@inheritDoc}
161         */
162        public AttributeTypeRegistry copy()
163        {
164            return ( AttributeTypeRegistry ) immutableAttributeTypeRegistry.copy();
165        }
166    
167    
168        /**
169         * {@inheritDoc}
170         */
171        public int size()
172        {
173            return immutableAttributeTypeRegistry.size();
174        }
175    
176    
177        /**
178         * {@inheritDoc}
179         */
180        public Iterator<AttributeType> iterator()
181        {
182            return immutableAttributeTypeRegistry.iterator();
183        }
184    
185    
186        /**
187         * {@inheritDoc}
188         */
189        public Iterator<String> oidsIterator()
190        {
191            return immutableAttributeTypeRegistry.oidsIterator();
192        }
193    
194    
195        /**
196         * {@inheritDoc}
197         */
198        public boolean contains( String oid )
199        {
200            return immutableAttributeTypeRegistry.contains( oid );
201        }
202    
203    
204        /**
205         * {@inheritDoc}
206         */
207        public String getOidByName( String name ) throws LdapException
208        {
209            return immutableAttributeTypeRegistry.getOidByName( name );
210        }
211    
212    
213        /**
214         * {@inheritDoc}
215         */
216        public String getSchemaName( String oid ) throws LdapException
217        {
218            return immutableAttributeTypeRegistry.getSchemaName( oid );
219        }
220    
221    
222        /**
223         * {@inheritDoc}
224         */
225        public SchemaObjectType getType()
226        {
227            return immutableAttributeTypeRegistry.getType();
228        }
229    
230    
231        /**
232         * {@inheritDoc}
233         */
234        public void renameSchema( String originalSchemaName, String newSchemaName )
235        {
236            // Do nothing
237        }
238    
239    
240        /**
241         * {@inheritDoc}
242         */
243        public void unregisterSchemaElements( String schemaName ) throws LdapException
244        {
245            throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) );
246        }
247    
248    
249        /**
250         * {@inheritDoc}
251         */
252        public SchemaObject get( String oid )
253        {
254            return immutableAttributeTypeRegistry.get( oid );
255        }
256    
257    
258        /**
259         * {@inheritDoc}
260         */
261        public void clear() throws LdapException
262        {
263            throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) );
264        }
265    
266    
267        /**
268         * {@inheritDoc}
269         */
270        public AttributeType unregister( AttributeType schemaObject ) throws LdapException
271        {
272            throw new LdapUnwillingToPerformException( ResultCodeEnum.NO_SUCH_OPERATION, I18n.err( I18n.ERR_04275 ) );
273        }
274    }