Search in sources :

Example 6 with SchemaObjectWrapper

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

the class DefaultSchemaLoader method loadMatchingRuleUses.

/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadMatchingRuleUses(Schema... schemas) throws LdapException, IOException {
    List<Entry> matchingRuleUseEntries = new ArrayList<>();
    if (schemas == null) {
        return matchingRuleUseEntries;
    }
    AttributesFactory factory = new AttributesFactory();
    for (Schema schema : schemas) {
        Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
        for (SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers) {
            SchemaObject schemaObject = schemaObjectWrapper.get();
            if (schemaObject instanceof MatchingRuleUse) {
                MatchingRuleUse matchingRuleUse = (MatchingRuleUse) schemaObject;
                Entry matchingRuleUseEntry = factory.convert(matchingRuleUse, schema, null);
                matchingRuleUseEntries.add(matchingRuleUseEntry);
            }
        }
    }
    return matchingRuleUseEntries;
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) AttributesFactory(org.apache.directory.api.ldap.model.schema.AttributesFactory) MatchingRuleUse(org.apache.directory.api.ldap.model.schema.MatchingRuleUse) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) ArrayList(java.util.ArrayList) SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)

Example 7 with SchemaObjectWrapper

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

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

the class Registries method dumpUsedBy.

/**
 * Dump the UsedBy data structure as a String
 *
 * @return The UsedBy data structure
 */
public String dumpUsedBy() {
    StringBuilder sb = new StringBuilder();
    sb.append("USED BY :\n");
    try {
        for (Map.Entry<SchemaObjectWrapper, Set<SchemaObjectWrapper>> entry : usedBy.entrySet()) {
            SchemaObjectWrapper wrapper = entry.getKey();
            sb.append(wrapper.get().getObjectType()).append('[').append(wrapper.get().getOid()).append("] : {");
            boolean isFirst = true;
            for (SchemaObjectWrapper uses : entry.getValue()) {
                if (isFirst) {
                    isFirst = false;
                } else {
                    sb.append(", ");
                }
                sb.append(uses.get().getObjectType()).append('[').append(wrapper.get().getOid()).append("]");
            }
            sb.append("}\n");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return sb.toString();
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper) HashMap(java.util.HashMap) Map(java.util.Map) LdapProtocolErrorException(org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) LdapSchemaViolationException(org.apache.directory.api.ldap.model.exception.LdapSchemaViolationException) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 9 with SchemaObjectWrapper

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

the class Registries method isReferenced.

/**
 * Checks if a specific SchemaObject is referenced by any other SchemaObject.
 *
 * @param schemaObject The SchemaObject we are looking for
 * @return true if there is at least one SchemaObjetc referencing the given one
 */
public boolean isReferenced(SchemaObject schemaObject) {
    SchemaObjectWrapper wrapper = new SchemaObjectWrapper(schemaObject);
    Set<SchemaObjectWrapper> set = usedBy.get(wrapper);
    boolean referenced = (set != null) && !set.isEmpty();
    if (LOG.isDebugEnabled()) {
        if (referenced) {
            LOG.debug("The {}:{} is referenced", schemaObject.getObjectType(), schemaObject.getOid());
        } else {
            LOG.debug("The {}:{} is not referenced", schemaObject.getObjectType(), schemaObject.getOid());
        }
    }
    return referenced;
}
Also used : SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)

Example 10 with SchemaObjectWrapper

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

the class Registries method checkReferences.

private boolean checkReferences(SchemaObject reference, SchemaObject referee, String message) {
    SchemaObjectWrapper referenceWrapper = new SchemaObjectWrapper(reference);
    SchemaObjectWrapper refereeWrapper = new SchemaObjectWrapper(referee);
    // Check the references : Syntax -> SyntaxChecker
    if (!using.containsKey(referenceWrapper)) {
        LOG.debug("The Syntax {}:{} does not reference any " + message, reference.getObjectType(), reference.getOid());
        return false;
    }
    Set<SchemaObjectWrapper> usings = using.get(referenceWrapper);
    if (!usings.contains(refereeWrapper)) {
        LOG.debug("The {}:{} does not reference any " + message, reference.getObjectType(), reference.getOid());
        return false;
    }
    // Check the referees : SyntaxChecker -> Syntax
    if (!usedBy.containsKey(refereeWrapper)) {
        LOG.debug("The {}:{} is not referenced by any " + message, referee.getObjectType(), referee.getOid());
        return false;
    }
    Set<SchemaObjectWrapper> used = usedBy.get(refereeWrapper);
    if (!used.contains(referenceWrapper)) {
        LOG.debug("The {}:{} is not referenced by any " + message, referee.getObjectType(), referee.getOid());
        return false;
    }
    return true;
}
Also used : SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)

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