Search in sources :

Example 16 with Schema

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

the class DefaultSchemaManager method loadAllEnabled.

/**
 * {@inheritDoc}
 */
@Override
public boolean loadAllEnabled() throws LdapException {
    Schema[] schemas = new Schema[schemaMap.size()];
    int i = 0;
    for (Schema schema : schemaMap.values()) {
        if (schema.isEnabled()) {
            schemas[i++] = schema;
        }
    }
    Schema[] enabledSchemas = new Schema[i];
    System.arraycopy(schemas, 0, enabledSchemas, 0, i);
    return loadWithDeps(enabledSchemas);
}
Also used : Schema(org.apache.directory.api.ldap.model.schema.registries.Schema)

Example 17 with Schema

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

the class JarLdifSchemaLoader method initializeSchemas.

/**
 * Scans for LDIF files just describing the various schema contained in
 * the schema repository.
 *
 * @throws LdapException
 */
private void initializeSchemas() throws IOException, LdapException {
    if (IS_DEBUG) {
        LOG.debug(I18n.msg(I18n.MSG_16006_INITIALIZING_SCHEMA));
    }
    Pattern pat = Pattern.compile("schema" + SEPARATOR_PATTERN + "ou=schema" + SEPARATOR_PATTERN + "cn=[a-z0-9-_]*\\." + LDIF_EXT);
    for (String file : RESOURCE_MAP.keySet()) {
        if (pat.matcher(file).matches()) {
            URL resource = getResource(file, "schema LDIF file");
            InputStream in = resource.openStream();
            try {
                LdifReader reader = new LdifReader(in);
                LdifEntry entry = reader.next();
                reader.close();
                Schema schema = getSchema(entry.getEntry());
                schemaMap.put(schema.getSchemaName(), schema);
                if (IS_DEBUG) {
                    LOG.debug(I18n.msg(I18n.MSG_16007_SCHEMA_INITIALIZED, schema));
                }
            } catch (LdapException le) {
                LOG.error(I18n.err(I18n.ERR_16009_LDIF_LOAD_FAIL, file), le);
                throw le;
            } finally {
                in.close();
            }
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) LdifReader(org.apache.directory.api.ldap.model.ldif.LdifReader) InputStream(java.io.InputStream) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) URL(java.net.URL) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry)

Example 18 with Schema

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

the class JarLdifSchemaLoader method loadComparators.

/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadComparators(Schema... schemas) throws LdapException, IOException {
    List<Entry> comparatorList = new ArrayList<>();
    if (schemas == null) {
        return comparatorList;
    }
    for (Schema schema : schemas) {
        String start = getSchemaDirectoryString(schema) + SchemaConstants.COMPARATORS_PATH + "/" + "m-oid=";
        String end = "." + LDIF_EXT;
        for (String resourcePath : RESOURCE_MAP.keySet()) {
            if (resourcePath.startsWith(start) && resourcePath.endsWith(end)) {
                URL resource = getResource(resourcePath, "comparator LDIF file");
                LdifReader reader = new LdifReader(resource.openStream());
                LdifEntry entry = reader.next();
                reader.close();
                comparatorList.add(entry.getEntry());
            }
        }
    }
    return comparatorList;
}
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 19 with Schema

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

the class JarLdifSchemaLoader method loadSyntaxCheckers.

/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadSyntaxCheckers(Schema... schemas) throws LdapException, IOException {
    List<Entry> syntaxCheckerList = new ArrayList<>();
    if (schemas == null) {
        return syntaxCheckerList;
    }
    for (Schema schema : schemas) {
        String start = getSchemaDirectoryString(schema) + SchemaConstants.SYNTAX_CHECKERS_PATH + "/" + "m-oid=";
        String end = "." + LDIF_EXT;
        for (String resourcePath : RESOURCE_MAP.keySet()) {
            if (resourcePath.startsWith(start) && resourcePath.endsWith(end)) {
                URL resource = getResource(resourcePath, "syntaxChecker LDIF file");
                LdifReader reader = new LdifReader(resource.openStream());
                LdifEntry entry = reader.next();
                reader.close();
                syntaxCheckerList.add(entry.getEntry());
            }
        }
    }
    return syntaxCheckerList;
}
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 20 with Schema

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

the class JarLdifSchemaLoader method loadAttributeTypes.

/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadAttributeTypes(Schema... schemas) throws LdapException, IOException {
    List<Entry> attributeTypeList = new ArrayList<>();
    if (schemas == null) {
        return attributeTypeList;
    }
    for (Schema schema : schemas) {
        // check that the attributeTypes directory exists for the schema
        String start = getSchemaDirectoryString(schema) + SchemaConstants.ATTRIBUTE_TYPES_PATH + "/" + "m-oid=";
        String end = "." + LDIF_EXT;
        // get list of attributeType LDIF schema files in attributeTypes
        for (String resourcePath : RESOURCE_MAP.keySet()) {
            if (resourcePath.startsWith(start) && resourcePath.endsWith(end)) {
                URL resource = getResource(resourcePath, "attributeType LDIF file");
                LdifReader reader = new LdifReader(resource.openStream());
                LdifEntry entry = reader.next();
                reader.close();
                attributeTypeList.add(entry.getEntry());
            }
        }
    }
    return attributeTypeList;
}
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)73 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)27 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