use of org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper in project directory-ldap-api by apache.
the class Registries method addUsing.
/**
* Add an association between a SchemaObject an the SchemaObject it refers
*
* @param reference The base SchemaObject
* @param referee The SchemaObject pointing on the reference
*/
private void addUsing(SchemaObject reference, SchemaObject referee) {
if ((reference == null) || (referee == null)) {
return;
}
SchemaObjectWrapper wrapper = new SchemaObjectWrapper(reference);
Set<SchemaObjectWrapper> uses = getUsing(reference);
if (uses == null) {
uses = new HashSet<>();
}
uses.add(new SchemaObjectWrapper(referee));
// Put back the set (this is a concurrentHashMap, it won't be replaced implicitly
using.put(wrapper, uses);
}
use of org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper in project directory-ldap-api by apache.
the class Registries method delUsedBy.
/**
* Del an association between a SchemaObject an the SchemaObject that refers it
*
* @param reference The base SchemaObject
* @param referee The SchemaObject pointing on the reference
*/
private void delUsedBy(SchemaObject referee, SchemaObject reference) {
if ((reference == null) || (referee == null)) {
return;
}
Set<SchemaObjectWrapper> uses = getUsedBy(referee);
if (uses == null) {
return;
}
uses.remove(new SchemaObjectWrapper(reference));
SchemaObjectWrapper wrapper = new SchemaObjectWrapper(referee);
if (uses.isEmpty()) {
usedBy.remove(wrapper);
} else {
usedBy.put(wrapper, uses);
}
}
use of org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper in project directory-ldap-api by apache.
the class Registries method dissociateFromSchema.
/**
* Store the given SchemaObject in the Map associating SchemaObjetcs to their
* related Schema.
*
* @param errors The list that collect errors
* @param schemaObject The schemaObject to register
* @throws LdapException If there is a problem
*/
public void dissociateFromSchema(List<Throwable> errors, SchemaObject schemaObject) throws LdapException {
LOG.debug("Unregistering {}:{}", schemaObject.getObjectType(), schemaObject.getOid());
// Check that the SchemaObject is already registered
if (!(schemaObject instanceof LoadableSchemaObject) && !globalOidRegistry.contains(schemaObject.getOid())) {
String msg = I18n.err(I18n.ERR_13751_UNREGISTERING_FAILED_NOT_PRESENT, schemaObject.getObjectType(), schemaObject.getOid());
LOG.error(msg);
Throwable error = new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
errors.add(error);
return;
}
// Get a normalized form of schema name
String schemaName = getSchemaName(schemaObject);
String oid = schemaObject.getOid();
// And unregister the schemaObject from its schema
Set<SchemaObjectWrapper> content = schemaObjects.get(schemaName);
SchemaObjectWrapper schemaObjectWrapper = new SchemaObjectWrapper(schemaObject);
if (!content.contains(schemaObjectWrapper)) {
// Not present !
// What should we do ?
LOG.info("Unregistering of {}:{} failed, is not present in the Registries", schemaObject.getObjectType(), schemaObject.getOid());
} else {
// Remove the association
content.remove(schemaObjectWrapper);
// an instance of LoadableSchemaObject
if (!(schemaObject instanceof LoadableSchemaObject)) {
try {
globalOidRegistry.unregister(oid);
} catch (LdapException ne) {
errors.add(ne);
return;
}
}
LOG.debug("Unregistered {} for OID {}", schemaObject.getName(), schemaObject.getOid());
}
}
use of org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper in project directory-ldap-api by apache.
the class Registries method delUsing.
/**
* Del an association between a SchemaObject an the SchemaObject it refers
*
* @param reference The base SchemaObject
* @param referee The SchemaObject pointing on the reference
*/
private void delUsing(SchemaObject reference, SchemaObject referee) {
if ((reference == null) || (referee == null)) {
return;
}
Set<SchemaObjectWrapper> uses = getUsing(reference);
if (uses == null) {
return;
}
uses.remove(new SchemaObjectWrapper(referee));
SchemaObjectWrapper wrapper = new SchemaObjectWrapper(reference);
if (uses.isEmpty()) {
using.remove(wrapper);
} else {
using.put(wrapper, uses);
}
}
use of org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper 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