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 25 import org.apache.directory.api.ldap.model.exception.LdapException; 26 import org.apache.directory.api.ldap.model.schema.SchemaObject; 27 import org.apache.directory.api.ldap.model.schema.SchemaObjectType; 28 29 30 /** 31 * Common schema object registry interface. 32 * 33 * @param <T> The SchemaObject type 34 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 35 */ 36 public interface SchemaObjectRegistry<T extends SchemaObject> 37 { 38 /** 39 * Checks to see if an SchemaObject exists in the registry, by its 40 * OID or name. 41 * 42 * @param oid the object identifier or name of the SchemaObject 43 * @return true if a SchemaObject definition exists for the oid, false 44 * otherwise 45 */ 46 boolean contains( String oid ); 47 48 49 /** 50 * Gets the name of the schema this schema object is associated with. 51 * 52 * @param oid the object identifier or the name 53 * @return the schema name 54 * @throws LdapException if the schema object does not exist 55 */ 56 String getSchemaName( String oid ) throws LdapException; 57 58 59 /** 60 * Gets the SchemaObject associated with a given OID. 61 * 62 * @param oid The SchemaObject's OID we are looking for 63 * @return The SchemaObject, if any. Null otherwise 64 */ 65 T get( String oid ); 66 67 68 /** 69 * Modify all the SchemaObject using a schemaName when this name changes. 70 * 71 * @param originalSchemaName The original Schema name 72 * @param newSchemaName The new Schema name 73 * @throws LdapException if the schema object does not exist 74 */ 75 void renameSchema( String originalSchemaName, String newSchemaName ) throws LdapException; 76 77 78 /** 79 * Gets an iterator over the registered schema objects in the registry. 80 * 81 * @return an Iterator of homogeneous schema objects 82 */ 83 Iterator<T> iterator(); 84 85 86 /** 87 * Gets an iterator over the registered schema objects'OID in the registry. 88 * 89 * @return an Iterator of OIDs 90 */ 91 Iterator<String> oidsIterator(); 92 93 94 /** 95 * Looks up a SchemaObject by its unique Object Identifier or by name. 96 * 97 * @param oid the object identifier or name 98 * @return the SchemaObject instance for the id 99 * @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 }