Search in sources :

Example 1 with DitStructureRule

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

the class DefaultSchemaLoader method loadDitStructureRules.

private void loadDitStructureRules(Attribute ditStructureRules) throws LdapException {
    if (ditStructureRules == null) {
        return;
    }
    for (Value value : ditStructureRules) {
        String desc = value.getValue();
        try {
            DitStructureRule ditStructureRule = DSR_DESCR_SCHEMA_PARSER.parseDITStructureRuleDescription(desc);
            updateSchemas(ditStructureRule);
        } catch (ParseException pe) {
            throw new LdapException(pe);
        }
    }
}
Also used : DitStructureRule(org.apache.directory.api.ldap.model.schema.DitStructureRule) Value(org.apache.directory.api.ldap.model.entry.Value) ParseException(java.text.ParseException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 2 with DitStructureRule

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

the class Registries method unregister.

/**
 * Unregister a SchemaObject from the registries
 *
 * @param schemaObject The SchemaObject we want to deregister
 * @throws LdapException If the removal failed
 */
private SchemaObject unregister(List<Throwable> errors, SchemaObject schemaObject) throws LdapException {
    LOG.debug("Unregistering {}:{}", schemaObject.getObjectType(), schemaObject.getOid());
    // Check that the SchemaObject is present in the registries
    if (!(schemaObject instanceof LoadableSchemaObject) && !globalOidRegistry.contains(schemaObject.getOid())) {
        String msg = I18n.err(I18n.ERR_13751_UNREGISTERING_FAILED_NOT_PRESENT, schemaObject.getObjectType(), schemaObject.getOid());
        LOG.error(msg);
        throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
    }
    SchemaObject unregistered;
    // First call the specific registry's register method
    switch(schemaObject.getObjectType()) {
        case ATTRIBUTE_TYPE:
            unregistered = attributeTypeRegistry.unregister((AttributeType) schemaObject);
            break;
        case COMPARATOR:
            unregistered = comparatorRegistry.unregister((LdapComparator<?>) schemaObject);
            break;
        case DIT_CONTENT_RULE:
            unregistered = ditContentRuleRegistry.unregister((DitContentRule) schemaObject);
            break;
        case DIT_STRUCTURE_RULE:
            unregistered = ditStructureRuleRegistry.unregister((DitStructureRule) schemaObject);
            break;
        case LDAP_SYNTAX:
            unregistered = ldapSyntaxRegistry.unregister((LdapSyntax) schemaObject);
            break;
        case MATCHING_RULE:
            unregistered = matchingRuleRegistry.unregister((MatchingRule) schemaObject);
            break;
        case MATCHING_RULE_USE:
            unregistered = matchingRuleUseRegistry.unregister((MatchingRuleUse) schemaObject);
            break;
        case NAME_FORM:
            unregistered = nameFormRegistry.unregister((NameForm) schemaObject);
            break;
        case NORMALIZER:
            unregistered = normalizerRegistry.unregister((Normalizer) schemaObject);
            break;
        case OBJECT_CLASS:
            unregistered = objectClassRegistry.unregister((ObjectClass) schemaObject);
            break;
        case SYNTAX_CHECKER:
            unregistered = syntaxCheckerRegistry.unregister((SyntaxChecker) schemaObject);
            break;
        default:
            throw new IllegalArgumentException(I18n.err(I18n.ERR_13718_UNEXPECTED_SCHEMA_OBJECT_TYPE, schemaObject.getObjectType()));
    }
    return unregistered;
}
Also used : LdapComparator(org.apache.directory.api.ldap.model.schema.LdapComparator) SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) SyntaxChecker(org.apache.directory.api.ldap.model.schema.SyntaxChecker) ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) MatchingRuleUse(org.apache.directory.api.ldap.model.schema.MatchingRuleUse) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) NameForm(org.apache.directory.api.ldap.model.schema.NameForm) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) DitStructureRule(org.apache.directory.api.ldap.model.schema.DitStructureRule) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) DitContentRule(org.apache.directory.api.ldap.model.schema.DitContentRule) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) MutableMatchingRule(org.apache.directory.api.ldap.model.schema.MutableMatchingRule)

Example 3 with DitStructureRule

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

the class DefaultDitStructureRuleRegistry method lookup.

/**
 * {@inheritDoc}
 */
