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 */
020package org.apache.directory.api.ldap.model.schema.registries;
021
022
023import java.util.Iterator;
024
025import org.apache.directory.api.ldap.model.exception.LdapException;
026import org.apache.directory.api.ldap.model.schema.SchemaObject;
027import org.apache.directory.api.ldap.model.schema.SchemaObjectType;
028
029
030/**
031 * Common schema object registry interface.
032 * 
033 * @param <T> The SchemaObject type
034 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
035 */
036public 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 oid 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    T 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     * @return The unregistred schema object
120     * @throws LdapException if the numeric identifier is invalid
121     */
122    T unregister( String numericOid ) throws LdapException;
123
124
125    /**
126     * Removes the SchemaObject registered with this registry.
127     * 
128     * @param schemaObject the schemaObject to unregister
129     * @return The unregistred schema object
130     * @throws LdapException if the schemaObject can't be unregistered is invalid
131     */
132    T unregister( T schemaObject ) throws LdapException;
133
134
135    /**
136     * Unregisters all SchemaObjects defined for a specific schema from
137     * this registry.
138     * 
139     * @param schemaName the name of the schema whose SchemaObjects will be removed from
140     * @throws LdapException If we had a problem while unregistering the schema
141     */
142    void unregisterSchemaElements( String schemaName ) throws LdapException;
143
144
145    /**
146     * Gets the numericOid for a name/alias if one is associated.  To prevent
147     * lookup failures due to case variance in the name, a failure to lookup the
148     * OID, will trigger a lookup using a lower cased version of the name and 
149     * the name that failed to match will automatically be associated with the
150     * OID.
151     * 
152     * @param name The name we are looking the oid for
153     * @return The numericOID associated with this name
154     * @throws LdapException If the OID can't be found
155     */
156    String getOidByName( String name ) throws LdapException;
157
158
159    /**
160     * Copy a DefaultSchemaObjectRegistry. All the stored SchemaObject will also
161     * be copied, by the cross references will be lost.
162     * 
163     * @return The copied registry
164     */
165    SchemaObjectRegistry<T> copy();
166
167
168    /**
169     * @return the type
170     */
171    SchemaObjectType getType();
172
173
174    /**
175     *  @return The number of AttributeType stored
176     */
177    int size();
178
179
180    /**
181     * Clear the registry from all its content
182     * 
183     * @throws LdapException If we had a failure while clearing the registry
184     */
185    void clear() throws LdapException;
186    
187}