Search in sources :

Example 21 with MatchingRule

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

the class AttributeTypeHelper method buildSubstring.

/**
 * Build the SUBSTR MR reference for an AttributeType
 */
private static void buildSubstring(MutableAttributeType attributeType, List<Throwable> errors, Registries registries) {
    String substringOid = attributeType.getSubstringOid();
    // The Substring MR. It can be null
    if (substringOid != null) {
        MatchingRule currentSubstring = null;
        try {
            currentSubstring = registries.getMatchingRuleRegistry().lookup(substringOid);
        } catch (LdapException ne) {
            // Not allowed.
            String msg = I18n.err(I18n.ERR_13760_CANNOT_FIND_SUBSTR_MR_OBJECT, substringOid, attributeType.getName());
            LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_SUBSTRING_MATCHING_RULE, msg, ne);
            ldapSchemaException.setSourceObject(attributeType);
            ldapSchemaException.setRelatedId(substringOid);
            errors.add(ldapSchemaException);
            LOG.info(msg);
            return;
        }
        if (currentSubstring != null) {
            attributeType.setSubstring(currentSubstring);
        } else {
            // Not allowed.
            String msg = I18n.err(I18n.ERR_13761_CANNOT_FIND_SUBSTR_MR_INSTANCE, substringOid, attributeType.getName());
            LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_SUBSTRING_MATCHING_RULE, msg);
            ldapSchemaException.setSourceObject(attributeType);
            ldapSchemaException.setRelatedId(substringOid);
            errors.add(ldapSchemaException);
            LOG.info(msg);
            return;
        }
    } else {
        AttributeType superior = attributeType.getSuperior();
        // If the AT has a superior, take its Substring MR if any
        if ((superior != null) && (superior.getSubstring() != null)) {
            attributeType.setSubstring(superior.getSubstring());
        }
    }
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 22 with MatchingRule

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

the class AttributeTypeHelper method buildOrdering.

/**
 * Build the ORDERING MR reference for an AttributeType
 */
private static void buildOrdering(MutableAttributeType attributeType, List<Throwable> errors, Registries registries) {
    String orderingOid = attributeType.getOrderingOid();
    if (orderingOid != null) {
        MatchingRule currentOrdering = null;
        try {
            currentOrdering = registries.getMatchingRuleRegistry().lookup(orderingOid);
        } catch (LdapException ne) {
            // Not allowed.
            String msg = I18n.err(I18n.ERR_13758_CANNOT_FIND_ORDERING_MR_OBJECT, orderingOid, attributeType.getName());
            LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_ORDERING_MATCHING_RULE, msg, ne);
            ldapSchemaException.setSourceObject(attributeType);
            ldapSchemaException.setRelatedId(orderingOid);
            errors.add(ldapSchemaException);
            LOG.info(msg);
            return;
        }
        if (currentOrdering != null) {
            attributeType.setOrdering(currentOrdering);
        } else {
            // Not allowed.
            String msg = I18n.err(I18n.ERR_13759_CANNOT_FIND_ORDERING_MR_INSTANCE, orderingOid, attributeType.getName());
            LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_ORDERING_MATCHING_RULE, msg);
            ldapSchemaException.setSourceObject(attributeType);
            ldapSchemaException.setRelatedId(orderingOid);
            errors.add(ldapSchemaException);
            LOG.info(msg);
        }
    } else {
        AttributeType superior = attributeType.getSuperior();
        // If the AT has a superior, take its Ordering MR if any
        if ((superior != null) && (superior.getOrdering() != null)) {
            attributeType.setOrdering(superior.getOrdering());
        }
    }
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 23 with MatchingRule

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

the class ConcreteNameComponentNormalizer method lookup.

/**
 * Looks up the Normalizer to use for a name component using the attributeId
 * for the name component.  First the attribute is resolved, then its
 * equality matching rule is looked up.  The normalizer of that matching
 * rule is returned.
 *
 * @param id the name or oid of the attribute in the name component to
 * normalize the value of
 * @return the Normalizer to use for normalizing the value of the attribute
 * @throws LdapException if there are failures resolving the Normalizer
 */
private Normalizer lookup(String id) throws LdapException {
    AttributeType type = schemaManager.lookupAttributeTypeRegistry(id);
    MatchingRule mrule = type.getEquality();
    if (mrule == null) {
        return new NoOpNormalizer(id);
    }
    return mrule.getNormalizer();
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule)

