use of org.apache.directory.api.ldap.model.schema.NameForm in project directory-ldap-api by apache.
the class DefaultSchemaLoader method loadNameForms.
private void loadNameForms(Attribute nameForms) throws LdapException {
if (nameForms == null) {
return;
}
for (Value value : nameForms) {
String desc = value.getValue();
try {
NameForm nameForm = NF_DESCR_SCHEMA_PARSER.parseNameFormDescription(desc);
updateSchemas(nameForm);
} catch (ParseException pe) {
throw new LdapException(pe);
}
}
}
use of org.apache.directory.api.ldap.model.schema.NameForm in project directory-ldap-api by apache.
the class DefaultSchemaLoader method loadNameForms.
/**
* {@inheritDoc}
*/
@Override
public List<Entry> loadNameForms(Schema... schemas) throws LdapException, IOException {
List<Entry> nameFormEntries = new ArrayList<>();
if (schemas == null) {
return nameFormEntries;
}
AttributesFactory factory = new AttributesFactory();
for (Schema schema : schemas) {
Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
for (SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers) {
SchemaObject schemaObject = schemaObjectWrapper.get();
if (schemaObject instanceof NameForm) {
NameForm nameForm = (NameForm) schemaObject;
Entry nameFormEntry = factory.convert(nameForm, schema, null);
nameFormEntries.add(nameFormEntry);
}
}
}
return nameFormEntries;
}
use of org.apache.directory.api.ldap.model.schema.NameForm 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.NameForm in project directory-ldap-api by apache.
the class NameFormDescriptionSchemaParserTest method testMay.
/**
* Test MAY and its values.
*
* @throws ParseException
*/
@Test
public void testMay() throws ParseException, LdapException {
String value = null;
NameForm nf = null;
// no MAY
value = "( 1.1 OC o MUST m )";
nf = parser.parseNameFormDescription(value);
assertEquals(0, nf.getMayAttributeTypeOids().size());
// MAY simple numericoid
value = "( 1.1 OC o MUST m MAY 1.2.3 )";
nf = parser.parseNameFormDescription(value);
assertEquals(1, nf.getMayAttributeTypeOids().size());
assertEquals("1.2.3", nf.getMayAttributeTypeOids().get(0));
// MAY mulitple
value = "(1.1 OC o MUST m MAY (cn$sn $11.22.33.44.55 $ objectClass ))";
nf = parser.parseNameFormDescription(value);
assertEquals(4, nf.getMayAttributeTypeOids().size());
assertEquals("cn", nf.getMayAttributeTypeOids().get(0));
assertEquals("sn", nf.getMayAttributeTypeOids().get(1));
assertEquals("11.22.33.44.55", nf.getMayAttributeTypeOids().get(2));
assertEquals("objectClass", nf.getMayAttributeTypeOids().get(3));
// MAY must only appear once
value = "( 1.1 OC o MUST m MAY test1 MAY test2 )";
try {
nf = parser.parseNameFormDescription(value);
fail("Exception expected, MAY appears twice");
} catch (ParseException pe) {
// expected
}
if (!parser.isQuirksMode()) {
// invalid value
value = "( 1.1 OC o MUST m MAY ( c_n ) )";
try {
nf = parser.parseNameFormDescription(value);
fail("Exception expected, invalid value c_n");
} catch (ParseException pe) {
// expected
}
}
}
use of org.apache.directory.api.ldap.model.schema.NameForm in project directory-ldap-api by apache.
the class NameFormDescriptionSchemaParserTest method testOc.
/**
* Test OC and its value.
*
* @throws ParseException
*/
@Test
public void testOc() throws ParseException, LdapException {
String value = null;
NameForm nf = null;
// numeric oid
value = "( 1.1 MUST m OC 1.2.3.4.5.6.7.8.9.0 )";
nf = parser.parseNameFormDescription(value);
assertEquals("1.2.3.4.5.6.7.8.9.0", nf.getStructuralObjectClassOid());
// numeric oid
value = "( 1.1 MUST m OC 123.4567.890 )";
nf = parser.parseNameFormDescription(value);
assertEquals("123.4567.890", nf.getStructuralObjectClassOid());
// descr
value = "( 1.1 MUST m OC abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789 )";
nf = parser.parseNameFormDescription(value);
assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", nf.getStructuralObjectClassOid());
// quoted value
value = "( 1.1 MUST m OC '1.2.3.4.5.6.7.8.9.0' )";
nf = parser.parseNameFormDescription(value);
assertEquals("1.2.3.4.5.6.7.8.9.0", nf.getStructuralObjectClassOid());
// quoted value
value = "( 1.1 MUST m OC 'test' )";
nf = parser.parseNameFormDescription(value);
assertEquals("test", nf.getStructuralObjectClassOid());
// invalid character
value = "( 1.1 MUST m OC 1.2.3.4.A )";
try {
nf = parser.parseNameFormDescription(value);
fail("Exception expected, invalid OC 1.2.3.4.A (invalid character)");
} catch (ParseException pe) {
// expected
}
// no multi value allowed
value = "( 1.1 MUST m OC ( test1 test2 ) )";
try {
nf = parser.parseNameFormDescription(value);
fail("Exception expected, OC must be single valued");
} catch (ParseException pe) {
// expected
}
// OC must only appear once
value = "( 1.1 MUST m OC test1 OC test2 )";
try {
nf = parser.parseNameFormDescription(value);
fail("Exception expected, OC appears twice");
} catch (ParseException pe) {
// expected
}
if (!parser.isQuirksMode()) {
// OC is required
value = "( 1.1 MUST m )";
try {
nf = parser.parseNameFormDescription(value);
fail("Exception expected, OC is required");
} catch (ParseException pe) {
// expected
}
// invalid start
value = "( 1.1 MUST m OC -test ) )";
try {
nf = parser.parseNameFormDescription(value);
fail("Exception expected, invalid OC '-test' (starts with hypen)");
} catch (ParseException pe) {
// expected
}
}
}
Aggregations