Search in sources :

Example 31 with ObjectClass

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

the class DefaultObjectClassRegistry method hasDescendants.

/**
 * {@inheritDoc}
 */
@Override
public boolean hasDescendants(String ancestorId) throws LdapException {
    try {
        String oid = getOidByName(ancestorId);
        Set<ObjectClass> descendants = oidToDescendants.get(oid);
        return (descendants != null) && !descendants.isEmpty();
    } catch (LdapException ne) {
        throw new LdapNoSuchAttributeException(ne.getMessage(), ne);
    }
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapNoSuchAttributeException(org.apache.directory.api.ldap.model.exception.LdapNoSuchAttributeException)

Example 32 with ObjectClass

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

the class DefaultObjectClassRegistry method clear.

/**
 * {@inheritDoc}
 */
@Override
public void clear() {
    // Clear the contained SchemaObjects
    for (SchemaObject objectClass : oidRegistry) {
        objectClass.clear();
    }
    // First clear the shared elements
    super.clear();
    // and clear the descendant
    for (Map.Entry<String, Set<ObjectClass>> entry : oidToDescendants.entrySet()) {
        Set<ObjectClass> descendants = entry.getValue();
        if (descendants != null) {
            descendants.clear();
        }
    }
    oidToDescendants.clear();
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) HashSet(java.util.HashSet) Set(java.util.Set) ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) Map(java.util.Map) HashMap(java.util.HashMap)

Example 33 with ObjectClass

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

the class QuirkySchemaTest method testLoadMinimalSchema.

/**
 * Try to load a very minimal (and correct) schema. It has just 'person' objectclass and all
 * the necessary attributes, matching rules and syntaxes. Load it in strict mode.
 * This test is here mostly to make sure that the test itself works.
 */
@Test
public void testLoadMinimalSchema() throws Exception {
    LdapConnection connection = createFakeConnection("src/test/resources/schema-minimal.ldif");
    DefaultSchemaLoader loader = new DefaultSchemaLoader(connection);
    Collection<Schema> allEnabled = loader.getAllEnabled();
    assertEquals(1, allEnabled.size());
    Schema schema = allEnabled.iterator().next();
    assertNotNull(schema);
    assertEquals(26, schema.getContent().size());
    SchemaManager schemaManager = new DefaultSchemaManager(loader);
    boolean loaded = schemaManager.loadAllEnabled();
    if (!loaded) {
        fail("Schema load failed : " + Exceptions.printErrors(schemaManager.getErrors()));
    }
    assertTrue(schemaManager.getRegistries().getAttributeTypeRegistry().contains("cn"));
    ObjectClass person = schemaManager.getRegistries().getObjectClassRegistry().lookup("person");
    assertNotNull(person);
    assertEquals(2, person.getMustAttributeTypes().size());
    assertEquals(4, person.getMayAttributeTypes().size());
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) Test(org.junit.Test)

Example 34 with ObjectClass

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

the class ObjectClassDescriptionSchemaParserTest method testNovellList.

