Search in sources :

Example 56 with Schema

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

the class DefaultSchemaManager method disable.

// -----------------------------------------------------------------------
// API methods
// -----------------------------------------------------------------------
/**
 * {@inheritDoc}
 */
@Override
public boolean disable(Schema... schemas) throws LdapException {
    boolean disabled = false;
    // Reset the errors if not null
    if (errors != null) {
        errors.clear();
    }
    // Work on a cloned and relaxed registries
    Registries clonedRegistries = cloneRegistries();
    clonedRegistries.setRelaxed();
    for (Schema schema : schemas) {
        unload(clonedRegistries, schema);
    }
    // Build the cross references
    errors = clonedRegistries.buildReferences();
    // Destroy the clonedRegistry
    clonedRegistries.clear();
    if (errors.isEmpty()) {
        // Ok no errors. Check the registries now
        errors = clonedRegistries.checkRefInteg();
        if (errors.isEmpty()) {
            // We are golden : let's apply the schemas in the real registries
            for (Schema schema : schemas) {
                unload(registries, schema);
                schema.disable();
            }
            // Build the cross references
            errors = registries.buildReferences();
            registries.setStrict();
            disabled = true;
        }
    }
    // clear the cloned registries
    clonedRegistries.clear();
    return disabled;
}
Also used : Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) Registries(org.apache.directory.api.ldap.model.schema.registries.Registries)

Example 57 with Schema

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

the class MatchingRuleTest method setup.

@BeforeClass
public static void setup() throws Exception {
    workingDirectory = System.getProperty("workingDirectory");
    if (workingDirectory == null) {
        String path = MatchingRuleTest.class.getResource("").getPath();
        int targetPos = path.indexOf("target");
        workingDirectory = path.substring(0, targetPos + 6);
    }
    schemaRepository = new File(workingDirectory, "schema");
    // Cleanup the target directory
    FileUtils.deleteDirectory(schemaRepository);
    SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor(new File(workingDirectory));
    extractor.extractOrCopy();
    LdifSchemaLoader loader = new LdifSchemaLoader(schemaRepository);
    schemaManager = new DefaultSchemaManager(loader);
    for (Schema schema : loader.getAllSchemas()) {
        schema.enable();
    }
    schemaManager.loadAllEnabled();
}
Also used : Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) SchemaLdifExtractor(org.apache.directory.api.ldap.schema.extractor.SchemaLdifExtractor) DefaultSchemaLdifExtractor(org.apache.directory.api.ldap.schema.extractor.impl.DefaultSchemaLdifExtractor) DefaultSchemaLdifExtractor(org.apache.directory.api.ldap.schema.extractor.impl.DefaultSchemaLdifExtractor) File(java.io.File) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) BeforeClass(org.junit.BeforeClass)

Example 58 with Schema

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

the class JarLdifSchemaLoader method loadSyntaxes.

/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadSyntaxes(Schema... schemas) throws LdapException, IOException {
    List<Entry> syntaxList = new ArrayList<>();
    if (schemas == null) {
        return syntaxList;
    }
    for (Schema schema : schemas) {
        String start = getSchemaDirectoryString(schema) + SchemaConstants.SYNTAXES_PATH + "/" + "m-oid=";
        String end = "." + LDIF_EXT;
        for (String resourcePath : RESOURCE_MAP.keySet()) {
            if (resourcePath.startsWith(start) && resourcePath.endsWith(end)) {
                URL resource = getResource(resourcePath, "syntax LDIF file");
                LdifReader reader = new LdifReader(resource.openStream());
                LdifEntry entry = reader.next();
                reader.close();
                syntaxList.add(entry.getEntry());
            }
        }
    }
    return syntaxList;
}
Also used : Entry(org.apache.directory.api.ldap.model.entry.Entry) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) LdifReader(org.apache.directory.api.ldap.model.ldif.LdifReader) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) ArrayList(java.util.ArrayList) URL(java.net.URL) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry)

Example 59 with Schema

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

the class JarLdifSchemaLoader method loadNameForms.

/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadNameForms(Schema... schemas) throws LdapException, IOException {
    List<Entry> nameFormList = new ArrayList<>();
    if (schemas == null) {
        return nameFormList;
    }
    for (Schema schema : schemas) {
        String start = getSchemaDirectoryString(schema) + SchemaConstants.NAME_FORMS_PATH + "/" + "m-oid=";
        String end = "." + LDIF_EXT;
        for (String resourcePath : RESOURCE_MAP.keySet()) {
            if (resourcePath.startsWith(start) && resourcePath.endsWith(end)) {
                URL resource = getResource(resourcePath, "nameForm LDIF file");
                LdifReader reader = new LdifReader(resource.openStream());
                LdifEntry entry = reader.next();
                reader.close();
                nameFormList.add(entry.getEntry());
            }
        }
    }
    return nameFormList;
}
Also used : Entry(org.apache.directory.api.ldap.model.entry.Entry) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) LdifReader(org.apache.directory.api.ldap.model.ldif.LdifReader) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) ArrayList(java.util.ArrayList) URL(java.net.URL) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry)

Example 60 with Schema

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

the class JarLdifSchemaLoader method loadObjectClasses.

/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadObjectClasses(Schema... schemas) throws LdapException, IOException {
    List<Entry> objectClassList = new ArrayList<>();
    if (schemas == null) {
        return objectClassList;
    }
    for (Schema schema : schemas) {
        // get objectClasses directory, check if exists, return if not
        String start = getSchemaDirectoryString(schema) + SchemaConstants.OBJECT_CLASSES_PATH + "/" + "m-oid=";
        String end = "." + LDIF_EXT;
        for (String resourcePath : RESOURCE_MAP.keySet()) {
            if (resourcePath.startsWith(start) && resourcePath.endsWith(end)) {
                URL resource = getResource(resourcePath, "objectClass LDIF file");
                LdifReader reader = new LdifReader(resource.openStream());
                LdifEntry entry = reader.next();
                reader.close();
                objectClassList.add(entry.getEntry());
            }
        }
    }
    return objectClassList;
}
Also used : Entry(org.apache.directory.api.ldap.model.entry.Entry) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) LdifReader(org.apache.directory.api.ldap.model.ldif.LdifReader) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) ArrayList(java.util.ArrayList) URL(java.net.URL) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry)

Aggregations

Schema (org.apache.directory.api.ldap.model.schema.registries.Schema)74 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)28 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