use of org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper in project directory-ldap-api by apache.
the class DefaultSchemaLoader method loadMatchingRuleUses.
/**
* {@inheritDoc}
*/
@Override
public List<Entry> loadMatchingRuleUses(Schema... schemas) throws LdapException, IOException {
List<Entry> matchingRuleUseEntries = new ArrayList<>();
if (schemas == null) {
return matchingRuleUseEntries;
}
AttributesFactory factory = new AttributesFactory();
for (Schema schema : schemas) {
Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
for (SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers) {
SchemaObject schemaObject = schemaObjectWrapper.get();
if (schemaObject instanceof MatchingRuleUse) {
MatchingRuleUse matchingRuleUse = (MatchingRuleUse) schemaObject;
Entry matchingRuleUseEntry = factory.convert(matchingRuleUse, schema, null);
matchingRuleUseEntries.add(matchingRuleUseEntry);
}
}
}
return matchingRuleUseEntries;
}
use of org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper in project directory-ldap-api by apache.
the class Registries method associateWithSchema.
/**
* Store the given SchemaObject in the Map associating SchemaObjetcs to their
* related Schema.
*
* @param errors The list of errors we are accumulating while checking the schema
* @param schemaObject The schemaObject to register
*/
public void associateWithSchema(List<Throwable> errors, SchemaObject schemaObject) {
LOG.debug("Registering {}:{}", schemaObject.getObjectType(), schemaObject.getOid());
// Check that the SchemaObject is not already registered
if (!(schemaObject instanceof LoadableSchemaObject) && globalOidRegistry.contains(schemaObject.getOid())) {
String msg = I18n.err(I18n.ERR_13750_REGISTERING_FAILED_ALREADY_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);
// And register the schemaObject within its schema
Set<SchemaObjectWrapper> content = schemaObjects.get(schemaName);
if (content == null) {
content = new HashSet<>();
schemaObjects.put(Strings.toLowerCaseAscii(schemaName), content);
}
SchemaObjectWrapper schemaObjectWrapper = new SchemaObjectWrapper(schemaObject);
if (content.contains(schemaObjectWrapper)) {
// Already present !
// What should we do ?
LOG.info("Registering of {}:{} failed, is already present in the Registries", schemaObject.getObjectType(), schemaObject.getOid());
} else {
// Create the association
content.add(schemaObjectWrapper);
// an instance of LoadableSchemaObject
if (!(schemaObject instanceof LoadableSchemaObject)) {
try {
globalOidRegistry.register(schemaObject);
} catch (LdapException ne) {
errors.add(ne);
return;
}
}
LOG.debug("registered {} 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 dumpUsedBy.
/**
* Dump the UsedBy data structure as a String
*
* @return The UsedBy data structure
*/
public String dumpUsedBy() {
StringBuilder sb = new StringBuilder();
sb.append("USED BY :\n");
try {
for (Map.Entry<SchemaObjectWrapper, Set<SchemaObjectWrapper>> entry : usedBy.entrySet()) {
SchemaObjectWrapper wrapper = entry.getKey();
sb.append(wrapper.get().getObjectType()).append('[').append(wrapper.get().getOid()).append("] : {");
boolean isFirst = true;
for (SchemaObjectWrapper uses : entry.getValue()) {
if (isFirst) {
isFirst = false;
} else {
sb.append(", ");
}
sb.append(uses.get().getObjectType()).append('[').append(wrapper.get().getOid()).append("]");
}
sb.append("}\n");
}
} catch (Exception e) {
e.printStackTrace();
}
return sb.toString();
}
use of org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper in project directory-ldap-api by apache.
the class Registries method isReferenced.
/**
* Checks if a specific SchemaObject is referenced by any other SchemaObject.
*
* @param schemaObject The SchemaObject we are looking for
* @return true if there is at least one SchemaObjetc referencing the given one
*/
public boolean isReferenced(SchemaObject schemaObject) {
SchemaObjectWrapper wrapper = new SchemaObjectWrapper(schemaObject);
Set<SchemaObjectWrapper> set = usedBy.get(wrapper);
boolean referenced = (set != null) && !set.isEmpty();
if (LOG.isDebugEnabled()) {
if (referenced) {
LOG.debug("The {}:{} is referenced", schemaObject.getObjectType(), schemaObject.getOid());
} else {
LOG.debug("The {}:{} is not referenced", schemaObject.getObjectType(), schemaObject.getOid());
}
}
return referenced;
}
use of org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper in project directory-ldap-api by apache.
the class Registries method checkReferences.
private boolean checkReferences(SchemaObject reference, SchemaObject referee, String message) {
SchemaObjectWrapper referenceWrapper = new SchemaObjectWrapper(reference);
SchemaObjectWrapper refereeWrapper = new SchemaObjectWrapper(referee);
// Check the references : Syntax -> SyntaxChecker
if (!using.containsKey(referenceWrapper)) {
LOG.debug("The Syntax {}:{} does not reference any " + message, reference.getObjectType(), reference.getOid());
return false;
}
Set<SchemaObjectWrapper> usings = using.get(referenceWrapper);
if (!usings.contains(refereeWrapper)) {
LOG.debug("The {}:{} does not reference any " + message, reference.getObjectType(), reference.getOid());
return false;
}
// Check the referees : SyntaxChecker -> Syntax
if (!usedBy.containsKey(refereeWrapper)) {
LOG.debug("The {}:{} is not referenced by any " + message, referee.getObjectType(), referee.getOid());
return false;
}
Set<SchemaObjectWrapper> used = usedBy.get(refereeWrapper);
if (!used.contains(referenceWrapper)) {
LOG.debug("The {}:{} is not referenced by any " + message, referee.getObjectType(), referee.getOid());
return false;
}
return true;
}
Aggregations