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;
}
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;
}
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;
}
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;
}
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);
}
}
}
Aggregations