Search in sources :

Example 1 with LoadableSchemaObject

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());
    }
}
Also used : LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 2 with LoadableSchemaObject

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;
}
Also used : LdapComparator(org.apache.directory.api.ldap.model.schema.LdapComparator) SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) SyntaxChecker(org.apache.directory.api.ldap.model.schema.SyntaxChecker) ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) MatchingRuleUse(org.apache.directory.api.ldap.model.schema.MatchingRuleUse) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) NameForm(org.apache.directory.api.ldap.model.schema.NameForm) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) DitStructureRule(org.apache.directory.api.ldap.model.schema.DitStructureRule) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) DitContentRule(org.apache.directory.api.ldap.model.schema.DitContentRule) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) MutableMatchingRule(org.apache.directory.api.ldap.model.schema.MutableMatchingRule)

Example 3 with LoadableSchemaObject

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();
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject)

Example 4 with LoadableSchemaObject

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());
    }
}
Also used : LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 5 with LoadableSchemaObject

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;
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) HashSet(java.util.HashSet) Set(java.util.Set) MatchingRuleUse(org.apache.directory.api.ldap.model.schema.MatchingRuleUse) NameForm(org.apache.directory.api.ldap.model.schema.NameForm) SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper) LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) DitStructureRule(org.apache.directory.api.ldap.model.schema.DitStructureRule) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) DitContentRule(org.apache.directory.api.ldap.model.schema.DitContentRule) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) MutableMatchingRule(org.apache.directory.api.ldap.model.schema.MutableMatchingRule) HashMap(java.util.HashMap) Map(java.util.Map) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) HashSet(java.util.HashSet)

Aggregations

LoadableSchemaObject (org.apache.directory.api.ldap.model.schema.LoadableSchemaObject)8 SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)5 SchemaObjectWrapper (org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)5 LdapUnwillingToPerformException (org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException)4 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)3 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)2 DitContentRule (org.apache.directory.api.ldap.model.schema.DitContentRule)2 DitStructureRule (org.apache.directory.api.ldap.model.schema.DitStructureRule)2 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)2 MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)2 MatchingRuleUse (org.apache.directory.api.ldap.model.schema.MatchingRuleUse)2 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)2 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)2 NameForm (org.apache.directory.api.ldap.model.schema.NameForm)2 ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 LdapOtherException (org.apache.directory.api.ldap.model.exception.LdapOtherException)1