Search in sources :

Example 91 with DefaultEntry

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

the class AttributesFactory method convert.

/**
 * Creates the attributes of an entry representing an objectClass.
 *
 * <pre>
 *  objectclass ( 1.3.6.1.4.1.18060.0.4.0.3.2
 *      NAME 'metaObjectClass'
 *      DESC 'meta definition of the objectclass object'
 *      SUP metaTop
 *      STRUCTURAL
 *      MUST m-oid
 *      MAY ( m-name $ m-obsolete $ m-supObjectClass $ m-typeObjectClass $ m-must $
 *            m-may $ m-extensionObjectClass )
 *  )
 * </pre>
 *
 * @param objectClass the objectClass to produce a meta schema entry for
 * @param schema The schema containing this ObjectClass
 * @param schemaManager The SchemaManager
 * @return the attributes of the metaSchema entry representing the objectClass
 * @throws LdapException If the conversion failed
 */
public Entry convert(ObjectClass objectClass, Schema schema, SchemaManager schemaManager) throws LdapException {
    Entry entry = new DefaultEntry(schemaManager);
    entry.put(SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_OBJECT_CLASS_OC);
    entry.put(MetaSchemaConstants.M_TYPE_OBJECT_CLASS_AT, objectClass.getType().toString());
    entry.put(SchemaConstants.CREATORS_NAME_AT, schema.getOwner());
    entry.put(SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime());
    injectCommon(objectClass, entry, schemaManager);
    Attribute attr;
    // handle the superior objectClasses
    if ((objectClass.getSuperiorOids() != null) && !objectClass.getSuperiorOids().isEmpty()) {
        if (schemaManager != null) {
            attr = new DefaultAttribute(schemaManager.getAttributeType(MetaSchemaConstants.M_SUP_OBJECT_CLASS_AT));
        } else {
            attr = new DefaultAttribute(MetaSchemaConstants.M_SUP_OBJECT_CLASS_AT);
        }
        for (String superior : objectClass.getSuperiorOids()) {
            attr.add(superior);
        }
        entry.put(attr);
    }
    // add the must list
    if ((objectClass.getMustAttributeTypeOids() != null) && !objectClass.getMustAttributeTypeOids().isEmpty()) {
        if (schemaManager != null) {
            attr = new DefaultAttribute(schemaManager.getAttributeType(MetaSchemaConstants.M_MUST_AT));
        } else {
            attr = new DefaultAttribute(MetaSchemaConstants.M_MUST_AT);
        }
        for (String mustOid : objectClass.getMustAttributeTypeOids()) {
            attr.add(mustOid);
        }
        entry.put(attr);
    }
    // add the may list
    if ((objectClass.getMayAttributeTypeOids() != null) && !objectClass.getMayAttributeTypeOids().isEmpty()) {
        if (schemaManager != null) {
            attr = new DefaultAttribute(schemaManager.getAttributeType(MetaSchemaConstants.M_MAY_AT));
        } else {
            attr = new DefaultAttribute(MetaSchemaConstants.M_MAY_AT);
        }
        for (String mayOid : objectClass.getMayAttributeTypeOids()) {
            attr.add(mayOid);
        }
        entry.put(attr);
    }
    return 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)

Example 92 with DefaultEntry

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

the class AttributesFactory method convert.

/**
 * Converts a DitStructureRule into an Entry
 *
 * @param ditStructureRule The DitStructureRule to convert
 * @param schema The schema containing this DitStructureRule
 * @param schemaManager The SchemaManager
 * @return The converted DitStructureRule
 */
public Entry convert(DitStructureRule ditStructureRule, Schema schema, SchemaManager schemaManager) {
    Entry entry = new DefaultEntry(schemaManager);
    entry.put(SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, "");
    entry.put(SchemaConstants.CREATORS_NAME_AT, schema.getOwner());
    entry.put(SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime());
    return entry;
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry)

Example 93 with DefaultEntry

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

the class AttributesFactory method convert.

/**
 * Converts a DitContentRule into an Entry
 *
 * @param dITContentRule The DitContentRule to convert
 * @param schema The schema containing this DitContentRule
 * @param schemaManager The SchemaManager
 * @return The converted DitContentRule
 */
public Entry convert(DitContentRule dITContentRule, Schema schema, SchemaManager schemaManager) {
    Entry entry = new DefaultEntry(schemaManager);
    entry.put(SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, "");
    entry.put(SchemaConstants.CREATORS_NAME_AT, schema.getOwner());
    entry.put(SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime());
    return entry;
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry)

Example 94 with DefaultEntry

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

the class AttributesFactory method convert.