@Override
public DitStructureRule lookup(int ruleId) throws LdapException {
    DitStructureRule ditStructureRule = byRuleId.get(ruleId);
    if (ditStructureRule == null) {
        String msg = I18n.err(I18n.ERR_13731_DIT_STRUCTURE_RULE_DOES_NOT_EXIST, ruleId);
        LOG.debug(msg);
        throw new LdapException(msg);
    }
    if (DEBUG) {
        LOG.debug("Found {} with ruleId: {}", ditStructureRule, ruleId);
    }
    return ditStructureRule;
}
Also used : DitStructureRule(org.apache.directory.api.ldap.model.schema.DitStructureRule) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 4 with DitStructureRule

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

the class DefaultDitStructureRuleRegistry method getSchemaName.

/**
 * {@inheritDoc}
 */
@Override
public String getSchemaName(int ruleId) throws LdapException {
    DitStructureRule ditStructureRule = byRuleId.get(ruleId);
    if (ditStructureRule != null) {
        return ditStructureRule.getSchemaName();
    }
    String msg = I18n.err(I18n.ERR_13729_RULE_ID_NOT_FOUND, ruleId);
    LOG.warn(msg);
    throw new LdapException(msg);
}
Also used : DitStructureRule(org.apache.directory.api.ldap.model.schema.DitStructureRule) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 5 with DitStructureRule

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

the class DitStructureRuleDescriptionSchemaParserTest method testSup.

/**
 * Tests SUP
 *
 * @throws ParseException
 */
@Test
public void testSup() throws ParseException {
    String value = null;
    DitStructureRule ditStructureRule = null;
    // no SUP
    value = "( 1 FORM 1.1 )";
    ditStructureRule = parser.parseDITStructureRuleDescription(value);
    assertEquals(0, ditStructureRule.getSuperRules().size());
    // SUP simple number
    value = "( 1 FORM 1.1 SUP 1 )";
    ditStructureRule = parser.parseDITStructureRuleDescription(value);
    assertEquals(1, ditStructureRule.getSuperRules().size());
    assertEquals(Integer.valueOf(1), ditStructureRule.getSuperRules().get(0));
    // SUP single number
    value = "( 1 FORM 1.1 SUP ( 1 ) )";
    ditStructureRule = parser.parseDITStructureRuleDescription(value);
    assertEquals(1, ditStructureRule.getSuperRules().size());
    assertEquals(Integer.valueOf(1), ditStructureRule.getSuperRules().get(0));
    // SUP multi number
    value = "( 1 FORM 1.1 SUP(12345 67890))";
    ditStructureRule = parser.parseDITStructureRuleDescription(value);
    assertEquals(2, ditStructureRule.getSuperRules().size());
    assertEquals(Integer.valueOf(12345), ditStructureRule.getSuperRules().get(0));
    assertEquals(Integer.valueOf(67890), ditStructureRule.getSuperRules().get(1));
    // non-numeric not allowed
    value = "( 1 FORM 1.1 SUP test )";
    try {
        parser.parseDITStructureRuleDescription(value);
        fail("Exception expected, invalid SUP test (non-numeric)");
    } catch (ParseException pe) {
    // expected
    }
    // oid not allowed
    value = "( 1 FORM 1.1 SUP 1.2.3.4 )";
    try {
        parser.parseDITStructureRuleDescription(value);
        fail("Exception expected, invalid SUP 1.2.3.4 (oid)");
    } catch (ParseException pe) {
    // expected
    }
}
Also used : DitStructureRule(org.apache.directory.api.ldap.model.schema.DitStructureRule) ParseException(java.text.ParseException) Test(org.junit.Test)

Aggregations

DitStructureRule (org.apache.directory.api.ldap.model.schema.DitStructureRule)12 ParseException (java.text.ParseException)5 Test (org.junit.Test)5 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)4 SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)4 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)2 DitContentRule (org.apache.directory.api.ldap.model.schema.DitContentRule)2 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)2 LoadableSchemaObject (org.apache.directory.api.ldap.model.schema.LoadableSchemaObject)2 MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)2 MatchingRuleUse (org.apache.directory.api.ldap.model.schema.MatchingRuleUse)2 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)2 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)2 NameForm (org.apache.directory.api.ldap.model.schema.NameForm)2 ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)2 SchemaObjectWrapper (org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1