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);
}
}
}
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;
}
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;
}
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);
}
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
}
}
Aggregations