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    
025    import org.apache.directory.shared.ldap.exception.LdapException;
026    import org.apache.directory.shared.ldap.schema.SchemaObject;
027    import org.apache.directory.shared.ldap.schema.SchemaObjectType;
028    
029    
030    /**
031     * Common schema object registry interface.
032     *
033     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034     * @version $Rev$, $Date$
035     */
036    public interface SchemaObjectRegistry<T extends SchemaObject>
037    {
038        /**
039         * Checks to see if an SchemaObject exists in the registry, by its
040         * OID or name. 
041         * 
042         * @param oid the object identifier or name of the SchemaObject
043         * @return true if a SchemaObject definition exists for the oid, false
044         * otherwise
045         */
046        boolean contains( String oid );
047    
048    
049        /**
050         * Gets the name of the schema this schema object is associated with.
051         *
052         * @param id the object identifier or the name
053         * @return the schema name
054         * @throws LdapException if the schema object does not exist
055         */
056        String getSchemaName( String oid ) throws LdapException;
057    
058    
059        /**
060         * Gets the SchemaObject associated with a given OID.
061         *
062         * @param oid The SchemaObject's OID we are looking for
063         * @return The SchemaObject, if any. Null otherwise
064         */
065        SchemaObject get( String oid );
066    
067    
068        /**
069         * Modify all the SchemaObject using a schemaName when this name changes.
070         *
071         * @param originalSchemaName The original Schema name
072         * @param newSchemaName The new Schema name
073         * @throws LdapException if the schema object does not exist
074         */
075        void renameSchema( String originalSchemaName, String newSchemaName ) throws LdapException;
076    
077    
078        /**
079         * Gets an iterator over the registered schema objects in the registry.
080         *
081         * @return an Iterator of homogeneous schema objects
082         */
083        Iterator<T> iterator();
084    
085    
086        /**
087         * Gets an iterator over the registered schema objects'OID in the registry.
088         *
089         * @return an Iterator of OIDs
090         */
091        Iterator<String> oidsIterator();
092    
093    
094        /**
095         * Looks up a SchemaObject by its unique Object Identifier or by name.
096         *
097         * @param oid the object identifier or name
098         * @return the SchemaObject instance for the id
099         * @throws LdapException if the SchemaObject does not exist
100         */
101        T lookup( String oid ) throws LdapException;
102    
103    
104        /**
105         * Registers a new SchemaObject with this registry.
106         *
107         * @param schemaObject the SchemaObject to register
108         * @throws LdapException if the SchemaObject is already registered or
109         * the registration operation is not supported
110         */
111        void register( T schemaObject ) throws LdapException;
112    
113    
114        /**
115         * Removes the SchemaObject registered with this registry, using its
116         * numeric OID.
117         * 
118         * @param numericOid the numeric identifier
119         * @throws LdapException if the numeric identifier is invalid
120         */
121        T unregister( String numericOid ) throws LdapException;
122    
123    
124        /**
125         * Removes the SchemaObject registered with this registry.
126         * 
127         * @param T the schemaObject to unregister
128         * @throws LdapException if the schemaObject can't be unregistered is invalid
129         */
130        T unregister( T schemaObject ) throws LdapException;
131    
132    
133        /**
134         * Unregisters all SchemaObjects defined for a specific schema from
135         * this registry.
136         * 
137         * @param schemaName the name of the schema whose SchemaObjects will be removed from
138         */
139        void unregisterSchemaElements( String schemaName ) throws LdapException;
140    
141    
142        /**
143         * Gets the numericOid for a name/alias if one is associated.  To prevent
144         * lookup failures due to case variance in the name, a failure to lookup the
145         * OID, will trigger a lookup using a lower cased version of the name and 
146         * the name that failed to match will automatically be associated with the
147         * OID.
148         * 
149         * @param name The name we are looking the oid for
150         * @return The numericOID associated with this name
151         * @throws LdapException If the OID can't be found
152         */
153        String getOidByName( String name ) throws LdapException;
154    
155    
156        /**
157         * Copy a DefaultSchemaObjectRegistry. All the stored SchemaObject will also
158         * be copied, by the cross references will be lost.
159         * 
160         * @return SchemaObjectRegistry<T> The copied registry
161         */
162        SchemaObjectRegistry<T> copy();
163    
164    
165        /**
166         * @return the type
167         */
168        SchemaObjectType getType();
169    
170    
171        /**
172         *  @return The number of AttributeType stored
173         */
174        int size();
175    
176    
177        /**
178         * Clear the registry from all its content
179         */
180        void clear() throws LdapException;
181    }