/**
 * <pre>
 *    objectclass ( 1.3.6.1.4.1.18060.0.4.0.3.3
 *       NAME 'metaAttributeType'
 *       DESC 'meta definition of the AttributeType object'
 *       SUP metaTop
 *       STRUCTURAL
 *       MUST ( m-name $ m-syntax )
 *       MAY ( m-supAttributeType $ m-obsolete $ m-equality $ m-ordering $
 *             m-substr $ m-singleValue $ m-collective $ m-noUserModification $
 *             m-usage $ m-extensionAttributeType )
 *    )
 * </pre>
 *
 * @param attributeType The AttributeType to convert
 * @param schema The schema containing this AttributeType
 * @param schemaManager The SchemaManager
 * @return The converted AttributeType
 * @throws LdapException If the conversion failed
 */
public Entry convert(AttributeType attributeType, Schema schema, SchemaManager schemaManager) throws LdapException {
    Entry entry = new DefaultEntry(schemaManager);
    entry.put(SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_ATTRIBUTE_TYPE_OC);
    entry.put(MetaSchemaConstants.M_COLLECTIVE_AT, getBoolean(attributeType.isCollective()));
    entry.put(MetaSchemaConstants.M_NO_USER_MODIFICATION_AT, getBoolean(!attributeType.isUserModifiable()));
    entry.put(MetaSchemaConstants.M_SINGLE_VALUE_AT, getBoolean(attributeType.isSingleValued()));
    entry.put(MetaSchemaConstants.M_USAGE_AT, attributeType.getUsage().toString());
    entry.put(SchemaConstants.CREATORS_NAME_AT, schema.getOwner());
    entry.put(SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime());
    injectCommon(attributeType, entry, schemaManager);
    String superiorOid = attributeType.getSuperiorOid();
    if (superiorOid != null) {
        entry.put(MetaSchemaConstants.M_SUP_ATTRIBUTE_TYPE_AT, superiorOid);
    }
    if (attributeType.getEqualityOid() != null) {
        entry.put(MetaSchemaConstants.M_EQUALITY_AT, attributeType.getEqualityOid());
    }
    if (attributeType.getSubstringOid() != null) {
        entry.put(MetaSchemaConstants.M_SUBSTR_AT, attributeType.getSubstringOid());
    }
    if (attributeType.getOrderingOid() != null) {
        entry.put(MetaSchemaConstants.M_ORDERING_AT, attributeType.getOrderingOid());
    }
    if (attributeType.getSyntaxOid() != null) {
        entry.put(MetaSchemaConstants.M_SYNTAX_AT, attributeType.getSyntaxOid());
    }
    return entry;
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry)

Example 95 with DefaultEntry

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

the class LdifAttributesReader method parseEntry.

/**
 * A method which parses a ldif string and returns an Entry.
 *
 * @param ldif The ldif string
 * @return An entry
 * @throws LdapLdifException If something went wrong
 */
public Entry parseEntry(String ldif) throws LdapLdifException {
    lines = new ArrayList<String>();
    position = 0;
    LOG.debug(I18n.msg(I18n.MSG_13407_STARTS_PARSING_LDIF));
    if (Strings.isEmpty(ldif)) {
        return new DefaultEntry();
    }
    StringReader strIn = new StringReader(ldif);
    reader = new BufferedReader(strIn);
    try {
        readLines();
        Entry entry = parseEntry((SchemaManager) null);
        if (LOG.isDebugEnabled()) {
            if (entry == null) {
                LOG.debug(I18n.msg(I18n.MSG_13401_PARSED_NO_ENTRY));
            } else {
                LOG.debug(I18n.msg(I18n.MSG_13402_PARSED_ONE_ENTRY));
            }
        }
        return entry;
    } catch (LdapLdifException ne) {
        LOG.error(I18n.err(I18n.ERR_13403_CANNOT_PARSE_LDIF_BUFFER, ne.getLocalizedMessage()));
        throw new LdapLdifException(I18n.err(I18n.ERR_13442_ERROR_PARSING_LDIF_BUFFER), ne);
    } finally {
        try {
            reader.close();
        } catch (IOException ioe) {
            throw new LdapLdifException(I18n.err(I18n.ERR_13450_CANNOT_CLOSE_FILE), ioe);
        }
    }
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) IOException(java.io.IOException)

Aggregations

DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)128 Entry (org.apache.directory.api.ldap.model.entry.Entry)116 Test (org.junit.Test)55 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)41 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)39 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)23 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)20 Modification (org.apache.directory.api.ldap.model.entry.Modification)16 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)16 Dn (org.apache.directory.api.ldap.model.name.Dn)15 CreateException (org.apache.directory.fortress.core.CreateException)15 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)14 Value (org.apache.directory.api.ldap.model.entry.Value)12 LdifReader (org.apache.directory.api.ldap.model.ldif.LdifReader)12 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)5 IOException (java.io.IOException)4 ObjectInputStream (java.io.ObjectInputStream)4 ObjectOutputStream (java.io.ObjectOutputStream)4