Search in sources :

Example 1 with ComparableComparator

use of org.apache.directory.api.ldap.model.schema.comparators.ComparableComparator in project directory-ldap-api by apache.

the class MatchingRuleHelper method addToRegistries.

/**
 * Inject the MatchingRule into the Registries, updating the references to
 * other SchemaObject
 *
 * @param matchingRule The MatchingRule to add to the Registries
 * @param errors The errors we got while adding the MatchingRule to the registries
 * @param registries The Registries
 * @throws LdapException If the addition failed
 */
@SuppressWarnings("rawtypes")
public static void addToRegistries(MutableMatchingRule matchingRule, List<Throwable> errors, Registries registries) throws LdapException {
    if (registries != null) {
        try {
            matchingRule.unlock();
            LdapComparator<?> ldapComparator = null;
            Normalizer normalizer = null;
            LdapSyntax ldapSyntax = null;
            try {
                // Gets the associated Comparator
                ldapComparator = registries.getComparatorRegistry().lookup(matchingRule.getOid());
            } catch (LdapException ne) {
                // Default to a catch all comparator
                ldapComparator = new ComparableComparator(matchingRule.getOid());
            }
            try {
                // Gets the associated Normalizer
                normalizer = registries.getNormalizerRegistry().lookup(matchingRule.getOid());
            } catch (LdapException ne) {
                // Default to the NoOp normalizer
                normalizer = new NoOpNormalizer(matchingRule.getOid());
            }
            try {
                // Get the associated LdapSyntax
                ldapSyntax = registries.getLdapSyntaxRegistry().lookup(matchingRule.getSyntaxOid());
            } catch (LdapException ne) {
                // The Syntax is a mandatory element, it must exist.
                String msg = I18n.err(I18n.ERR_13765_MR_MUST_REFER_EXISTING_SYNTAX);
                LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.MR_NONEXISTENT_SYNTAX, msg, ne);
                ldapSchemaException.setSourceObject(matchingRule);
                ldapSchemaException.setRelatedId(matchingRule.getSyntaxOid());
                errors.add(ldapSchemaException);
                LOG.info(msg);
            }
            /**
             * Add the MR references (using and usedBy) :
             * MR -> C
             * MR -> N
             * MR -> S
             */
            if (ldapComparator != null) {
                registries.addReference(matchingRule, ldapComparator);
                matchingRule.setLdapComparator(ldapComparator);
            }
            if (normalizer != null) {
                registries.addReference(matchingRule, normalizer);
                matchingRule.setNormalizer(normalizer);
            }
            if (ldapSyntax != null) {
                registries.addReference(matchingRule, ldapSyntax);
                matchingRule.setSyntax(ldapSyntax);
            }
        } finally {
            matchingRule.lock();
        }
    }
}
Also used : NoOpNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer) NoOpNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) ComparableComparator(org.apache.directory.api.ldap.model.schema.comparators.ComparableComparator) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Aggregations

LdapException (org.apache.directory.api.ldap.model.exception.LdapException)1 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)1 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)1 Normalizer (org.apache.directory.api.ldap.model.schema.Normalizer)1 ComparableComparator (org.apache.directory.api.ldap.model.schema.comparators.ComparableComparator)1 NoOpNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer)1