Search in sources :

Example 16 with SchemaObjectWrapper

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

the class Registries method contains.

/**
 * Tells if the given SchemaObject is present in one schema. The schema
 * may be disabled.
 *
 * @param schemaObject The schemaObject we are looking for
 * @return true if the schemaObject is present in a schema
 */
public boolean contains(SchemaObject schemaObject) {
    String schemaName = schemaObject.getSchemaName();
    Set<SchemaObjectWrapper> setSchemaObjects = schemaObjects.get(schemaName);
    if ((setSchemaObjects == null) || setSchemaObjects.isEmpty()) {
        return false;
    }
    SchemaObjectWrapper wrapper = new SchemaObjectWrapper(schemaObject);
    return setSchemaObjects.contains(wrapper);
}
Also used : SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)

Example 17 with SchemaObjectWrapper

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

the class Registries method addUsedBy.

/**
 * Add 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 addUsedBy(SchemaObject referee, SchemaObject reference) {
    if ((reference == null) || (referee == null)) {
        return;
    }
    SchemaObjectWrapper wrapper = new SchemaObjectWrapper(referee);
    Set<SchemaObjectWrapper> uses = getUsedBy(referee);
    if (uses == null) {
        uses = new HashSet<>();
    }
    uses.add(new SchemaObjectWrapper(reference));
    // Put back the set (this is a concurrentHashMap, it won't be replaced implicitly
    usedBy.put(wrapper, uses);
}
Also used : SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)

Example 18 with SchemaObjectWrapper

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

the class Registries method dissociateFromSchema.

/**
 * Remove the given SchemaObject from the Map associating SchemaObjetcs to their
 * related Schema.
 *
 * @param schemaObject The schemaObject to remove
 * @throws LdapException If there is a problem
 */
public void dissociateFromSchema(SchemaObject schemaObject) throws LdapException {
    // And unregister the schemaObject within its schema
    Set<SchemaObjectWrapper> content = schemaObjects.get(Strings.toLowerCaseAscii(schemaObject.getSchemaName()));
    if (content != null) {
        SchemaObjectWrapper schemaObjectWrapper = new SchemaObjectWrapper(schemaObject);
        if (content.contains(schemaObjectWrapper)) {
            // remove the schemaObject
            content.remove(schemaObjectWrapper);
            // an instance of LoadableSchemaObject
            if (!(schemaObject instanceof LoadableSchemaObject)) {
                globalOidRegistry.unregister(schemaObject.getOid());
            }
            LOG.debug("Unregistered {}:{}", schemaObject.getObjectType(), schemaObject.getOid());
        } else {
            // Not present !!
            // What should we do ?
            LOG.debug("Unregistering of {}:{} failed, not found in Registries", schemaObject.getObjectType(), schemaObject.getOid());
        }
    }
}
Also used : LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)

Example 19 with SchemaObjectWrapper

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

the class Registries method dumpUsing.

/**
 * Dump the Using data structure as a String
 *
 * @return The Using data structure
 */
public String dumpUsing() {
    StringBuilder sb = new StringBuilder();
    sb.append("USING :\n");
    try {
        for (Map.Entry<SchemaObjectWrapper, Set<SchemaObjectWrapper>> entry : using.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 20 with SchemaObjectWrapper

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

the class DefaultSchemaLoader method loadDitStructureRules.

/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadDitStructureRules(Schema... schemas) throws LdapException, IOException {
    List<Entry> ditStructureRuleEntries = new ArrayList<>();
    if (schemas == null) {
        return ditStructureRuleEntries;
    }
    AttributesFactory factory = new AttributesFactory();
    for (Schema schema : schemas) {
        Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
        for (SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers) {
            SchemaObject schemaObject = schemaObjectWrapper.get();
            if (schemaObject instanceof DitStructureRule) {
                DitStructureRule ditStructureRule = (DitStructureRule) schemaObject;
                Entry ditStructureRuleEntry = factory.convert(ditStructureRule, schema, null);
                ditStructureRuleEntries.add(ditStructureRuleEntry);
            }
        }
    }
    return ditStructureRuleEntries;
}
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) DitStructureRule(org.apache.directory.api.ldap.model.schema.DitStructureRule) 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)

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