@Test
public void testNovellList() throws ParseException, NamingException {
    String value = "( 2.16.840.1.113719.1.1.6.1.30 NAME 'List' SUP Top STRUCTURAL MUST cn MAY ( description $ l $ member $ ou $ o $ eMailAddress $ mailboxLocation $ mailboxID $ owner $ seeAlso $ fullName ) X-NDS_NAMING 'cn' X-NDS_CONTAINMENT ( 'Organization' 'organizationalUnit' 'domain' ) X-NDS_NOT_CONTAINER '1' X-NDS_NONREMOVABLE '1' X-NDS_ACL_TEMPLATES '2#entry#[Root Template]#member' )";
    ObjectClass objectClass = parser.parseObjectClassDescription(value);
    assertEquals("2.16.840.1.113719.1.1.6.1.30", objectClass.getOid());
    assertEquals(1, objectClass.getNames().size());
    assertEquals("List", objectClass.getNames().get(0));
    assertNull(objectClass.getDescription());
    assertEquals(1, objectClass.getSuperiorOids().size());
    assertEquals("Top", objectClass.getSuperiorOids().get(0));
    assertEquals(ObjectClassTypeEnum.STRUCTURAL, objectClass.getType());
    assertEquals(1, objectClass.getMustAttributeTypeOids().size());
    assertEquals("cn", objectClass.getMustAttributeTypeOids().get(0));
    assertEquals(11, objectClass.getMayAttributeTypeOids().size());
    assertEquals("description", objectClass.getMayAttributeTypeOids().get(0));
    assertEquals("fullName", objectClass.getMayAttributeTypeOids().get(10));
    assertEquals(5, objectClass.getExtensions().size());
    assertNotNull(objectClass.getExtension("X-NDS_NAMING"));
    assertEquals(1, objectClass.getExtension("X-NDS_NAMING").size());
    assertEquals("cn", objectClass.getExtension("X-NDS_NAMING").get(0));
    assertNotNull(objectClass.getExtension("X-NDS_NOT_CONTAINER"));
    assertEquals(1, objectClass.getExtension("X-NDS_NOT_CONTAINER").size());
    assertEquals("1", objectClass.getExtension("X-NDS_NOT_CONTAINER").get(0));
    assertNotNull(objectClass.getExtension("X-NDS_NONREMOVABLE"));
    assertEquals(1, objectClass.getExtension("X-NDS_NONREMOVABLE").size());
    assertEquals("1", objectClass.getExtension("X-NDS_NONREMOVABLE").get(0));
    // X-NDS_CONTAINMENT ( 'Organization' 'organizationalUnit' 'domain' )
    assertNotNull(objectClass.getExtension("X-NDS_CONTAINMENT"));
    assertEquals(3, objectClass.getExtension("X-NDS_CONTAINMENT").size());
    assertEquals("Organization", objectClass.getExtension("X-NDS_CONTAINMENT").get(0));
    assertEquals("organizationalUnit", objectClass.getExtension("X-NDS_CONTAINMENT").get(1));
    assertEquals("domain", objectClass.getExtension("X-NDS_CONTAINMENT").get(2));
    // X-NDS_ACL_TEMPLATES '2#entry#[Root Template]#member'
    assertNotNull(objectClass.getExtension("X-NDS_ACL_TEMPLATES"));
    assertEquals(1, objectClass.getExtension("X-NDS_ACL_TEMPLATES").size());
    assertEquals("2#entry#[Root Template]#member", objectClass.getExtension("X-NDS_ACL_TEMPLATES").get(0));
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) Test(org.junit.Test)

Example 35 with ObjectClass

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

the class ObjectClassDescriptionSchemaParserTest method testSiemensDirxX500Subschema.

@Test
public void testSiemensDirxX500Subschema() throws ParseException, NamingException {
    String value = "( 2.5.20.1 NAME 'x500subSchema' AUXILIARY MAY (dITStructureRules $ nameForms $ dITContentRules $ x500objectClasses $ x500attributeTypes $ matchingRules $ matchingRuleUse) )";
    ObjectClass objectClass = parser.parseObjectClassDescription(value);
    assertEquals("2.5.20.1", objectClass.getOid());
    assertEquals(1, objectClass.getNames().size());
    assertEquals("x500subSchema", objectClass.getNames().get(0));
    assertNull(objectClass.getDescription());
    assertEquals(0, objectClass.getSuperiorOids().size());
    assertEquals(ObjectClassTypeEnum.AUXILIARY, objectClass.getType());
    assertEquals(0, objectClass.getMustAttributeTypeOids().size());
    assertEquals(7, objectClass.getMayAttributeTypeOids().size());
    assertEquals("dITStructureRules", objectClass.getMayAttributeTypeOids().get(0));
    assertEquals("matchingRuleUse", objectClass.getMayAttributeTypeOids().get(6));
    assertEquals(0, objectClass.getExtensions().size());
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) Test(org.junit.Test)

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