use of org.apache.directory.api.ldap.model.schema.MatchingRuleUse in project directory-ldap-api by apache.
the class Registries method clone.
/**
* Clone the Registries. This is done in two steps :
* - first clone the SchemaObjetc registries
* - second restore the relation between them
*/
// False positive
@Override
public Registries clone() throws CloneNotSupportedException {
// First clone the structure
Registries clone = (Registries) super.clone();
// Now, clone the oidRegistry
clone.globalOidRegistry = globalOidRegistry.copy();
// We have to clone every SchemaObject registries now
clone.attributeTypeRegistry = attributeTypeRegistry.copy();
clone.comparatorRegistry = comparatorRegistry.copy();
clone.ditContentRuleRegistry = ditContentRuleRegistry.copy();
clone.ditStructureRuleRegistry = ditStructureRuleRegistry.copy();
clone.ldapSyntaxRegistry = ldapSyntaxRegistry.copy();
clone.matchingRuleRegistry = matchingRuleRegistry.copy();
clone.matchingRuleUseRegistry = matchingRuleUseRegistry.copy();
clone.nameFormRegistry = nameFormRegistry.copy();
clone.normalizerRegistry = normalizerRegistry.copy();
clone.objectClassRegistry = objectClassRegistry.copy();
clone.syntaxCheckerRegistry = syntaxCheckerRegistry.copy();
// Store all the SchemaObjects into the globalOid registry
for (AttributeType attributeType : clone.attributeTypeRegistry) {
clone.globalOidRegistry.put(attributeType);
}
for (DitContentRule ditContentRule : clone.ditContentRuleRegistry) {
clone.globalOidRegistry.put(ditContentRule);
}
for (DitStructureRule ditStructureRule : clone.ditStructureRuleRegistry) {
clone.globalOidRegistry.put(ditStructureRule);
}
for (MatchingRule matchingRule : clone.matchingRuleRegistry) {
clone.globalOidRegistry.put(matchingRule);
}
for (MatchingRuleUse matchingRuleUse : clone.matchingRuleUseRegistry) {
clone.globalOidRegistry.put(matchingRuleUse);
}
for (NameForm nameForm : clone.nameFormRegistry) {
clone.globalOidRegistry.put(nameForm);
}
for (ObjectClass objectClass : clone.objectClassRegistry) {
clone.globalOidRegistry.put(objectClass);
}
for (LdapSyntax syntax : clone.ldapSyntaxRegistry) {
clone.globalOidRegistry.put(syntax);
}
// Clone the schema list
clone.loadedSchemas = new HashMap<>();
for (Map.Entry<String, Set<SchemaObjectWrapper>> entry : schemaObjects.entrySet()) {
// We don't clone the schemas
clone.loadedSchemas.put(entry.getKey(), loadedSchemas.get(entry.getKey()));
}
// Clone the Using and usedBy structures
// They will be empty
clone.using = new HashMap<>();
clone.usedBy = new HashMap<>();
// Last, rebuild the using and usedBy references
clone.buildReferences();
// Now, check the registries. We don't care about errors
clone.checkRefInteg();
clone.schemaObjects = new HashMap<>();
// SchemaObjects
for (Map.Entry<String, Set<SchemaObjectWrapper>> entry : schemaObjects.entrySet()) {
Set<SchemaObjectWrapper> objects = new HashSet<>();
for (SchemaObjectWrapper schemaObjectWrapper : entry.getValue()) {
SchemaObject original = schemaObjectWrapper.get();
try {
if (!(original instanceof LoadableSchemaObject)) {
SchemaObject copy = clone.globalOidRegistry.getSchemaObject(original.getOid());
SchemaObjectWrapper newWrapper = new SchemaObjectWrapper(copy);
objects.add(newWrapper);
} else {
SchemaObjectWrapper newWrapper = new SchemaObjectWrapper(original);
objects.add(newWrapper);
}
} catch (LdapException ne) {
// Nothing to do
}
}
clone.schemaObjects.put(entry.getKey(), objects);
}
return clone;
}
use of org.apache.directory.api.ldap.model.schema.MatchingRuleUse in project directory-ldap-api by apache.
the class MatchingRuleUseDescriptionSchemaParserTest method testFull.
@Test
public void testFull() throws ParseException {
String value = null;
MatchingRuleUse matchingRuleUse = 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 APPLIES ( 0.1.2.3.4.5.6.7.8.9 $ abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789 ) X-TEST-a ('test1-1' 'test1-2') X-TEST-b ('test2-1' 'test2-2') )";
matchingRuleUse = parser.parseMatchingRuleUseDescription(value);
assertEquals("1.2.3.4.5.6.7.8.9.0", matchingRuleUse.getOid());
assertEquals(2, matchingRuleUse.getNames().size());
assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", matchingRuleUse.getNames().get(0));
assertEquals("test", matchingRuleUse.getNames().get(1));
assertEquals("Descripton \u00E4\u00F6\u00FC\u00DF \u90E8\u9577", matchingRuleUse.getDescription());
assertTrue(matchingRuleUse.isObsolete());
assertEquals(2, matchingRuleUse.getApplicableAttributeOids().size());
assertEquals("0.1.2.3.4.5.6.7.8.9", matchingRuleUse.getApplicableAttributeOids().get(0));
assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", matchingRuleUse.getApplicableAttributeOids().get(1));
assertEquals(2, matchingRuleUse.getExtensions().size());
assertNotNull(matchingRuleUse.getExtension("X-TEST-a"));
assertEquals(2, matchingRuleUse.getExtension("X-TEST-a").size());
assertEquals("test1-1", matchingRuleUse.getExtension("X-TEST-a").get(0));
assertEquals("test1-2", matchingRuleUse.getExtension("X-TEST-a").get(1));
assertNotNull(matchingRuleUse.getExtension("X-TEST-b"));
assertEquals(2, matchingRuleUse.getExtension("X-TEST-b").size());
assertEquals("test2-1", matchingRuleUse.getExtension("X-TEST-b").get(0));
assertEquals("test2-2", matchingRuleUse.getExtension("X-TEST-b").get(1));
}
use of org.apache.directory.api.ldap.model.schema.MatchingRuleUse in project directory-ldap-api by apache.
the class MatchingRuleUseDescriptionSchemaParserTest method testRequiredElements.
/**
* Test required elements.
*
* @throws ParseException
*/
@Test
public void testRequiredElements() throws ParseException {
String value = null;
MatchingRuleUse matchingRuleUse = null;
value = "( 1.2.3.4.5.6.7.8.9.0 APPLIES a )";
matchingRuleUse = parser.parseMatchingRuleUseDescription(value);
assertEquals(1, matchingRuleUse.getApplicableAttributeOids().size());
if (!parser.isQuirksMode()) {
value = "( 1.2.3.4.5.6.7.8.9.0 )";
try {
parser.parseMatchingRuleUseDescription(value);
fail("Exception expected, APPLIES is required");
} catch (ParseException pe) {
// expected
}
}
}
Aggregations