Search in sources :

Example 6 with ObjectClass

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

the class DefaultSchemaLoader method loadObjectClasses.

private void loadObjectClasses(Attribute objectClasses) throws LdapException {
    if (objectClasses == null) {
        return;
    }
    for (Value value : objectClasses) {
        String desc = value.getValue();
        try {
            ObjectClass objectClass = OC_DESCR_SCHEMA_PARSER.parseObjectClassDescription(desc);
            updateSchemas(objectClass);
        } catch (ParseException pe) {
            throw new LdapException(pe);
        }
    }
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) Value(org.apache.directory.api.ldap.model.entry.Value) ParseException(java.text.ParseException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 7 with ObjectClass

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

the class DefaultSchemaLoader method loadObjectClasses.

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

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

the class ObjectClassHelper method buildSuperiors.

/**
 * Build the references to this ObjectClass SUPERIORS, checking that the type
 * hierarchy is correct.
 */
private static void buildSuperiors(ObjectClass objectClass, List<Throwable> errors, Registries registries) {
    ObjectClassRegistry ocRegistry = registries.getObjectClassRegistry();
    List<String> superiorOids = objectClass.getSuperiorOids();
    if (superiorOids != null) {
        objectClass.getSuperiors().clear();
        for (String superiorName : superiorOids) {
            try {
                ObjectClass superior = ocRegistry.lookup(ocRegistry.getOidByName(superiorName));
                // Before adding the superior, check that the ObjectClass type is consistent
                switch(objectClass.getType()) {
                    case ABSTRACT:
                        if (superior.getType() != ObjectClassTypeEnum.ABSTRACT) {
                            // An ABSTRACT OC can only inherit from ABSTRACT OCs
                            String msg = I18n.err(I18n.ERR_13766_ABSTRACT_OC_CANNOT_INHERIT_FROM_OC, objectClass.getOid(), superior.getObjectType(), superior);
                            LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_ABSTRACT_MUST_INHERIT_FROM_ABSTRACT_OC, msg);
                            ldapSchemaException.setSourceObject(objectClass);
                            errors.add(ldapSchemaException);
                            LOG.info(msg);
                            continue;
                        }
                        break;
                    case AUXILIARY:
                        if (superior.getType() == ObjectClassTypeEnum.STRUCTURAL) {
                            // An AUXILIARY OC cannot inherit from STRUCTURAL OCs
                            String msg = I18n.err(I18n.ERR_13767_AUX_OC_CANNOT_INHERIT_FROM_STRUCT_OC, objectClass.getOid(), superior);
                            LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_AUXILIARY_CANNOT_INHERIT_FROM_STRUCTURAL_OC, msg);
                            ldapSchemaException.setSourceObject(objectClass);
                            errors.add(ldapSchemaException);
                            LOG.info(msg);
                            continue;
                        }
                        break;
                    case STRUCTURAL:
                        if (superior.getType() == ObjectClassTypeEnum.AUXILIARY) {
                            // A STRUCTURAL OC cannot inherit from AUXILIARY OCs
                            String msg = I18n.err(I18n.ERR_13768_STRUCT_OC_CANNOT_INHERIT_FROM_AUX_OC, objectClass.getOid(), superior);
                            LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_STRUCTURAL_CANNOT_INHERIT_FROM_AUXILIARY_OC, msg);
                            ldapSchemaException.setSourceObject(objectClass);
                            errors.add(ldapSchemaException);
                            LOG.info(msg);
                            continue;
                        }
                        break;
                    default:
                        throw new IllegalArgumentException(I18n.err(I18n.ERR_13717_UNEXPECTED_OBJECT_CLASS_TYPE_ENUM, objectClass.getType()));
                }
                objectClass.getSuperiors().add(superior);
            } catch (LdapException ne) {
                // Cannot find the OC
                String msg = I18n.err(I18n.ERR_13769_CANNOT_REGISTER_SUPERIOR_MISSING, objectClass.getOid(), superiorName);
                LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_NONEXISTENT_SUPERIOR, msg, ne);
                ldapSchemaException.setSourceObject(objectClass);
                ldapSchemaException.setRelatedId(superiorName);
                errors.add(ldapSchemaException);
                LOG.info(msg);
                return;
            }
        }
    }
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) ObjectClassRegistry(org.apache.directory.api.ldap.model.schema.registries.ObjectClassRegistry) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 9 with ObjectClass

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

