use of org.apache.directory.api.ldap.model.schema.LoadableSchemaObject in project directory-ldap-api by apache.
the class Registries method associateWithSchema.
/**
* Store the given SchemaObject in the Map associating SchemaObjetcs to their
* related Schema.
*
* @param errors The list of errors we are accumulating while checking the schema
* @param schemaObject The schemaObject to register
*/
public void associateWithSchema(List<Throwable> errors, SchemaObject schemaObject) {
LOG.debug("Registering {}:{}", schemaObject.getObjectType(), schemaObject.getOid());
// Check that the SchemaObject is not already registered
if (!(schemaObject instanceof LoadableSchemaObject) && globalOidRegistry.contains(schemaObject.getOid())) {
String msg = I18n.err(I18n.ERR_13750_REGISTERING_FAILED_ALREADY_PRESENT, schemaObject.getObjectType(), schemaObject.getOid());
LOG.error(msg);
Throwable error = new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
errors.add(error);
return;
}
// Get a normalized form of schema name
String schemaName = getSchemaName(schemaObject);
// And register the schemaObject within its schema
Set<SchemaObjectWrapper> content = schemaObjects.get(schemaName);
if (content == null) {
content = new HashSet<>();
schemaObjects.put(Strings.toLowerCaseAscii(schemaName), content);
}
SchemaObjectWrapper schemaObjectWrapper = new SchemaObjectWrapper(schemaObject);
if (content.contains(schemaObjectWrapper)) {
// Already present !
// What should we do ?
LOG.info("Registering of {}:{} failed, is already present in the Registries", schemaObject.getObjectType(), schemaObject.getOid());
} else {
// Create the association
content.add(schemaObjectWrapper);
// an instance of LoadableSchemaObject
if (!(schemaObject instanceof LoadableSchemaObject)) {
try {
globalOidRegistry.register(schemaObject);
} catch (LdapException ne) {
errors.add(ne);
return;
}
}
LOG.debug("registered {} for OID {}", schemaObject.getName(), schemaObject.getOid());
}
}
use of org.apache.directory.api.ldap.model.schema.LoadableSchemaObject in project directory-ldap-api by apache.
the class Registries method unregister.
/**
* Unregister a SchemaObject from the registries
*
* @param schemaObject The SchemaObject we want to deregister
* @throws LdapException If the removal failed
*/
private SchemaObject unregister(List<Throwable> errors, SchemaObject schemaObject) throws LdapException {
LOG.debug("Unregistering {}:{}", schemaObject.getObjectType(), schemaObject.getOid());
// Check that the SchemaObject is present in the registries
if (!(schemaObject instanceof LoadableSchemaObject) && !globalOidRegistry.contains(schemaObject.getOid())) {
String msg = I18n.err(I18n.ERR_13751_UNREGISTERING_FAILED_NOT_PRESENT, schemaObject.getObjectType(), schemaObject.getOid());
LOG.error(msg);
throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
}
SchemaObject unregistered;
// First call the specific registry's register method
switch(schemaObject.getObjectType()) {
case ATTRIBUTE_TYPE:
unregistered = attributeTypeRegistry.unregister((AttributeType) schemaObject);
break;
case COMPARATOR:
unregistered = comparatorRegistry.unregister((LdapComparator<?>) schemaObject);
break;
case DIT_CONTENT_RULE:
unregistered = ditContentRuleRegistry.unregister((DitContentRule) schemaObject);
break;
case DIT_STRUCTURE_RULE:
unregistered = ditStructureRuleRegistry.unregister((DitStructureRule) schemaObject);
break;
case LDAP_SYNTAX:
unregistered = ldapSyntaxRegistry.unregister((LdapSyntax) schemaObject);
break;
case MATCHING_RULE:
unregistered = matchingRuleRegistry.unregister((MatchingRule) schemaObject);
break;
case MATCHING_RULE_USE:
unregistered = matchingRuleUseRegistry.unregister((MatchingRuleUse) schemaObject);
break;
case NAME_FORM:
unregistered = nameFormRegistry.unregister((NameForm) schemaObject);
break;
case NORMALIZER:
unregistered = normalizerRegistry.unregister((Normalizer) schemaObject);
break;
case OBJECT_CLASS:
unregistered = objectClassRegistry.unregister((ObjectClass) schemaObject);
break;
case SYNTAX_CHECKER:
unregistered = syntaxCheckerRegistry.unregister((SyntaxChecker) schemaObject);
break;
default:
throw new IllegalArgumentException(I18n.err(I18n.ERR_13718_UNEXPECTED_SCHEMA_OBJECT_TYPE, schemaObject.getObjectType()));
}
return unregistered;
}
use of org.apache.directory.api.ldap.model.schema.LoadableSchemaObject in project directory-ldap-api by apache.
the class DefaultSchemaObjectRegistry method clear.
/**
* {@inheritDoc}
*/
@Override
public void clear() {
// Clear all the schemaObjects
for (SchemaObject schemaObject : oidRegistry) {
// Don't clear LoadableSchemaObject
if (!(schemaObject instanceof LoadableSchemaObject)) {
schemaObject.clear();
}
}
// Remove the byName elements
byName.clear();
// Clear the OidRegistry
oidRegistry.clear();
}
use of org.apache.directory.api.ldap.model.schema.LoadableSchemaObject in project directory-ldap-api by apache.
the class Registries method dissociateFromSchema.
/**
* Store the given SchemaObject in the Map associating SchemaObjetcs to their
* related Schema.
*
* @param errors The list that collect errors
* @param schemaObject The schemaObject to register
* @throws LdapException If there is a problem
*/
public void dissociateFromSchema(List<Throwable> errors, SchemaObject schemaObject) throws LdapException {
LOG.debug("Unregistering {}:{}", schemaObject.getObjectType(), schemaObject.getOid());
// Check that the SchemaObject is already registered
if (!(schemaObject instanceof LoadableSchemaObject) && !globalOidRegistry.contains(schemaObject.getOid())) {
String msg = I18n.err(I18n.ERR_13751_UNREGISTERING_FAILED_NOT_PRESENT, schemaObject.getObjectType(), schemaObject.getOid());
LOG.error(msg);
Throwable error = new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
errors.add(error);
return;
}
// Get a normalized form of schema name
String schemaName = getSchemaName(schemaObject);
String oid = schemaObject.getOid();
// And unregister the schemaObject from its schema
Set<SchemaObjectWrapper> content = schemaObjects.get(schemaName);
SchemaObjectWrapper schemaObjectWrapper = new SchemaObjectWrapper(schemaObject);
if (!content.contains(schemaObjectWrapper)) {
// Not present !
// What should we do ?
LOG.info("Unregistering of {}:{} failed, is not present in the Registries", schemaObject.getObjectType(), schemaObject.getOid());
} else {
// Remove the association
content.remove(schemaObjectWrapper);
// an instance of LoadableSchemaObject
if (!(schemaObject instanceof LoadableSchemaObject)) {
try {
globalOidRegistry.unregister(oid);
} catch (LdapException ne) {
errors.add(ne);
return;
}
}
LOG.debug("Unregistered {} for OID {}", schemaObject.getName(), schemaObject.getOid());
}
}
use of org.apache.directory.api.ldap.model.schema.LoadableSchemaObject in project directory-ldap-api by apache.
the class Registries method clone.
/**
* Clone the Registries. This is done in two steps :
* - first clone the SchemaObjetc registries
* - second restore the relation between them
*/
// False positive
@Override
public Registries clone() throws CloneNotSupportedException {
// First clone the structure
Registries clone = (Registries) super.clone();
// Now, clone the oidRegistry
clone.globalOidRegistry = globalOidRegistry.copy();
// We have to clone every SchemaObject registries now
clone.attributeTypeRegistry = attributeTypeRegistry.copy();
clone.comparatorRegistry = comparatorRegistry.copy();
clone.ditContentRuleRegistry = ditContentRuleRegistry.copy();
clone.ditStructureRuleRegistry = ditStructureRuleRegistry.copy();
clone.ldapSyntaxRegistry = ldapSyntaxRegistry.copy();
clone.matchingRuleRegistry = matchingRuleRegistry.copy();
clone.matchingRuleUseRegistry = matchingRuleUseRegistry.copy();
clone.nameFormRegistry = nameFormRegistry.copy();
clone.normalizerRegistry = normalizerRegistry.copy();
clone.objectClassRegistry = objectClassRegistry.copy();
clone.syntaxCheckerRegistry = syntaxCheckerRegistry.copy();
// Store all the SchemaObjects into the globalOid registry
for (AttributeType attributeType : clone.attributeTypeRegistry) {
clone.globalOidRegistry.put(attributeType);
}
for (DitContentRule ditContentRule : clone.ditContentRuleRegistry) {
clone.globalOidRegistry.put(ditContentRule);
}
for (DitStructureRule ditStructureRule : clone.ditStructureRuleRegistry) {
clone.globalOidRegistry.put(ditStructureRule);
}
for (MatchingRule matchingRule : clone.matchingRuleRegistry) {
clone.globalOidRegistry.put(matchingRule);
}
for (MatchingRuleUse matchingRuleUse : clone.matchingRuleUseRegistry) {
clone.globalOidRegistry.put(matchingRuleUse);
}
for (NameForm nameForm : clone.nameFormRegistry) {
clone.globalOidRegistry.put(nameForm);
}
for (ObjectClass objectClass : clone.objectClassRegistry) {
clone.globalOidRegistry.put(objectClass);
}
for (LdapSyntax syntax : clone.ldapSyntaxRegistry) {
clone.globalOidRegistry.put(syntax);
}
// Clone the schema list
clone.loadedSchemas = new HashMap<>();
for (Map.Entry<String, Set<SchemaObjectWrapper>> entry : schemaObjects.entrySet()) {
// We don't clone the schemas
clone.loadedSchemas.put(entry.getKey(), loadedSchemas.get(entry.getKey()));
}
// Clone the Using and usedBy structures
// They will be empty
clone.using = new HashMap<>();
clone.usedBy = new HashMap<>();
// Last, rebuild the using and usedBy references
clone.buildReferences();
// Now, check the registries. We don't care about errors
clone.checkRefInteg();
clone.schemaObjects = new HashMap<>();
// SchemaObjects
for (Map.Entry<String, Set<SchemaObjectWrapper>> entry : schemaObjects.entrySet()) {
Set<SchemaObjectWrapper> objects = new HashSet<>();
for (SchemaObjectWrapper schemaObjectWrapper : entry.getValue()) {
SchemaObject original = schemaObjectWrapper.get();
try {
if (!(original instanceof LoadableSchemaObject)) {
SchemaObject copy = clone.globalOidRegistry.getSchemaObject(original.getOid());
SchemaObjectWrapper newWrapper = new SchemaObjectWrapper(copy);
objects.add(newWrapper);
} else {
SchemaObjectWrapper newWrapper = new SchemaObjectWrapper(original);
objects.add(newWrapper);
}
} catch (LdapException ne) {
// Nothing to do
}
}
clone.schemaObjects.put(entry.getKey(), objects);
}
return clone;
}
Aggregations