Search in sources :

Example 21 with Attribute

use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.

the class SchemaEntityFactory method getNormalizer.

/**
 * {@inheritDoc}
 */
@Override
public Normalizer getNormalizer(SchemaManager schemaManager, Entry entry, Registries targetRegistries, String schemaName) throws LdapException {
    checkEntry(entry, SchemaConstants.NORMALIZER);
    // The Normalizer OID
    String oid = getOid(entry, SchemaConstants.NORMALIZER, schemaManager.isStrict());
    // Get the schema
    if (!schemaManager.isSchemaLoaded(schemaName)) {
        // The schema is not loaded. We can't create the requested Normalizer
        String msg = I18n.err(I18n.ERR_16024_CANNOT_ADD_NORMALIZER, entry.getDn().getName(), schemaName);
        LOG.warn(msg);
        throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
    }
    Schema schema = getSchema(schemaName, targetRegistries);
    if (schema == null) {
        // The schema is disabled. We still have to update the backend
        String msg = I18n.err(I18n.ERR_16025_CANNOT_ADD_NORMALIZER_IN_REGISTRY, entry.getDn().getName(), schemaName);
        LOG.info(msg);
        schema = schemaManager.getLoadedSchema(schemaName);
    }
    // The FQCN
    String className = getFqcn(entry, SchemaConstants.NORMALIZER);
    // The ByteCode
    Attribute byteCode = entry.get(MetaSchemaConstants.M_BYTECODE_AT);
    try {
        // Class load the Normalizer
        Normalizer normalizer = classLoadNormalizer(schemaManager, oid, className, byteCode);
        // Update the common fields
        setSchemaObjectProperties(normalizer, entry, schema);
        // return the resulting Normalizer
        return normalizer;
    } catch (Exception e) {
        throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, e.getMessage(), e);
    }
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) InvocationTargetException(java.lang.reflect.InvocationTargetException) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 22 with Attribute

use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.

the class SchemaEntityFactory method getLdapComparator.

/**
 * {@inheritDoc}
 */
@Override
public LdapComparator<?> getLdapComparator(SchemaManager schemaManager, LdapComparatorDescription comparatorDescription, Registries targetRegistries, String schemaName) throws LdapException {
    checkDescription(comparatorDescription, SchemaConstants.COMPARATOR);
    // The Comparator OID
    String oid = getOid(comparatorDescription, SchemaConstants.COMPARATOR);
    // Get the schema
    Schema schema = getSchema(schemaName, targetRegistries);
    if (schema == null) {
        // The schema is not loaded. We can't create the requested Comparator
        String msg = I18n.err(I18n.ERR_16022_CANNOT_ADD_CMP, comparatorDescription.getName(), schemaName);
        LOG.warn(msg);
        throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
    }
    // The FQCN
    String fqcn = getFqcn(comparatorDescription, SchemaConstants.COMPARATOR);
    // get the byteCode
    Attribute byteCode = getByteCode(comparatorDescription, SchemaConstants.COMPARATOR);
    // Class load the comparator
    LdapComparator<?> comparator = classLoadComparator(schemaManager, oid, fqcn, byteCode);
    // Update the common fields
    setSchemaObjectProperties(comparator, comparatorDescription, schema);
    return comparator;
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema)

Example 23 with Attribute

use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.

the class SchemaEntityFactory method getObjectClass.

/**
 * {@inheritDoc}
 */
