use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.
the class StringValueAttributeTypeTest method testInstanceOf.
/**
* Test the instanceOf method
*/
@Test
public void testInstanceOf() throws LdapException {
AttributeType attribute = EntryUtils.getIA5StringAttributeType();
Value ssv = Value.createValue(attribute);
assertTrue(ssv.isInstanceOf(attribute));
attribute = EntryUtils.getBytesAttributeType();
assertFalse(ssv.isInstanceOf(attribute));
}
use of org.apache.directory.api.ldap.model.schema.AttributeType 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.AttributeType in project directory-ldap-api by apache.
the class ObjectClassHelper method addToRegistries.
/**
* Inject the ObjectClass into the registries, updating the references to
* other SchemaObject
*
* @param objectClass The ObjectClass to add to the Registries
* @param errors The errors we got while adding the ObjectClass to the Registries
* @param registries The Registries
* @throws LdapException on failure
*/
public static void addToRegistries(ObjectClass objectClass, List<Throwable> errors, Registries registries) throws LdapException {
if (registries != null) {
try {
objectClass.unlock();
// The superiors
buildSuperiors(objectClass, errors, registries);
// The MAY AttributeTypes
buildMay(objectClass, errors, registries);
// The MUST AttributeTypes
buildMust(objectClass, errors, registries);
/**
* Add the OC references (using and usedBy) :
* OC -> AT (MAY and MUST)
* OC -> OC (SUPERIORS)
*/
for (AttributeType mayAttributeType : objectClass.getMayAttributeTypes()) {
registries.addReference(objectClass, mayAttributeType);
}
for (AttributeType mustAttributeType : objectClass.getMustAttributeTypes()) {
registries.addReference(objectClass, mustAttributeType);
}
for (ObjectClass superiorObjectClass : objectClass.getSuperiors()) {
registries.addReference(objectClass, superiorObjectClass);
}
} finally {
objectClass.lock();
}
}
}
use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.
the class ObjectClassHelper method removeFromRegistries.
/**
* Remove the ObjectClass from the registries, updating the references to
* other SchemaObject.
*
* If one of the referenced SchemaObject does not exist (SUPERIORS, MAY, MUST),
* an exception is thrown.
*
* @param objectClass The ObjectClass to remove fro the registries
* @param errors The errors we got while removing the ObjectClass from the registries
* @param registries The Registries
* @throws LdapException If the ObjectClass is not valid
*/
public static void removeFromRegistries(ObjectClass objectClass, List<Throwable> errors, Registries registries) throws LdapException {
if (registries != null) {
ObjectClassRegistry objectClassRegistry = registries.getObjectClassRegistry();
// Unregister this ObjectClass into the Descendant map
objectClassRegistry.unregisterDescendants(objectClass, objectClass.getSuperiors());
/**
* Remove the OC references (using and usedBy) :
* OC -> AT (for MAY and MUST)
* OC -> OC
*/
if (objectClass.getMayAttributeTypes() != null) {
for (AttributeType may : objectClass.getMayAttributeTypes()) {
registries.delReference(objectClass, may);
}
}
if (objectClass.getMustAttributeTypes() != null) {
for (AttributeType must : objectClass.getMustAttributeTypes()) {
registries.delReference(objectClass, must);
}
}
if (objectClass.getSuperiors() != null) {
for (ObjectClass superior : objectClass.getSuperiors()) {
registries.delReference(objectClass, superior);
}
}
}
}
use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.
the class Registries method resolve.
private void resolve(ObjectClass objectClass, List<Throwable> errors) {
// This set is used to avoid having more than one error
// for an ObjectClass. It's mandatory when processing
// the Superiors, as they may be broken and referenced more than once.
Set<String> processed = new HashSet<>();
// Store the ObjectClass itself in the processed, to avoid cycle
processed.add(objectClass.getOid());
// Call the recursive method, as we may have superiors to deal with
resolveRecursive(objectClass, processed, errors);
// Check that the MAY and MUST AT are consistent (no AT in MAY and in MUST
// in one of its superior
List<AttributeType> musts = getMustRecursive(new ArrayList<AttributeType>(), new HashSet<ObjectClass>(), objectClass);
if (musts != null) {
for (AttributeType may : objectClass.getMayAttributeTypes()) {
if (musts.contains(may)) {
// This is not allowed.
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_DUPLICATE_AT_IN_MAY_AND_MUST);
ldapSchemaException.setSourceObject(objectClass);
ldapSchemaException.setOtherObject(may);
errors.add(ldapSchemaException);
}
}
}
}
Aggregations