Search in sources :

Example 1 with OpenLdapSchemaParser

use of org.apache.directory.api.ldap.model.schema.parsers.OpenLdapSchemaParser in project directory-ldap-api by apache.

the class LdapNetworkConnection method addSchema.

/**
 * parses the given schema file present in OpenLDAP schema format
 * and adds all the SchemaObjects present in it to the SchemaManager
 *
 * @param schemaFile the schema file in OpenLDAP schema format
 * @throws LdapException in case of any errors while parsing
 */
public void addSchema(File schemaFile) throws LdapException {
    try {
        if (schemaManager == null) {
            loadSchema();
        }
        if (schemaManager == null) {
            throw new LdapException("Cannot load the schema");
        }
        OpenLdapSchemaParser olsp = new OpenLdapSchemaParser();
        olsp.setQuirksMode(true);
        olsp.parse(schemaFile);
        Registries registries = schemaManager.getRegistries();
        List<Throwable> errors = new ArrayList<>();
        for (AttributeType atType : olsp.getAttributeTypes()) {
            registries.buildReference(errors, atType);
            registries.getAttributeTypeRegistry().register(atType);
        }
        for (ObjectClass oc : olsp.getObjectClassTypes()) {
            registries.buildReference(errors, oc);
            registries.getObjectClassRegistry().register(oc);
        }
        LOG.info("successfully loaded the schema from file {}", schemaFile.getAbsolutePath());
    } catch (Exception e) {
        LOG.error(I18n.err(I18n.ERR_03206_FAIL_LOAD_SCHEMA_FILE, schemaFile.getAbsolutePath()));
        throw new LdapException(e);
    }
}
Also used : OpenLdapSchemaParser(org.apache.directory.api.ldap.model.schema.parsers.OpenLdapSchemaParser) ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) ArrayList(java.util.ArrayList) Registries(org.apache.directory.api.ldap.model.schema.registries.Registries) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException) InvalidConnectionException(org.apache.directory.ldap.client.api.exception.InvalidConnectionException) LdapOperationException(org.apache.directory.api.ldap.model.exception.LdapOperationException) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) MessageEncoderException(org.apache.directory.api.ldap.codec.api.MessageEncoderException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) DecoderException(org.apache.directory.api.asn1.DecoderException) LdapNoPermissionException(org.apache.directory.api.ldap.model.exception.LdapNoPermissionException) LdapOtherException(org.apache.directory.api.ldap.model.exception.LdapOtherException) ProtocolEncoderException(org.apache.mina.filter.codec.ProtocolEncoderException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Aggregations

IOException (java.io.IOException)1 ConnectException (java.net.ConnectException)1 UnresolvedAddressException (java.nio.channels.UnresolvedAddressException)1 ArrayList (java.util.ArrayList)1 DecoderException (org.apache.directory.api.asn1.DecoderException)1 MessageEncoderException (org.apache.directory.api.ldap.codec.api.MessageEncoderException)1 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)1 LdapAuthenticationException (org.apache.directory.api.ldap.model.exception.LdapAuthenticationException)1 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)1 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)1 LdapNoPermissionException (org.apache.directory.api.ldap.model.exception.LdapNoPermissionException)1 LdapOperationException (org.apache.directory.api.ldap.model.exception.LdapOperationException)1 LdapOtherException (org.apache.directory.api.ldap.model.exception.LdapOtherException)1 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)1 ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)1 OpenLdapSchemaParser (org.apache.directory.api.ldap.model.schema.parsers.OpenLdapSchemaParser)1 Registries (org.apache.directory.api.ldap.model.schema.registries.Registries)1 InvalidConnectionException (org.apache.directory.ldap.client.api.exception.InvalidConnectionException)1 ProtocolEncoderException (org.apache.mina.filter.codec.ProtocolEncoderException)1