Search in sources :

Example 66 with Schema

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

the class LdifSchemaLoader method loadDitContentRules.

/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadDitContentRules(Schema... schemas) throws LdapException, IOException {
    List<Entry> ditContentRuleList = new ArrayList<>();
    if (schemas == null) {
        return ditContentRuleList;
    }
    for (Schema schema : schemas) {
        File ditContentRulesDirectory = new File(getSchemaDirectory(schema), SchemaConstants.DIT_CONTENT_RULES_PATH);
        if (!ditContentRulesDirectory.exists()) {
            return ditContentRuleList;
        }
        File[] ditContentRuleFiles = ditContentRulesDirectory.listFiles(ldifFilter);
        if (ditContentRuleFiles != null) {
            for (File ldifFile : ditContentRuleFiles) {
                LdifReader reader = new LdifReader(ldifFile);
                LdifEntry entry = reader.next();
                reader.close();
                ditContentRuleList.add(entry.getEntry());
            }
        }
    }
    return ditContentRuleList;
}
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) File(java.io.File) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry)

Example 67 with Schema

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

the class LdifSchemaLoader method initializeSchemas.

/**
 * Scans for LDIF files just describing the various schema contained in
 * the schema repository.
 *
 * @throws LdapException
 */
private void initializeSchemas() throws LdapException, IOException {
    if (IS_DEBUG) {
        LOG.debug(I18n.msg(I18n.MSG_16006_INITIALIZING_SCHEMA));
    }
    File schemaDirectory = new File(baseDirectory, SchemaConstants.OU_SCHEMA);
    String[] ldifFiles = schemaDirectory.list(ldifFilter);
    if (ldifFiles != null) {
        for (String ldifFile : ldifFiles) {
            File file = new File(schemaDirectory, ldifFile);
            try (LdifReader reader = new LdifReader(file)) {
                LdifEntry entry = reader.next();
                Schema schema = getSchema(entry.getEntry());
                if (schema == null) {
                    // The entry was not a schema, skip it
                    continue;
                }
                schemaMap.put(schema.getSchemaName(), schema);
                if (IS_DEBUG) {
                    LOG.debug(I18n.msg(I18n.MSG_16007_SCHEMA_INITIALIZED, schema));
                }
            } catch (LdapException e) {
                LOG.error(I18n.err(I18n.ERR_16009_LDIF_LOAD_FAIL, ldifFile), e);
                throw e;
            }
        }
    }
}
Also used : LdifReader(org.apache.directory.api.ldap.model.ldif.LdifReader) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) File(java.io.File) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry)

Example 68 with Schema

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

the class LdifSchemaLoader method loadMatchingRuleUses.

/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadMatchingRuleUses(Schema... schemas) throws LdapException, IOException {
    List<Entry> matchingRuleUseList = new ArrayList<>();
    if (schemas == null) {
        return matchingRuleUseList;
    }
    for (Schema schema : schemas) {
        File matchingRuleUsesDirectory = new File(getSchemaDirectory(schema), SchemaConstants.MATCHING_RULE_USE_PATH);
        if (!matchingRuleUsesDirectory.exists()) {
            return matchingRuleUseList;
        }
        File[] matchingRuleUseFiles = matchingRuleUsesDirectory.listFiles(ldifFilter);
        if (matchingRuleUseFiles != null) {
            for (File ldifFile : matchingRuleUseFiles) {
                LdifReader reader = new LdifReader(ldifFile);
                LdifEntry entry = reader.next();
                reader.close();
                matchingRuleUseList.add(entry.getEntry());
            }
        }
    }
    return matchingRuleUseList;
}
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) File(java.io.File) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry)

Example 69 with Schema

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

the class LdifSchemaLoader method loadMatchingRules.

/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadMatchingRules(Schema... schemas) throws LdapException, IOException {
    List<Entry> matchingRuleList = new ArrayList<>();
    if (schemas == null) {
        return matchingRuleList;
    }
    for (Schema schema : schemas) {
        File matchingRulesDirectory = new File(getSchemaDirectory(schema), SchemaConstants.MATCHING_RULES_PATH);
        if (!matchingRulesDirectory.exists()) {
            return matchingRuleList;
        }
        File[] matchingRuleFiles = matchingRulesDirectory.listFiles(ldifFilter);
        if (matchingRuleFiles != null) {
            for (File ldifFile : matchingRuleFiles) {
                LdifReader reader = new LdifReader(ldifFile);
                LdifEntry entry = reader.next();
                reader.close();
                matchingRuleList.add(entry.getEntry());
            }
        }
    }
    return matchingRuleList;
}
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) File(java.io.File) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry)

Example 70 with Schema

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

the class LdifSchemaLoader 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
        File objectClassesDirectory = new File(getSchemaDirectory(schema), SchemaConstants.OBJECT_CLASSES_PATH);
        if (!objectClassesDirectory.exists()) {
            return objectClassList;
        }
        // get list of objectClass LDIF files from directory and load
        File[] objectClassFiles = objectClassesDirectory.listFiles(ldifFilter);
        if (objectClassFiles != null) {
            for (File ldifFile : objectClassFiles) {
                LdifReader reader = new LdifReader(ldifFile);
                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) File(java.io.File) 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