Search in sources :

Example 26 with Schema

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

the class LdifSchemaLoader 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) {
        File nameFormsDirectory = new File(getSchemaDirectory(schema), SchemaConstants.NAME_FORMS_PATH);
        if (!nameFormsDirectory.exists()) {
            return nameFormList;
        }
        File[] nameFormFiles = nameFormsDirectory.listFiles(ldifFilter);
        if (nameFormFiles != null) {
            for (File ldifFile : nameFormFiles) {
                LdifReader reader = new LdifReader(ldifFile);
                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) File(java.io.File) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry)

Example 27 with Schema

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

the class LdifSchemaLoader 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) {
        File syntaxesDirectory = new File(getSchemaDirectory(schema), SchemaConstants.SYNTAXES_PATH);
        if (!syntaxesDirectory.exists()) {
            return syntaxList;
        }
        File[] syntaxFiles = syntaxesDirectory.listFiles(ldifFilter);
        if (syntaxFiles != null) {
            for (File ldifFile : syntaxFiles) {
                LdifReader reader = new LdifReader(ldifFile);
                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) File(java.io.File) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry)

Example 28 with Schema

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

the class SchemaEntityFactory method getObjectClass.

/**
 * {@inheritDoc}
 */
@Override
public ObjectClass getObjectClass(SchemaManager schemaManager, Entry entry, Registries targetRegistries, String schemaName) throws LdapException {
    checkEntry(entry, SchemaConstants.OBJECT_CLASS);
    // The ObjectClass OID
    String oid = getOid(entry, SchemaConstants.OBJECT_CLASS, schemaManager.isStrict());
    // Get the schema
    if (!schemaManager.isSchemaLoaded(schemaName)) {
        // The schema is not loaded. We can't create the requested ObjectClass
        String msg = I18n.err(I18n.ERR_16030_CANNOT_ADD_OC, entry.getDn().getName(), schemaName);
        LOG.warn(msg);
        throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
    }
    Schema schema = getSchema(schemaName, targetRegistries);
    if (schema == null) {
        // The schema is disabled. We still have to update the backend
        String msg = I18n.err(I18n.ERR_16031_CANNOT_ADD_OC_IN_REGISTRY, entry.getDn().getName(), schemaName);
        LOG.info(msg);
        schema = schemaManager.getLoadedSchema(schemaName);
    }
    // Create the ObjectClass instance
    MutableObjectClass oc = new MutableObjectClass(oid);
    // The Sup field
    Attribute mSuperiors = entry.get(MetaSchemaConstants.M_SUP_OBJECT_CLASS_AT);
    if (mSuperiors != null) {
        oc.setSuperiorOids(getStrings(mSuperiors));
    }
    // The May field
    Attribute mMay = entry.get(MetaSchemaConstants.M_MAY_AT);
    if (mMay != null) {
        oc.setMayAttributeTypeOids(getStrings(mMay));
    }
    // The Must field
    Attribute mMust = entry.get(MetaSchemaConstants.M_MUST_AT);
    if (mMust != null) {
        oc.setMustAttributeTypeOids(getStrings(mMust));
    }
    // The objectClassType field
    Attribute mTypeObjectClass = entry.get(MetaSchemaConstants.M_TYPE_OBJECT_CLASS_AT);
    if (mTypeObjectClass != null) {
        String type = mTypeObjectClass.getString();
        oc.setType(ObjectClassTypeEnum.getClassType(type));
    }
    // Common properties
    setSchemaObjectProperties(oc, entry, schema);
    return oc;
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) MutableObjectClass(org.apache.directory.api.ldap.model.schema.MutableObjectClass)

Example 29 with Schema

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

the class DefaultSchemaLoader method loadNameForms.

/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadNameForms(Schema... schemas) throws LdapException, IOException {
    List<Entry> nameFormEntries = new ArrayList<>();
    if (schemas == null) {
        return nameFormEntries;
    }
    AttributesFactory factory = new AttributesFactory();
    for (Schema schema : schemas) {
        Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
        for (SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers) {
            SchemaObject schemaObject = schemaObjectWrapper.get();
            if (schemaObject instanceof NameForm) {
                NameForm nameForm = (NameForm) schemaObject;
                Entry nameFormEntry = factory.convert(nameForm, schema, null);
                nameFormEntries.add(nameFormEntry);
            }
        }
    }
    return nameFormEntries;
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) AttributesFactory(org.apache.directory.api.ldap.model.schema.AttributesFactory) NameForm(org.apache.directory.api.ldap.model.schema.NameForm) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) ArrayList(java.util.ArrayList) SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)

Example 30 with Schema

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

the class DefaultSchemaLoader method loadMatchingRules.

/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadMatchingRules(Schema... schemas) throws LdapException, IOException {
    List<Entry> matchingRuleEntries = new ArrayList<>();
    if (schemas == null) {
        return matchingRuleEntries;
    }
    AttributesFactory factory = new AttributesFactory();
    for (Schema schema : schemas) {
        Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
        for (SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers) {
            SchemaObject schemaObject = schemaObjectWrapper.get();
            if (schemaObject instanceof MatchingRule) {
                MatchingRule matchingRule = (MatchingRule) schemaObject;
                Entry matchingRuleEntry = factory.convert(matchingRule, schema, null);
                matchingRuleEntries.add(matchingRuleEntry);
            }
        }
    }
    return matchingRuleEntries;
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) AttributesFactory(org.apache.directory.api.ldap.model.schema.AttributesFactory) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) ArrayList(java.util.ArrayList) SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule)

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