@Override
public ObjectClass getObjectClass(SchemaManager schemaManager, Entry entry, Registries targetRegistries, String schemaName) throws LdapException {
    checkEntry(entry, SchemaConstants.OBJECT_CLASS);
    // The ObjectClass OID
    String oid = getOid(entry, SchemaConstants.OBJECT_CLASS, schemaManager.isStrict());
    // Get the schema
    if (!schemaManager.isSchemaLoaded(schemaName)) {
        // The schema is not loaded. We can't create the requested ObjectClass
        String msg = I18n.err(I18n.ERR_16030_CANNOT_ADD_OC, entry.getDn().getName(), schemaName);
        LOG.warn(msg);
        throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
    }
    Schema schema = getSchema(schemaName, targetRegistries);
    if (schema == null) {
        // The schema is disabled. We still have to update the backend
        String msg = I18n.err(I18n.ERR_16031_CANNOT_ADD_OC_IN_REGISTRY, entry.getDn().getName(), schemaName);
        LOG.info(msg);
        schema = schemaManager.getLoadedSchema(schemaName);
    }
    // Create the ObjectClass instance
    MutableObjectClass oc = new MutableObjectClass(oid);
    // The Sup field
    Attribute mSuperiors = entry.get(MetaSchemaConstants.M_SUP_OBJECT_CLASS_AT);
    if (mSuperiors != null) {
        oc.setSuperiorOids(getStrings(mSuperiors));
    }
    // The May field
    Attribute mMay = entry.get(MetaSchemaConstants.M_MAY_AT);
    if (mMay != null) {
        oc.setMayAttributeTypeOids(getStrings(mMay));
    }
    // The Must field
    Attribute mMust = entry.get(MetaSchemaConstants.M_MUST_AT);
    if (mMust != null) {
        oc.setMustAttributeTypeOids(getStrings(mMust));
    }
    // The objectClassType field
    Attribute mTypeObjectClass = entry.get(MetaSchemaConstants.M_TYPE_OBJECT_CLASS_AT);
    if (mTypeObjectClass != null) {
        String type = mTypeObjectClass.getString();
        oc.setType(ObjectClassTypeEnum.getClassType(type));
    }
    // Common properties
    setSchemaObjectProperties(oc, entry, schema);
    return oc;
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) MutableObjectClass(org.apache.directory.api.ldap.model.schema.MutableObjectClass)

Example 24 with Attribute

use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.

the class SchemaEntityFactory method getFqcn.

/**
 * Process the FQCN attribute
 * @throws LdapInvalidAttributeValueException
 */
private String getFqcn(Entry entry, String objectType) throws LdapInvalidAttributeValueException {
    // The FQCN
    Attribute mFqcn = entry.get(MetaSchemaConstants.M_FQCN_AT);
    if (mFqcn == null) {
        String msg = I18n.err(I18n.ERR_16034_ENTRY_WITHOUT_VALID_AT, objectType, MetaSchemaConstants.M_FQCN_AT);
        LOG.warn(msg);
        throw new IllegalArgumentException(msg);
    }
    return mFqcn.getString();
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute)

Example 25 with Attribute

use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.

the class SchemaElementImpl method nameToLdif.

/**
 * @return the Names as Ldif lines
 * @throws org.apache.directory.api.ldap.model.exception.LdapException If the conversion goes wrong
 */
private String nameToLdif() throws LdapException {
    if (names.isEmpty()) {
        return "";
    } else {
        Entry entry = new DefaultEntry();
        Attribute attribute = new DefaultAttribute("m-name");
        for (String name : names) {
            attribute.add(name);
        }
        entry.put(attribute);
        return LdifUtils.convertAttributesToLdif(entry);
    }
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute)

Aggregations

Attribute (org.apache.directory.api.ldap.model.entry.Attribute)269 Test (org.junit.Test)180 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)168 Entry (org.apache.directory.api.ldap.model.entry.Entry)94 Modification (org.apache.directory.api.ldap.model.entry.Modification)56 Value (org.apache.directory.api.ldap.model.entry.Value)52 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)46 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)35 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)23 EncoderException (org.apache.directory.api.asn1.EncoderException)20 ByteBuffer (java.nio.ByteBuffer)18 DecoderException (org.apache.directory.api.asn1.DecoderException)18 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)18 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)18 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)18 SearchResultEntry (org.apache.directory.api.ldap.model.message.SearchResultEntry)18 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)16 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)16 ModifyRequest (org.apache.directory.api.ldap.model.message.ModifyRequest)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13