Example 24 with MatchingRule

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

the class MatchingRuleDescriptionSchemaParserTest method testSun2.

/**
 * This is a real matching rule from Sun Directory 5.2. It has an invalid
 * syntax, no DOTs allowed in NAME value.
 */
@Test
public void testSun2() throws ParseException, NamingException {
    String value = "( 1.3.6.1.4.1.42.2.27.9.4.34.3.6 NAME 'caseExactSubstringMatch-2.16.840.1.113730.3.3.2.11.3' DESC 'en' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )";
    if (!parser.isQuirksMode()) {
        try {
            parser.parseMatchingRuleDescription(value);
            fail("Exception expected, invalid NAME value 'caseExactSubstringMatch-2.16.840.1.113730.3.3.2.11.3' (contains DOTs)");
        } catch (ParseException pe) {
            assertTrue(true);
        }
    } else {
        MatchingRule matchingRule = parser.parseMatchingRuleDescription(value);
        assertEquals("1.3.6.1.4.1.42.2.27.9.4.34.3.6", matchingRule.getOid());
        assertEquals(1, matchingRule.getNames().size());
        assertEquals("caseExactSubstringMatch-2.16.840.1.113730.3.3.2.11.3", matchingRule.getNames().get(0));
        assertEquals("en", matchingRule.getDescription());
        assertFalse(matchingRule.isObsolete());
        assertEquals("1.3.6.1.4.1.1466.115.121.1.15", matchingRule.getSyntaxOid());
        assertEquals(0, matchingRule.getExtensions().size());
    }
}
Also used : ParseException(java.text.ParseException) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) Test(org.junit.Test)

Example 25 with MatchingRule

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

the class MatchingRuleDescriptionSchemaParserTest method testFull.

@Test
public void testFull() throws ParseException, NamingException {
    String value = null;
    MatchingRule matchingRule = null;
    value = "( 1.2.3.4.5.6.7.8.9.0 NAME ( 'abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789' 'test' ) DESC 'Descripton \u00E4\u00F6\u00FC\u00DF \u90E8\u9577' OBSOLETE SYNTAX 0.1.2.3.4.5.6.7.8.9 X-TEST-a ('test1-1' 'test1-2') X-TEST-b ('test2-1' 'test2-2') )";
    matchingRule = parser.parseMatchingRuleDescription(value);
    assertEquals("1.2.3.4.5.6.7.8.9.0", matchingRule.getOid());
    assertEquals(2, matchingRule.getNames().size());
    assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", matchingRule.getNames().get(0));
    assertEquals("test", matchingRule.getNames().get(1));
    assertEquals("Descripton \u00E4\u00F6\u00FC\u00DF \u90E8\u9577", matchingRule.getDescription());
    assertTrue(matchingRule.isObsolete());
    assertEquals("0.1.2.3.4.5.6.7.8.9", matchingRule.getSyntaxOid());
    assertEquals(2, matchingRule.getExtensions().size());
    assertNotNull(matchingRule.getExtension("X-TEST-a"));
    assertEquals(2, matchingRule.getExtension("X-TEST-a").size());
    assertEquals("test1-1", matchingRule.getExtension("X-TEST-a").get(0));
    assertEquals("test1-2", matchingRule.getExtension("X-TEST-a").get(1));
    assertNotNull(matchingRule.getExtension("X-TEST-b"));
    assertEquals(2, matchingRule.getExtension("X-TEST-b").size());
    assertEquals("test2-1", matchingRule.getExtension("X-TEST-b").get(0));
    assertEquals("test2-2", matchingRule.getExtension("X-TEST-b").get(1));
}
Also used : MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) Test(org.junit.Test)

Aggregations

MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)36 Test (org.junit.Test)21 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)11 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)11 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)9 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)7 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)7 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)6 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)5 Normalizer (org.apache.directory.api.ldap.model.schema.Normalizer)5 ParseException (java.text.ParseException)4 LdapProtocolErrorException (org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException)4 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)4 NoOpNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer)4 LdapComparator (org.apache.directory.api.ldap.model.schema.LdapComparator)3 ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)3 SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)3 Entry (org.apache.directory.api.ldap.model.entry.Entry)2 Value (org.apache.directory.api.ldap.model.entry.Value)2 DitContentRule (org.apache.directory.api.ldap.model.schema.DitContentRule)2