Search in sources :

Example 11 with SchemaObjectWrapper

use of org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper in project directory-ldap-api by apache.

the class Registries method addUsing.

/**
 * Add an association between a SchemaObject an the SchemaObject it refers
 *
 * @param reference The base SchemaObject
 * @param referee The SchemaObject pointing on the reference
 */
private void addUsing(SchemaObject reference, SchemaObject referee) {
    if ((reference == null) || (referee == null)) {
        return;
    }
    SchemaObjectWrapper wrapper = new SchemaObjectWrapper(reference);
    Set<SchemaObjectWrapper> uses = getUsing(reference);
    if (uses == null) {
        uses = new HashSet<>();
    }
    uses.add(new SchemaObjectWrapper(referee));
    // Put back the set (this is a concurrentHashMap, it won't be replaced implicitly
    using.put(wrapper, uses);
}
Also used : SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)

Example 12 with SchemaObjectWrapper

use of org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper in project directory-ldap-api by apache.

the class Registries method delUsedBy.

/**
 * Del an association between a SchemaObject an the SchemaObject that refers it
 *
 * @param reference The base SchemaObject
 * @param referee The SchemaObject pointing on the reference
 */
private void delUsedBy(SchemaObject referee, SchemaObject reference) {
    if ((reference == null) || (referee == null)) {
        return;
    }
    Set<SchemaObjectWrapper> uses = getUsedBy(referee);
    if (uses == null) {
        return;
    }
    uses.remove(new SchemaObjectWrapper(reference));
    SchemaObjectWrapper wrapper = new SchemaObjectWrapper(referee);
    if (uses.isEmpty()) {
        usedBy.remove(wrapper);
    } else {
        usedBy.put(wrapper, uses);
    }
}
Also used : SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)

Example 13 with SchemaObjectWrapper

use of org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper 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 14 with SchemaObjectWrapper

use of org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper in project directory-ldap-api by apache.

the class Registries method delUsing.

/**
 * Del an association between a SchemaObject an the SchemaObject it refers
 *
 * @param reference The base SchemaObject
 * @param referee The SchemaObject pointing on the reference
 */
private void delUsing(SchemaObject reference, SchemaObject referee) {
    if ((reference == null) || (referee == null)) {
        return;
    }
    Set<SchemaObjectWrapper> uses = getUsing(reference);
    if (uses == null) {
        return;
    }
    uses.remove(new SchemaObjectWrapper(referee));
    SchemaObjectWrapper wrapper = new SchemaObjectWrapper(reference);
    if (uses.isEmpty()) {
        using.remove(wrapper);
    } else {
        using.put(wrapper, uses);
    }
}
Also used : SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)

Example 15 with SchemaObjectWrapper

use of org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper 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

SchemaObjectWrapper (org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)27 SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)14 Schema (org.apache.directory.api.ldap.model.schema.registries.Schema)13 ArrayList (java.util.ArrayList)12 DefaultSchema (org.apache.directory.api.ldap.model.schema.registries.DefaultSchema)12 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)11 Entry (org.apache.directory.api.ldap.model.entry.Entry)11 AttributesFactory (org.apache.directory.api.ldap.model.schema.AttributesFactory)8 LoadableSchemaObject (org.apache.directory.api.ldap.model.schema.LoadableSchemaObject)6 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)5 HashSet (java.util.HashSet)4 Set (java.util.Set)4 LdapUnwillingToPerformException (org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 LdapProtocolErrorException (org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException)3 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)2 LdapSchemaViolationException (org.apache.directory.api.ldap.model.exception.LdapSchemaViolationException)2 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)2 DitContentRule (org.apache.directory.api.ldap.model.schema.DitContentRule)2