Search in sources :

Example 31 with Schema

use of org.apache.directory.api.ldap.model.schema.registries.Schema 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 32 with Schema

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

the class DefaultSchemaLoader method loadAttributeTypes.

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

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

the class DefaultSchemaLoader method loadSyntaxes.

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

Example 34 with Schema

use of org.apache.directory.api.ldap.model.schema.registries.Schema 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 35 with Schema

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

the class QuirkySchemaTest method testLoadQuirkySchema.

/**
 * Try to load a quirky schema. This schema has a lot of issues that violate the
 * standards. Therefore load the schema in relaxed mode. We should be able to work
 * with this schema anyway. E.g. the loader and schema manager should not die on
 * null pointer or similar trivial error.
 */
@Test
public void testLoadQuirkySchema() throws Exception {
    LdapConnection connection = createFakeConnection("src/test/resources/schema-quirky.ldif");
    DefaultSchemaLoader loader = new DefaultSchemaLoader(connection, true);
    Collection<Schema> allEnabled = loader.getAllEnabled();
    assertEquals(1, allEnabled.size());
    Schema schema = allEnabled.iterator().next();
    assertNotNull(schema);
    SchemaManager schemaManager = new DefaultSchemaManager(loader);
    boolean loaded = schemaManager.loadAllEnabledRelaxed();
    if (!loaded) {
        fail("Schema load failed : " + Exceptions.printErrors(schemaManager.getErrors()));
    }
    assertTrue("Surprisingly no errors after load", schemaManager.getErrors().size() > 0);
    assertTrue(schemaManager.getRegistries().getAttributeTypeRegistry().contains("cn"));
    ObjectClass person = schemaManager.getRegistries().getObjectClassRegistry().lookup("person");
    assertNotNull(person);
    assertEquals(2, person.getMustAttributeTypes().size());
    assertEquals(5, 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)

Aggregations

Schema (org.apache.directory.api.ldap.model.schema.registries.Schema)73 ArrayList (java.util.ArrayList)34 Entry (org.apache.directory.api.ldap.model.entry.Entry)34 DefaultSchema (org.apache.directory.api.ldap.model.schema.registries.DefaultSchema)27 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)26 LdifReader (org.apache.directory.api.ldap.model.ldif.LdifReader)25 File (java.io.File)13 SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)13 SchemaObjectWrapper (org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)13 URL (java.net.URL)12 LdapUnwillingToPerformException (org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException)12 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)11 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)9 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)9 Registries (org.apache.directory.api.ldap.model.schema.registries.Registries)9 AttributesFactory (org.apache.directory.api.ldap.model.schema.AttributesFactory)8 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)7 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)7 Test (org.junit.Test)7 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)6