Search in sources :

Example 6 with SchemaObject

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;
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) AttributesFactory(org.apache.directory.api.ldap.model.schema.AttributesFactory) MatchingRuleUse(org.apache.directory.api.ldap.model.schema.MatchingRuleUse) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) ArrayList(java.util.ArrayList) SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)

Example 7 with SchemaObject

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;
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 8 with SchemaObject

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);
    }
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 9 with SchemaObject

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;
}
Also used : LdapComparator(org.apache.directory.api.ldap.model.schema.LdapComparator) SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) SyntaxChecker(org.apache.directory.api.ldap.model.schema.SyntaxChecker) ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) MatchingRuleUse(org.apache.directory.api.ldap.model.schema.MatchingRuleUse) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) NameForm(org.apache.directory.api.ldap.model.schema.NameForm) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) DitStructureRule(org.apache.directory.api.ldap.model.schema.DitStructureRule) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) DitContentRule(org.apache.directory.api.ldap.model.schema.DitContentRule) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) MutableMatchingRule(org.apache.directory.api.ldap.model.schema.MutableMatchingRule)

Example 10 with SchemaObject

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));
            }
        }
    }
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject)

Aggregations

SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)37 SchemaObjectWrapper (org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)14 Schema (org.apache.directory.api.ldap.model.schema.registries.Schema)13 ArrayList (java.util.ArrayList)12 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)12 Entry (org.apache.directory.api.ldap.model.entry.Entry)11 DefaultSchema (org.apache.directory.api.ldap.model.schema.registries.DefaultSchema)11 LoadableSchemaObject (org.apache.directory.api.ldap.model.schema.LoadableSchemaObject)10 AttributesFactory (org.apache.directory.api.ldap.model.schema.AttributesFactory)8 ParseException (java.text.ParseException)6 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)4 DitStructureRule (org.apache.directory.api.ldap.model.schema.DitStructureRule)4 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)4 ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 Set (java.util.Set)3 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)3 DitContentRule (org.apache.directory.api.ldap.model.schema.DitContentRule)3