use of org.apache.directory.api.ldap.model.schema.registries.AttributeTypeRegistry in project directory-ldap-api by apache.
the class DitContentRuleHelper method addToRegistries.
/**
* Inject the DitContentRule into the registries, updating the references to
* other SchemaObject
*
* @param ditContentRule The DitContentRule to add to the Registries
* @param errors The errors we got while adding the DitContentRule to the Registries
* @param registries The Registries
* @throws LdapException If the addition failed
*/
public static void addToRegistries(DitContentRule ditContentRule, List<Throwable> errors, Registries registries) throws LdapException {
if (registries != null) {
try {
ditContentRule.unlock();
AttributeTypeRegistry atRegistry = registries.getAttributeTypeRegistry();
ObjectClassRegistry ocRegistry = registries.getObjectClassRegistry();
if (ditContentRule.getMayAttributeTypeOids() != null) {
ditContentRule.getMayAttributeTypes().clear();
for (String oid : ditContentRule.getMayAttributeTypeOids()) {
ditContentRule.getMayAttributeTypes().add(atRegistry.lookup(oid));
}
}
if (ditContentRule.getMustAttributeTypeOids() != null) {
ditContentRule.getMustAttributeTypes().clear();
for (String oid : ditContentRule.getMustAttributeTypeOids()) {
ditContentRule.getMustAttributeTypes().add(atRegistry.lookup(oid));
}
}
if (ditContentRule.getNotAttributeTypeOids() != null) {
ditContentRule.getNotAttributeTypes().clear();
for (String oid : ditContentRule.getNotAttributeTypeOids()) {
ditContentRule.getNotAttributeTypes().add(atRegistry.lookup(oid));
}
}
if (ditContentRule.getAuxObjectClassOids() != null) {
ditContentRule.getAuxObjectClasses().clear();
for (String oid : ditContentRule.getAuxObjectClassOids()) {
ditContentRule.getAuxObjectClasses().add(ocRegistry.lookup(oid));
}
}
} finally {
ditContentRule.lock();
}
}
}
use of org.apache.directory.api.ldap.model.schema.registries.AttributeTypeRegistry in project directory-ldap-api by apache.
the class NameFormHelper method addToRegistries.
/**
* Inject the NameForm into the registries, updating the references to
* other SchemaObject
*
* @param nameForm The NameForm to add to the Registries
* @param errors The errors we got while adding the NameForm to the Registries
* @param registries The Registries
* @throws LdapException If the addition failed
*/
public static void addToRegistries(NameForm nameForm, List<Throwable> errors, Registries registries) throws LdapException {
if (registries != null) {
try {
nameForm.unlock();
AttributeTypeRegistry atRegistry = registries.getAttributeTypeRegistry();
ObjectClass structuralObjectClass = registries.getObjectClassRegistry().lookup(nameForm.getStructuralObjectClassOid());
nameForm.setStructuralObjectClass(structuralObjectClass);
nameForm.getMayAttributeTypes().clear();
for (String oid : nameForm.getMayAttributeTypeOids()) {
nameForm.getMayAttributeTypes().add(atRegistry.lookup(oid));
}
nameForm.getMustAttributeTypes().clear();
for (String oid : nameForm.getMustAttributeTypeOids()) {
nameForm.getMustAttributeTypes().add(atRegistry.lookup(oid));
}
} finally {
nameForm.lock();
}
}
}
use of org.apache.directory.api.ldap.model.schema.registries.AttributeTypeRegistry in project directory-ldap-api by apache.
the class ObjectClassHelper method buildMust.
/**
* Build and check the MUST AT for this ObjectClass.
*/
private static void buildMust(ObjectClass objectClass, List<Throwable> errors, Registries registries) {
AttributeTypeRegistry atRegistry = registries.getAttributeTypeRegistry();
List<String> mustAttributeTypeOids = objectClass.getMustAttributeTypeOids();
if (mustAttributeTypeOids != null) {
objectClass.getMustAttributeTypes().clear();
for (String mustAttributeTypeName : mustAttributeTypeOids) {
try {
AttributeType attributeType = atRegistry.lookup(mustAttributeTypeName);
if (attributeType.isCollective()) {
// Collective Attributes are not allowed in MAY or MUST
String msg = I18n.err(I18n.ERR_13778_COLLECTIVE_NOT_ALLOWED_IN_MUST, mustAttributeTypeName, objectClass.getOid());
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_COLLECTIVE_NOT_ALLOWED_IN_MUST, msg);
ldapSchemaException.setSourceObject(objectClass);
ldapSchemaException.setRelatedId(mustAttributeTypeName);
errors.add(ldapSchemaException);
LOG.info(msg);
continue;
}
if (objectClass.getMustAttributeTypes().contains(attributeType)) {
// Already registered : this is an error
String msg = I18n.err(I18n.ERR_13772_CANNOT_REGISTER_DUPLICATE_AT_IN_MUST, objectClass.getOid(), mustAttributeTypeName);
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_DUPLICATE_AT_IN_MUST, msg);
ldapSchemaException.setSourceObject(objectClass);
ldapSchemaException.setRelatedId(mustAttributeTypeName);
errors.add(ldapSchemaException);
LOG.info(msg);
continue;
}
// Check that the MUST AT is not also present in the MAY AT
if (objectClass.getMayAttributeTypes().contains(attributeType)) {
// Already registered : this is an error
String msg = I18n.err(I18n.ERR_13773_CANNOT_REGISTER_DUPLICATE_AT_IN_MAY_AND_MUST, objectClass.getOid(), mustAttributeTypeName);
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_DUPLICATE_AT_IN_MAY_AND_MUST, msg);
ldapSchemaException.setSourceObject(objectClass);
ldapSchemaException.setRelatedId(mustAttributeTypeName);
errors.add(ldapSchemaException);
LOG.info(msg);
continue;
}
objectClass.getMustAttributeTypes().add(attributeType);
} catch (LdapException ne) {
// Cannot find the AT
String msg = I18n.err(I18n.ERR_13774_CANNOT_REGISTER_AT_IN_MUST_DOES_NOT_EXIST, objectClass.getOid(), mustAttributeTypeName);
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_NONEXISTENT_MUST_AT, msg, ne);
ldapSchemaException.setSourceObject(objectClass);
ldapSchemaException.setRelatedId(mustAttributeTypeName);
errors.add(ldapSchemaException);
LOG.info(msg);
continue;
}
}
}
}
Aggregations