use of org.apache.directory.api.ldap.model.schema.SchemaObject 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.SchemaObject in project directory-ldap-api by apache.
the class OidRegistry method getNameSet.
/**
* Gets the names associated with an OID. An OID is unique however it may
* have many names used to refer to it. A good example is the cn and
* commonName attribute names for OID 2.5.4.3. Within a server one name
* within the set must be chosen as the primary name. This is used to
* name certain things within the server internally. If there is more than
* one name then the first name is taken to be the primary.
*
* @param oid the OID for which we return the set of common names
* @return a sorted set of names
* @throws org.apache.directory.api.ldap.model.exception.LdapException if oid does not exist
*/
public List<String> getNameSet(String oid) throws LdapException {
SchemaObject schemaObject = byOid.get(oid);
if (null == schemaObject) {
String msg = I18n.err(I18n.ERR_13741_OID_NOT_FOUND_IN_REGISTRY, oid);
LOG.error(msg);
throw new LdapException(msg);
}
List<String> names = schemaObject.getNames();
if (IS_DEBUG) {
LOG.debug("looked up names '{}' for OID '{}'", ArrayUtils.toString(names), oid);
}
return names;
}
use of org.apache.directory.api.ldap.model.schema.SchemaObject in project directory-ldap-api by apache.
the class OidRegistry method getPrimaryName.
/**
* Gets the primary name associated with an OID. The primary name is the
* first name specified for the OID.
*
* @param oid the object identifier
* @return the primary name
* @throws LdapException if oid does not exist
*/
public String getPrimaryName(String oid) throws LdapException {
SchemaObject schemaObject = byOid.get(oid);
if (schemaObject != null) {
return schemaObject.getName();
} else {
String msg = I18n.err(I18n.ERR_13741_OID_NOT_FOUND_IN_REGISTRY, oid);
LOG.error(msg);
throw new LdapException(msg);
}
}
use of org.apache.directory.api.ldap.model.schema.SchemaObject in project directory-ldap-api by apache.
the class Registries method unregister.
/**
* Unregister a SchemaObject from the registries
*
* @param schemaObject The SchemaObject we want to deregister
* @throws LdapException If the removal failed
*/
private SchemaObject unregister(List<Throwable> errors, SchemaObject schemaObject) throws LdapException {
LOG.debug("Unregistering {}:{}", schemaObject.getObjectType(), schemaObject.getOid());
// Check that the SchemaObject is present in the registries
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);
throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
}
SchemaObject unregistered;
// First call the specific registry's register method
switch(schemaObject.getObjectType()) {
case ATTRIBUTE_TYPE:
unregistered = attributeTypeRegistry.unregister((AttributeType) schemaObject);
break;
case COMPARATOR:
unregistered = comparatorRegistry.unregister((LdapComparator<?>) schemaObject);
break;
case DIT_CONTENT_RULE:
unregistered = ditContentRuleRegistry.unregister((DitContentRule) schemaObject);
break;
case DIT_STRUCTURE_RULE:
unregistered = ditStructureRuleRegistry.unregister((DitStructureRule) schemaObject);
break;
case LDAP_SYNTAX:
unregistered = ldapSyntaxRegistry.unregister((LdapSyntax) schemaObject);
break;
case MATCHING_RULE:
unregistered = matchingRuleRegistry.unregister((MatchingRule) schemaObject);
break;
case MATCHING_RULE_USE:
unregistered = matchingRuleUseRegistry.unregister((MatchingRuleUse) schemaObject);
break;
case NAME_FORM:
unregistered = nameFormRegistry.unregister((NameForm) schemaObject);
break;
case NORMALIZER:
unregistered = normalizerRegistry.unregister((Normalizer) schemaObject);
break;
case OBJECT_CLASS:
unregistered = objectClassRegistry.unregister((ObjectClass) schemaObject);
break;
case SYNTAX_CHECKER:
unregistered = syntaxCheckerRegistry.unregister((SyntaxChecker) schemaObject);
break;
default:
throw new IllegalArgumentException(I18n.err(I18n.ERR_13718_UNEXPECTED_SCHEMA_OBJECT_TYPE, schemaObject.getObjectType()));
}
return unregistered;
}
use of org.apache.directory.api.ldap.model.schema.SchemaObject in project directory-ldap-api by apache.
the class DefaultComparatorRegistry method unregisterSchemaElements.
/**
* {@inheritDoc}
*/
@Override
public void unregisterSchemaElements(String schemaName) throws LdapException {
if (schemaName == null) {
return;
}
// with the give schemaName
for (LdapComparator<?> comparator : this) {
if (schemaName.equalsIgnoreCase(comparator.getSchemaName())) {
String oid = comparator.getOid();
SchemaObject removed = unregister(oid);
if (DEBUG) {
LOG.debug(I18n.msg(I18n.MSG_13702_REMOVED_FROM_REGISTRY, removed, oid));
}
}
}
}
Aggregations