use of org.apache.directory.api.ldap.model.schema.registries.AttributeTypeRegistry in project directory-ldap-api by apache.
the class ObjectClassHelper method buildMay.
/**
* Build and check the MAY AT for this ObjectClass
*/
private static void buildMay(ObjectClass objectClass, List<Throwable> errors, Registries registries) {
AttributeTypeRegistry atRegistry = registries.getAttributeTypeRegistry();
List<String> mayAttributeTypeOids = objectClass.getMayAttributeTypeOids();
if (mayAttributeTypeOids != null) {
objectClass.getMayAttributeTypes().clear();
for (String mayAttributeTypeName : mayAttributeTypeOids) {
try {
AttributeType attributeType = atRegistry.lookup(mayAttributeTypeName);
if (attributeType.isCollective()) {
// Collective Attributes are not allowed in MAY or MUST
String msg = I18n.err(I18n.ERR_13779_COLLECTIVE_NOT_ALLOWED_IN_MAY, mayAttributeTypeName, objectClass.getOid());
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_COLLECTIVE_NOT_ALLOWED_IN_MAY, msg);
ldapSchemaException.setSourceObject(objectClass);
ldapSchemaException.setRelatedId(mayAttributeTypeName);
errors.add(ldapSchemaException);
LOG.info(msg);
continue;
}
if (objectClass.getMayAttributeTypes().contains(attributeType)) {
// Already registered : this is an error
String msg = I18n.err(I18n.ERR_13770_CANNOT_REGISTER_DUPLICATE_AT_IN_MAY, objectClass.getOid(), mayAttributeTypeName);
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_DUPLICATE_AT_IN_MAY, msg);
ldapSchemaException.setSourceObject(objectClass);
ldapSchemaException.setRelatedId(mayAttributeTypeName);
errors.add(ldapSchemaException);
LOG.info(msg);
continue;
}
objectClass.getMayAttributeTypes().add(attributeType);
} catch (LdapException ne) {
// Cannot find the AT
String msg = I18n.err(I18n.ERR_13771_CANNOT_REGISTER_AT_IN_MAY_DOES_NOT_EXIST, objectClass.getOid(), mayAttributeTypeName);
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_NONEXISTENT_MAY_AT, msg, ne);
ldapSchemaException.setSourceObject(objectClass);
ldapSchemaException.setRelatedId(mayAttributeTypeName);
errors.add(ldapSchemaException);
LOG.info(msg);
continue;
}
}
}
}
use of org.apache.directory.api.ldap.model.schema.registries.AttributeTypeRegistry in project directory-ldap-api by apache.
the class AttributeTypeHelper method addToRegistries.
/**
* Inject the AttributeType into the Registries, updating the references to
* other SchemaObject
*
* If one of the referenced SchemaObject does not exist (SUP, EQUALITY, ORDERING, SUBSTR, SYNTAX),
* an exception is thrown.
*
* @param attributeType The AttributeType to add to the Registries
* @param errors The errors we got while adding the AttributeType to the Registries
* @param registries The Registries
* @throws LdapException If the AttributeType is not valid
*/
public static void addToRegistries(MutableAttributeType attributeType, List<Throwable> errors, Registries registries) throws LdapException {
if (registries != null) {
try {
attributeType.unlock();
AttributeTypeRegistry attributeTypeRegistry = registries.getAttributeTypeRegistry();
// The superior
if (!buildSuperior(attributeType, errors, registries)) {
// We have had errors, let's stop here as we need a correct superior to continue
return;
}
// The Syntax
buildSyntax(attributeType, errors, registries);
// The EQUALITY matching rule
buildEquality(attributeType, errors, registries);
// The ORDERING matching rule
buildOrdering(attributeType, errors, registries);
// The SUBSTR matching rule
buildSubstring(attributeType, errors, registries);
// Check the USAGE
checkUsage(attributeType, errors);
// Check the COLLECTIVE element
checkCollective(attributeType, errors);
// Inject the attributeType into the oid/normalizer map
attributeTypeRegistry.addMappingFor(attributeType);
// Register this AttributeType into the Descendant map
attributeTypeRegistry.registerDescendants(attributeType, attributeType.getSuperior());
/**
* Add the AT references (using and usedBy) :
* AT -> MR (for EQUALITY, ORDERING and SUBSTR)
* AT -> S
* AT -> AT
*/
if (attributeType.getEquality() != null) {
registries.addReference(attributeType, attributeType.getEquality());
}
if (attributeType.getOrdering() != null) {
registries.addReference(attributeType, attributeType.getOrdering());
}
if (attributeType.getSubstring() != null) {
registries.addReference(attributeType, attributeType.getSubstring());
}
if (attributeType.getSyntax() != null) {
registries.addReference(attributeType, attributeType.getSyntax());
}
if (attributeType.getSuperior() != null) {
registries.addReference(attributeType, attributeType.getSuperior());
}
} finally {
attributeType.lock();
}
}
}
use of org.apache.directory.api.ldap.model.schema.registries.AttributeTypeRegistry in project directory-ldap-api by apache.
the class AttributeTypeHelper method buildSuperior.
/**
* Build the Superior AttributeType reference for an AttributeType
*/
private static boolean buildSuperior(MutableAttributeType attributeType, List<Throwable> errors, Registries registries) {
MutableAttributeType currentSuperior;
AttributeTypeRegistry attributeTypeRegistry = registries.getAttributeTypeRegistry();
String superiorOid = attributeType.getSuperiorOid();
if (superiorOid != null) {
// This AT has a superior
try {
currentSuperior = (MutableAttributeType) attributeTypeRegistry.lookup(superiorOid);
} catch (Exception e) {
// Not allowed.
String msg = I18n.err(I18n.ERR_13752_CANNOT_FIND_SUPERIOR, superiorOid, attributeType.getName());
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_SUPERIOR, msg, e);
ldapSchemaException.setSourceObject(attributeType);
ldapSchemaException.setRelatedId(superiorOid);
errors.add(ldapSchemaException);
LOG.info(msg);
// Get out now
return false;
}
if (currentSuperior != null) {
// a special case : if the superior is collective, this is an error
if (currentSuperior.isCollective()) {
String msg = I18n.err(I18n.ERR_13776_CANNOT_SUBTYPE_COLLECTIVE, currentSuperior, attributeType.getName());
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_CANNOT_SUBTYPE_COLLECTIVE_AT, msg);
ldapSchemaException.setSourceObject(attributeType);
errors.add(ldapSchemaException);
LOG.info(msg);
return false;
}
attributeType.setSuperior(currentSuperior);
// handled.
if (currentSuperior.getSuperior() == null) {
registries.buildReference(errors, currentSuperior);
}
// Update the descendant MAP
try {
attributeTypeRegistry.registerDescendants(attributeType, currentSuperior);
} catch (LdapException ne) {
errors.add(ne);
LOG.info(ne.getMessage());
return false;
}
// Check for cycles now
Set<String> superiors = new HashSet<>();
superiors.add(attributeType.getOid());
AttributeType tmp = currentSuperior;
boolean isOk = true;
while (tmp != null) {
if (superiors.contains(tmp.getOid())) {
// There is a cycle : bad bad bad !
// Not allowed.
String msg = I18n.err(I18n.ERR_13753_CYCLE_DETECTED, attributeType.getName());
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_CYCLE_TYPE_HIERARCHY, msg);
ldapSchemaException.setSourceObject(attributeType);
errors.add(ldapSchemaException);
LOG.info(msg);
isOk = false;
break;
} else {
superiors.add(tmp.getOid());
tmp = tmp.getSuperior();
}
}
superiors.clear();
return isOk;
} else {
// Not allowed.
String msg = I18n.err(I18n.ERR_13752_CANNOT_FIND_SUPERIOR, superiorOid, attributeType.getName());
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_SUPERIOR, msg);
ldapSchemaException.setSourceObject(attributeType);
ldapSchemaException.setRelatedId(superiorOid);
errors.add(ldapSchemaException);
LOG.info(msg);
// Get out now
return false;
}
} else {
// No superior, just return
return true;
}
}
use of org.apache.directory.api.ldap.model.schema.registries.AttributeTypeRegistry in project directory-ldap-api by apache.
the class MatchingRuleUseHelper method addToRegistries.
/**
* Inject the MatchingRuleUse into the registries, updating the references to
* other SchemaObject
*
* @param matchingRuleUse The MatchingRuleUse to add to the Registries
* @param errors The errors we got while adding the MatchingRuleUse to the Registries
* @param registries The Registries
* @throws LdapException If the addition failed
*/
public static void addToRegistries(MatchingRuleUse matchingRuleUse, List<Throwable> errors, Registries registries) throws LdapException {
if (registries != null) {
try {
matchingRuleUse.unlock();
AttributeTypeRegistry atRegistry = registries.getAttributeTypeRegistry();
matchingRuleUse.getApplicableAttributes().clear();
for (String oid : matchingRuleUse.getApplicableAttributeOids()) {
matchingRuleUse.getApplicableAttributes().add(atRegistry.lookup(oid));
}
} finally {
matchingRuleUse.lock();
}
}
}
use of org.apache.directory.api.ldap.model.schema.registries.AttributeTypeRegistry in project directory-ldap-api by apache.
the class AttributeTypeHelper method removeFromRegistries.
/**
* Remove the AttributeType from the registries, updating the references to
* other SchemaObject.
*
* If one of the referenced SchemaObject does not exist (SUP, EQUALITY, ORDERING, SUBSTR, SYNTAX),
* an exception is thrown.
*
* @param attributeType The AttributeType to remove from the Registries
* @param errors The errors we got while removing the AttributeType from the Registries
* @param registries The Registries
* @throws LdapException If the AttributeType is not valid
*/
public static void removeFromRegistries(AttributeType attributeType, List<Throwable> errors, Registries registries) throws LdapException {
if (registries != null) {
AttributeTypeRegistry attributeTypeRegistry = registries.getAttributeTypeRegistry();
// Remove the attributeType from the oid/normalizer map
attributeTypeRegistry.removeMappingFor(attributeType);
// Unregister this AttributeType into the Descendant map
attributeTypeRegistry.unregisterDescendants(attributeType, attributeType.getSuperior());
/**
* Remove the AT references (using and usedBy) :
* AT -> MR (for EQUALITY, ORDERING and SUBSTR)
* AT -> S
* AT -> AT
*/
if (attributeType.getEquality() != null) {
registries.delReference(attributeType, attributeType.getEquality());
}
if (attributeType.getOrdering() != null) {
registries.delReference(attributeType, attributeType.getOrdering());
}
if (attributeType.getSubstring() != null) {
registries.delReference(attributeType, attributeType.getSubstring());
}
if (attributeType.getSyntax() != null) {
registries.delReference(attributeType, attributeType.getSyntax());
}
if (attributeType.getSuperior() != null) {
registries.delReference(attributeType, attributeType.getSuperior());
}
}
}
Aggregations