use of org.apache.directory.api.ldap.model.schema.registries.Schema in project directory-ldap-api by apache.
the class DefaultSchemaLoader method loadSyntaxCheckers.
/**
* {@inheritDoc}
*/
@Override
public List<Entry> loadSyntaxCheckers(Schema... schemas) throws LdapException, IOException {
List<Entry> syntaxCheckerEntries = new ArrayList<>();
if (schemas == null) {
return syntaxCheckerEntries;
}
for (Schema schema : schemas) {
Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
for (SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers) {
SchemaObject schemaObject = schemaObjectWrapper.get();
if (schemaObject instanceof SyntaxCheckerDescription) {
SyntaxCheckerDescription syntaxCheckerDescription = (SyntaxCheckerDescription) schemaObject;
Entry syntaxCheckerEntry = getEntry(syntaxCheckerDescription);
syntaxCheckerEntries.add(syntaxCheckerEntry);
}
}
}
return syntaxCheckerEntries;
}
use of org.apache.directory.api.ldap.model.schema.registries.Schema in project directory-ldap-api by apache.
the class DefaultSchemaLoader method loadDitContentRules.
/**
* {@inheritDoc}
*/
@Override
public List<Entry> loadDitContentRules(Schema... schemas) throws LdapException, IOException {
List<Entry> ditContentRuleEntries = new ArrayList<>();
if (schemas == null) {
return ditContentRuleEntries;
}
AttributesFactory factory = new AttributesFactory();
for (Schema schema : schemas) {
Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
for (SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers) {
SchemaObject schemaObject = schemaObjectWrapper.get();
if (schemaObject instanceof DitContentRule) {
DitContentRule ditContentRule = (DitContentRule) schemaObject;
Entry ditContentRuleEntry = factory.convert(ditContentRule, schema, null);
ditContentRuleEntries.add(ditContentRuleEntry);
}
}
}
return ditContentRuleEntries;
}
use of org.apache.directory.api.ldap.model.schema.registries.Schema in project directory-ldap-api by apache.
the class SchemaManagerLoadTest method loadNewSchemaBadDependencies.
/**
* Test that we can't load a new schema with bad dependencies
*/
@Test
public void loadNewSchemaBadDependencies() throws Exception {
LdifSchemaLoader loader = new LdifSchemaLoader(schemaRepository);
SchemaManager schemaManager = new DefaultSchemaManager(loader);
Schema dummy = new DefaultSchema(loader, "dummy");
dummy.addDependencies("bad");
assertFalse(schemaManager.load(dummy));
assertFalse(schemaManager.getErrors().isEmpty());
assertEquals(0, schemaManager.getAttributeTypeRegistry().size());
assertEquals(0, schemaManager.getComparatorRegistry().size());
assertEquals(0, schemaManager.getMatchingRuleRegistry().size());
assertEquals(0, schemaManager.getNormalizerRegistry().size());
assertEquals(0, schemaManager.getObjectClassRegistry().size());
assertEquals(0, schemaManager.getSyntaxCheckerRegistry().size());
assertEquals(0, schemaManager.getLdapSyntaxRegistry().size());
assertEquals(0, schemaManager.getGlobalOidRegistry().size());
assertEquals(0, schemaManager.getRegistries().getLoadedSchemas().size());
assertNull(schemaManager.getRegistries().getLoadedSchema("dummy"));
}
use of org.apache.directory.api.ldap.model.schema.registries.Schema in project directory-ldap-api by apache.
the class SchemaManagerLoadTest method testLoadSchemasWithDepsCoreInetOrgPersonAndBad.
// ---------------------------------------------------------------------------
// Test the load( Schema... ) method
// ---------------------------------------------------------------------------
/**
* test loading the "InetOrgPerson", "core" and an empty schema. The empty schema
* should be present in the registries, as it's a vaid schema
*/
@Test
public void testLoadSchemasWithDepsCoreInetOrgPersonAndBad() throws Exception {
LdifSchemaLoader loader = new LdifSchemaLoader(schemaRepository);
SchemaManager schemaManager = new DefaultSchemaManager(loader);
Schema system = loader.getSchema("system");
Schema core = loader.getSchema("core");
Schema empty = new DefaultSchema(loader, "empty");
Schema cosine = loader.getSchema("cosine");
Schema inetOrgPerson = loader.getSchema("InetOrgPerson");
assertTrue(schemaManager.load(system, core, empty, cosine, inetOrgPerson));
assertTrue(schemaManager.getErrors().isEmpty());
assertEquals(142, schemaManager.getAttributeTypeRegistry().size());
assertEquals(36, schemaManager.getComparatorRegistry().size());
assertEquals(42, schemaManager.getMatchingRuleRegistry().size());
assertEquals(35, schemaManager.getNormalizerRegistry().size());
assertEquals(50, schemaManager.getObjectClassRegistry().size());
assertEquals(59, schemaManager.getSyntaxCheckerRegistry().size());
assertEquals(66, schemaManager.getLdapSyntaxRegistry().size());
assertEquals(300, schemaManager.getGlobalOidRegistry().size());
assertEquals(5, schemaManager.getRegistries().getLoadedSchemas().size());
assertNotNull(schemaManager.getRegistries().getLoadedSchema("system"));
assertNotNull(schemaManager.getRegistries().getLoadedSchema("core"));
assertNotNull(schemaManager.getRegistries().getLoadedSchema("cosine"));
assertNotNull(schemaManager.getRegistries().getLoadedSchema("InetOrgPerson"));
assertNotNull(schemaManager.getRegistries().getLoadedSchema("empty"));
}
use of org.apache.directory.api.ldap.model.schema.registries.Schema in project directory-ldap-api by apache.
the class SchemaMarker method initializeSchemas.
/**
* Initialize the Schema object from a Single LDIF file
*/
private void initializeSchemas(InputStream in) throws LdapException, IOException {
try (LdifReader ldifReader = new LdifReader(in)) {
Schema currentSchema = null;
while (ldifReader.hasNext()) {
LdifEntry ldifEntry = ldifReader.next();
String dn = ldifEntry.getDn().getName();
if (SCHEMA_START_PATTERN.matcher(dn).matches()) {
Schema schema = getSchema(ldifEntry.getEntry());
schemaMap.put(schema.getSchemaName(), schema);
currentSchema = schema;
} else {
if (currentSchema == null) {
throw new LdapException(I18n.err(I18n.ERR_16076_NOT_A_SCHEMA_DEFINITION));
}
loadSchemaObject(currentSchema.getSchemaName(), ldifEntry);
}
}
}
}
Aggregations