use of org.apache.directory.api.ldap.model.schema.MatchingRule in project directory-ldap-api by apache.
the class Ava method compareTo.
/**
* @see Comparable#compareTo(Object)
*/
@Override
public int compareTo(Ava that) {
if (that == null) {
return 1;
}
int comp;
if (schemaManager == null) {
// Compare the ATs
comp = normType.compareTo(that.normType);
if (comp != 0) {
return comp;
}
// and compare the values
if (value == null) {
if (that.value == null) {
return 0;
} else {
return -1;
}
} else {
if (that.value == null) {
return 1;
} else {
comp = value.compareTo((Value) that.value);
return comp;
}
}
} else {
if (that.schemaManager == null) {
// Problem : we will apply the current Ava SchemaManager to the given Ava
try {
that.apply(schemaManager);
} catch (LdapInvalidDnException lide) {
return 1;
}
}
// First compare the AT OID
comp = attributeType.getOid().compareTo(that.attributeType.getOid());
if (comp != 0) {
return comp;
}
// Now, compare the two values using the ordering matchingRule comparator, if any
MatchingRule orderingMR = attributeType.getOrdering();
if (orderingMR != null) {
LdapComparator<Object> comparator = (LdapComparator<Object>) orderingMR.getLdapComparator();
if (comparator != null) {
comp = value.compareTo(that.value);
return comp;
} else {
comp = compareValues(that);
return comp;
}
} else {
comp = compareValues(that);
return comp;
}
}
}
use of org.apache.directory.api.ldap.model.schema.MatchingRule in project directory-ldap-api by apache.
the class MatchingRuleDescriptionSchemaParserTest method testSun1.
@Test
public void testSun1() throws ParseException, NamingException {
String value = "( 2.5.13.5 NAME 'caseExactMatch' DESC 'Case Exact Matching on Directory String [defined in X.520]' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )";
MatchingRule matchingRule = parser.parseMatchingRuleDescription(value);
assertEquals("2.5.13.5", matchingRule.getOid());
assertEquals(1, matchingRule.getNames().size());
assertEquals("caseExactMatch", matchingRule.getNames().get(0));
assertEquals("Case Exact Matching on Directory String [defined in X.520]", matchingRule.getDescription());
assertFalse(matchingRule.isObsolete());
assertEquals("1.3.6.1.4.1.1466.115.121.1.15", matchingRule.getSyntaxOid());
assertEquals(0, matchingRule.getExtensions().size());
}
use of org.apache.directory.api.ldap.model.schema.MatchingRule in project directory-ldap-api by apache.
the class MatchingRuleDescriptionSchemaParserTest method testSyntax.
@Test
public void testSyntax() throws ParseException, NamingException {
String value = null;
MatchingRule matchingRule = null;
// simple
value = "( 1.1 SYNTAX 0.1.2.3.4.5.6.7.8.9 )";
matchingRule = parser.parseMatchingRuleDescription(value);
assertEquals("0.1.2.3.4.5.6.7.8.9", matchingRule.getSyntaxOid());
// simple
value = "(1.1 SYNTAX 123.456.789.0)";
matchingRule = parser.parseMatchingRuleDescription(value);
assertEquals("123.456.789.0", matchingRule.getSyntaxOid());
// simple with spaces
value = "( 1.1 SYNTAX 0.1.2.3.4.5.6.7.8.9 )";
matchingRule = parser.parseMatchingRuleDescription(value);
assertEquals("0.1.2.3.4.5.6.7.8.9", matchingRule.getSyntaxOid());
// quoted value in parentheses
value = "( 1.1 SYNTAX ('0.1.2.3.4.5.6.7.8.9') )";
matchingRule = parser.parseMatchingRuleDescription(value);
assertEquals("0.1.2.3.4.5.6.7.8.9", matchingRule.getSyntaxOid());
// SYNTAX must only appear once
value = "( 1.1 SYNTAX 2.2 SYNTAX 3.3 )";
try {
matchingRule = parser.parseMatchingRuleDescription(value);
fail("Exception expected, SYNTAX appears twice");
} catch (ParseException pe) {
assertTrue(true);
}
if (!parser.isQuirksMode()) {
// non-numeric not allowed
value = "( test )";
try {
parser.parse(value);
fail("Exception expected, SYNTAX is require");
} catch (ParseException pe) {
// expected
}
// SYNTAX is required
value = "( 1.1 )";
try {
matchingRule = parser.parseMatchingRuleDescription(value);
fail("Exception expected, SYNTAX is required");
} catch (ParseException pe) {
// expected
}
}
}
use of org.apache.directory.api.ldap.model.schema.MatchingRule in project directory-ldap-api by apache.
the class MatchingRuleDescriptionSchemaParserTest method testRfc1.
// //////////////////////////////////////////////////////////////
// Some real-world matching rule descriptons //
// //////////////////////////////////////////////////////////////
@Test
public void testRfc1() throws ParseException, NamingException {
String value = "( 2.5.13.5 NAME 'caseExactMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )";
MatchingRule matchingRule = parser.parseMatchingRuleDescription(value);
assertEquals("2.5.13.5", matchingRule.getOid());
assertEquals(1, matchingRule.getNames().size());
assertEquals("caseExactMatch", matchingRule.getNames().get(0));
assertNull(matchingRule.getDescription());
assertFalse(matchingRule.isObsolete());
assertEquals("1.3.6.1.4.1.1466.115.121.1.15", matchingRule.getSyntaxOid());
assertEquals(0, matchingRule.getExtensions().size());
}
use of org.apache.directory.api.ldap.model.schema.MatchingRule 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;
}
Aggregations