use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.
the class DefaultSchemaLoader method loadObjectClasses.
private void loadObjectClasses(Attribute objectClasses) throws LdapException {
if (objectClasses == null) {
return;
}
for (Value value : objectClasses) {
String desc = value.getValue();
try {
ObjectClass objectClass = OC_DESCR_SCHEMA_PARSER.parseObjectClassDescription(desc);
updateSchemas(objectClass);
} catch (ParseException pe) {
throw new LdapException(pe);
}
}
}
use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.
the class DefaultSchemaLoader method loadObjectClasses.
/**
* {@inheritDoc}
*/
@Override
public List<Entry> loadObjectClasses(Schema... schemas) throws LdapException, IOException {
List<Entry> objectClassEntries = new ArrayList<>();
if (schemas == null) {
return objectClassEntries;
}
AttributesFactory factory = new AttributesFactory();
for (Schema schema : schemas) {
Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
for (SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers) {
SchemaObject schemaObject = schemaObjectWrapper.get();
if (schemaObject instanceof ObjectClass) {
ObjectClass objectClass = (ObjectClass) schemaObject;
Entry objectClassEntry = factory.convert(objectClass, schema, null);
objectClassEntries.add(objectClassEntry);
}
}
}
return objectClassEntries;
}
use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.
the class ObjectClassHelper method buildSuperiors.
/**
* Build the references to this ObjectClass SUPERIORS, checking that the type
* hierarchy is correct.
*/
private static void buildSuperiors(ObjectClass objectClass, List<Throwable> errors, Registries registries) {
ObjectClassRegistry ocRegistry = registries.getObjectClassRegistry();
List<String> superiorOids = objectClass.getSuperiorOids();
if (superiorOids != null) {
objectClass.getSuperiors().clear();
for (String superiorName : superiorOids) {
try {
ObjectClass superior = ocRegistry.lookup(ocRegistry.getOidByName(superiorName));
// Before adding the superior, check that the ObjectClass type is consistent
switch(objectClass.getType()) {
case ABSTRACT:
if (superior.getType() != ObjectClassTypeEnum.ABSTRACT) {
// An ABSTRACT OC can only inherit from ABSTRACT OCs
String msg = I18n.err(I18n.ERR_13766_ABSTRACT_OC_CANNOT_INHERIT_FROM_OC, objectClass.getOid(), superior.getObjectType(), superior);
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_ABSTRACT_MUST_INHERIT_FROM_ABSTRACT_OC, msg);
ldapSchemaException.setSourceObject(objectClass);
errors.add(ldapSchemaException);
LOG.info(msg);
continue;
}
break;
case AUXILIARY:
if (superior.getType() == ObjectClassTypeEnum.STRUCTURAL) {
// An AUXILIARY OC cannot inherit from STRUCTURAL OCs
String msg = I18n.err(I18n.ERR_13767_AUX_OC_CANNOT_INHERIT_FROM_STRUCT_OC, objectClass.getOid(), superior);
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_AUXILIARY_CANNOT_INHERIT_FROM_STRUCTURAL_OC, msg);
ldapSchemaException.setSourceObject(objectClass);
errors.add(ldapSchemaException);
LOG.info(msg);
continue;
}
break;
case STRUCTURAL:
if (superior.getType() == ObjectClassTypeEnum.AUXILIARY) {
// A STRUCTURAL OC cannot inherit from AUXILIARY OCs
String msg = I18n.err(I18n.ERR_13768_STRUCT_OC_CANNOT_INHERIT_FROM_AUX_OC, objectClass.getOid(), superior);
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_STRUCTURAL_CANNOT_INHERIT_FROM_AUXILIARY_OC, msg);
ldapSchemaException.setSourceObject(objectClass);
errors.add(ldapSchemaException);
LOG.info(msg);
continue;
}
break;
default:
throw new IllegalArgumentException(I18n.err(I18n.ERR_13717_UNEXPECTED_OBJECT_CLASS_TYPE_ENUM, objectClass.getType()));
}
objectClass.getSuperiors().add(superior);
} catch (LdapException ne) {
// Cannot find the OC
String msg = I18n.err(I18n.ERR_13769_CANNOT_REGISTER_SUPERIOR_MISSING, objectClass.getOid(), superiorName);
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_NONEXISTENT_SUPERIOR, msg, ne);
ldapSchemaException.setSourceObject(objectClass);
ldapSchemaException.setRelatedId(superiorName);
errors.add(ldapSchemaException);
LOG.info(msg);
return;
}
}
}
}
use of org.apache.directory.api.ldap.model.schema.ObjectClass 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.ObjectClass 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);
}
}
}
}
Aggregations