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;
}
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;
}
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;
}
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;
}
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());
}
Aggregations