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