Search in sources :

Example 51 with ObjectClass

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

the class SchemaManagerAddTest method testAddObjectClassNoSuperiorWithExistingOid.

/**
 * Addition of an OC with an existing OID
 */
@Test
public void testAddObjectClassNoSuperiorWithExistingOid() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int ocrSize = schemaManager.getObjectClassRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    ObjectClass objectClass = new ObjectClass("2.5.17.0");
    assertFalse(schemaManager.add(objectClass));
    assertEquals(1, schemaManager.getErrors().size());
    Throwable error = schemaManager.getErrors().get(0);
    assertTrue(error instanceof LdapSchemaException);
    ObjectClass added = schemaManager.lookupObjectClassRegistry("2.5.17.0");
    assertNotNull(added);
    assertEquals(ocrSize, schemaManager.getObjectClassRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) MutableObjectClass(org.apache.directory.api.ldap.model.schema.MutableObjectClass) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) Test(org.junit.Test)

Example 52 with ObjectClass

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

the class DefaultSchemaManager method addObjectClasses.

/**
 * Add all the Schema's ObjectClasses
 */
private void addObjectClasses(Schema schema, Registries registries) throws LdapException, IOException {
    if (schema.getSchemaLoader() == null) {
        return;
    }
    for (Entry entry : schema.getSchemaLoader().loadObjectClasses(schema)) {
        ObjectClass objectClass = factory.getObjectClass(this, entry, registries, schema.getSchemaName());
        addSchemaObject(registries, objectClass, schema);
    }
}
Also used : Entry(org.apache.directory.api.ldap.model.entry.Entry) ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass)

Example 53 with ObjectClass

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

the class NameFormHelper method addToRegistries.

/**
 * Inject the NameForm into the registries, updating the references to
 * other SchemaObject
 *
 * @param nameForm The NameForm to add to the Registries
 * @param errors The errors we got while adding the NameForm to the Registries
 * @param registries The Registries
 * @throws LdapException If the addition failed
 */
public static void addToRegistries(NameForm nameForm, List<Throwable> errors, Registries registries) throws LdapException {
    if (registries != null) {
        try {
            nameForm.unlock();
            AttributeTypeRegistry atRegistry = registries.getAttributeTypeRegistry();
            ObjectClass structuralObjectClass = registries.getObjectClassRegistry().lookup(nameForm.getStructuralObjectClassOid());
            nameForm.setStructuralObjectClass(structuralObjectClass);
            nameForm.getMayAttributeTypes().clear();
            for (String oid : nameForm.getMayAttributeTypeOids()) {
                nameForm.getMayAttributeTypes().add(atRegistry.lookup(oid));
            }
            nameForm.getMustAttributeTypes().clear();
            for (String oid : nameForm.getMustAttributeTypeOids()) {
                nameForm.getMustAttributeTypes().add(atRegistry.lookup(oid));
            }
        } finally {
            nameForm.lock();
        }
    }
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) AttributeTypeRegistry(org.apache.directory.api.ldap.model.schema.registries.AttributeTypeRegistry)

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