use of org.apache.directory.api.ldap.model.schema.registries.Schema 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());
}
use of org.apache.directory.api.ldap.model.schema.registries.Schema in project directory-ldap-api by apache.
the class DefaultSchemaLoader method loadDitStructureRules.
/**
* {@inheritDoc}
*/
@Override
public List<Entry> loadDitStructureRules(Schema... schemas) throws LdapException, IOException {
List<Entry> ditStructureRuleEntries = new ArrayList<>();
if (schemas == null) {
return ditStructureRuleEntries;
}
AttributesFactory factory = new AttributesFactory();
for (Schema schema : schemas) {
Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
for (SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers) {
SchemaObject schemaObject = schemaObjectWrapper.get();
if (schemaObject instanceof DitStructureRule) {
DitStructureRule ditStructureRule = (DitStructureRule) schemaObject;
Entry ditStructureRuleEntry = factory.convert(ditStructureRule, schema, null);
ditStructureRuleEntries.add(ditStructureRuleEntry);
}
}
}
return ditStructureRuleEntries;
}
use of org.apache.directory.api.ldap.model.schema.registries.Schema in project directory-ldap-api by apache.
the class DefaultSchemaLoader method updateSchemas.
private void updateSchemas(SchemaObject schemaObject) {
String schemaName = schemaObject.getSchemaName();
Schema schema;
if (Strings.isEmpty(schemaName) || "null".equals(schemaName)) {
schemaName = "default";
schema = schemaMap.get(schemaName);
} else {
schema = schemaMap.get(schemaName);
}
if (schema == null) {
schema = new DefaultSchema(this, schemaName);
schemaMap.put(schemaName, schema);
}
schema.getContent().add(new SchemaObjectWrapper(schemaObject));
}
use of org.apache.directory.api.ldap.model.schema.registries.Schema in project directory-ldap-api by apache.
the class DefaultSchemaLoader method loadNormalizers.
/**
* {@inheritDoc}
*/
@Override
public List<Entry> loadNormalizers(Schema... schemas) throws LdapException, IOException {
List<Entry> normalizerEntries = new ArrayList<>();
if (schemas == null) {
return normalizerEntries;
}
for (Schema schema : schemas) {
Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
for (SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers) {
SchemaObject schemaObject = schemaObjectWrapper.get();
if (schemaObject instanceof NormalizerDescription) {
NormalizerDescription normalizerDescription = (NormalizerDescription) schemaObject;
Entry normalizerEntry = getEntry(normalizerDescription);
normalizerEntries.add(normalizerEntry);
}
}
}
return normalizerEntries;
}
use of org.apache.directory.api.ldap.model.schema.registries.Schema in project directory-ldap-api by apache.
the class DefaultSchemaLoader method loadComparators.
/**
* {@inheritDoc}
*/
@Override
public List<Entry> loadComparators(Schema... schemas) throws LdapException, IOException {
List<Entry> comparatorEntries = new ArrayList<>();
if (schemas == null) {
return comparatorEntries;
}
for (Schema schema : schemas) {
Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
for (SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers) {
SchemaObject schemaObject = schemaObjectWrapper.get();
if (schemaObject instanceof LdapComparatorDescription) {
LdapComparatorDescription ldapComparatorDescription = (LdapComparatorDescription) schemaObject;
Entry lcEntry = getEntry(ldapComparatorDescription);
comparatorEntries.add(lcEntry);
}
}
}
return comparatorEntries;
}
Aggregations