the class ObjectClassHelper method addToRegistries.

/**
 * Inject the ObjectClass into the registries, updating the references to
 * other SchemaObject
 *
 * @param objectClass The ObjectClass to add to the Registries
 * @param errors The errors we got while adding the ObjectClass to the Registries
 * @param registries The Registries
 * @throws LdapException on failure
 */
public static void addToRegistries(ObjectClass objectClass, List<Throwable> errors, Registries registries) throws LdapException {
    if (registries != null) {
        try {
            objectClass.unlock();
            // The superiors
            buildSuperiors(objectClass, errors, registries);
            // The MAY AttributeTypes
            buildMay(objectClass, errors, registries);
            // The MUST AttributeTypes
            buildMust(objectClass, errors, registries);
            /**
             * Add the OC references (using and usedBy) :
             * OC -> AT (MAY and MUST)
             * OC -> OC (SUPERIORS)
             */
            for (AttributeType mayAttributeType : objectClass.getMayAttributeTypes()) {
                registries.addReference(objectClass, mayAttributeType);
            }
            for (AttributeType mustAttributeType : objectClass.getMustAttributeTypes()) {
                registries.addReference(objectClass, mustAttributeType);
            }
            for (ObjectClass superiorObjectClass : objectClass.getSuperiors()) {
                registries.addReference(objectClass, superiorObjectClass);
            }
        } finally {
            objectClass.lock();
        }
    }
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType)

Example 10 with ObjectClass

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

the class ObjectClassHelper method removeFromRegistries.

/**
 * Remove the ObjectClass from the registries, updating the references to
 * other SchemaObject.
 *
 * If one of the referenced SchemaObject does not exist (SUPERIORS, MAY, MUST),
 * an exception is thrown.
 *
 * @param objectClass The ObjectClass to remove fro the registries
 * @param errors The errors we got while removing the ObjectClass from the registries
 * @param registries The Registries
 * @throws LdapException If the ObjectClass is not valid
 */
public static void removeFromRegistries(ObjectClass objectClass, List<Throwable> errors, Registries registries) throws LdapException {
    if (registries != null) {
        ObjectClassRegistry objectClassRegistry = registries.getObjectClassRegistry();
        // Unregister this ObjectClass into the Descendant map
        objectClassRegistry.unregisterDescendants(objectClass, objectClass.getSuperiors());
        /**
         * Remove the OC references (using and usedBy) :
         * OC -> AT (for MAY and MUST)
         * OC -> OC
         */
        if (objectClass.getMayAttributeTypes() != null) {
            for (AttributeType may : objectClass.getMayAttributeTypes()) {
                registries.delReference(objectClass, may);
            }
        }
        if (objectClass.getMustAttributeTypes() != null) {
            for (AttributeType must : objectClass.getMustAttributeTypes()) {
                registries.delReference(objectClass, must);
            }
        }
        if (objectClass.getSuperiors() != null) {
            for (ObjectClass superior : objectClass.getSuperiors()) {
                registries.delReference(objectClass, superior);
            }
        }
    }
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) ObjectClassRegistry(org.apache.directory.api.ldap.model.schema.registries.ObjectClassRegistry)

Aggregations

ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)53 Test (org.junit.Test)34 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)11 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)11 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)10 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)10 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)9 MutableObjectClass (org.apache.directory.api.ldap.model.schema.MutableObjectClass)6 ParseException (java.text.ParseException)5 HashSet (java.util.HashSet)5 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)5 SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)5 OpenLdapObjectIdentifierMacro (org.apache.directory.api.ldap.model.schema.syntaxCheckers.OpenLdapObjectIdentifierMacro)5 InputStream (java.io.InputStream)4 LdapNoSuchAttributeException (org.apache.directory.api.ldap.model.exception.LdapNoSuchAttributeException)4 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)3 MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)3 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2