use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.
the class SchemaEntityFactory method getAttributeType.
/**
* {@inheritDoc}
* @throws LdapInvalidAttributeValueException If the AttributeType does not exist
* @throws LdapUnwillingToPerformException If the schema is not loaded
*/
@Override
public AttributeType getAttributeType(SchemaManager schemaManager, Entry entry, Registries targetRegistries, String schemaName) throws LdapInvalidAttributeValueException, LdapUnwillingToPerformException {
checkEntry(entry, SchemaConstants.ATTRIBUTE_TYPE);
// The AttributeType OID
String oid = getOid(entry, SchemaConstants.ATTRIBUTE_TYPE, schemaManager.isStrict());
// Get the schema
if (!schemaManager.isSchemaLoaded(schemaName)) {
// The schema is not loaded, this is an error
String msg = I18n.err(I18n.ERR_16032_CANNOT_ADD_AT, 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_16033_CANNOT_ADD_AT_IN_REGISTRY, entry.getDn().getName(), schemaName);
LOG.info(msg);
schema = schemaManager.getLoadedSchema(schemaName);
}
// Create the new AttributeType
MutableAttributeType attributeType = new MutableAttributeType(oid);
if (schemaManager.isRelaxed()) {
attributeType.setRelaxed(true);
}
// Syntax
Attribute mSyntax = entry.get(MetaSchemaConstants.M_SYNTAX_AT);
if ((mSyntax != null) && (mSyntax.get() != null)) {
attributeType.setSyntaxOid(mSyntax.getString());
}
// Syntax Length
Attribute mSyntaxLength = entry.get(MetaSchemaConstants.M_LENGTH_AT);
if (mSyntaxLength != null) {
attributeType.setSyntaxLength(Integer.parseInt(mSyntaxLength.getString()));
}
// Equality
Attribute mEquality = entry.get(MetaSchemaConstants.M_EQUALITY_AT);
if (mEquality != null) {
attributeType.setEqualityOid(mEquality.getString());
}
// Ordering
Attribute mOrdering = entry.get(MetaSchemaConstants.M_ORDERING_AT);
if (mOrdering != null) {
attributeType.setOrderingOid(mOrdering.getString());
}
// Substr
Attribute mSubstr = entry.get(MetaSchemaConstants.M_SUBSTR_AT);
if (mSubstr != null) {
attributeType.setSubstringOid(mSubstr.getString());
}
Attribute mSupAttributeType = entry.get(MetaSchemaConstants.M_SUP_ATTRIBUTE_TYPE_AT);
// Sup
if (mSupAttributeType != null) {
attributeType.setSuperiorOid(mSupAttributeType.getString());
}
// isCollective
Attribute mCollective = entry.get(MetaSchemaConstants.M_COLLECTIVE_AT);
if (mCollective != null) {
String val = mCollective.getString();
attributeType.setCollective("TRUE".equalsIgnoreCase(val));
}
// isSingleValued
Attribute mSingleValued = entry.get(MetaSchemaConstants.M_SINGLE_VALUE_AT);
if (mSingleValued != null) {
String val = mSingleValued.getString();
attributeType.setSingleValued("TRUE".equalsIgnoreCase(val));
}
// isReadOnly
Attribute mNoUserModification = entry.get(MetaSchemaConstants.M_NO_USER_MODIFICATION_AT);
if (mNoUserModification != null) {
String val = mNoUserModification.getString();
attributeType.setUserModifiable(!"TRUE".equalsIgnoreCase(val));
}
// Usage
Attribute mUsage = entry.get(MetaSchemaConstants.M_USAGE_AT);
if (mUsage != null) {
attributeType.setUsage(UsageEnum.getUsage(mUsage.getString()));
}
// Common properties
setSchemaObjectProperties(attributeType, entry, schema);
return attributeType;
}
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, Entry entry, Registries targetRegistries, String schemaName) throws LdapException {
checkEntry(entry, SchemaConstants.COMPARATOR);
// The Comparator OID
String oid = getOid(entry, SchemaConstants.COMPARATOR, schemaManager.isStrict());
// Get the schema
if (!schemaManager.isSchemaLoaded(schemaName)) {
// The schema is not loaded. We can't create the requested Comparator
String msg = I18n.err(I18n.ERR_16022_CANNOT_ADD_CMP, 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_16023_CANNOT_ADD_CMP_IN_REGISTRY, entry.getDn().getName(), schemaName);
LOG.info(msg);
schema = schemaManager.getLoadedSchema(schemaName);
}
// The FQCN
String fqcn = getFqcn(entry, SchemaConstants.COMPARATOR);
// The ByteCode
Attribute byteCode = entry.get(MetaSchemaConstants.M_BYTECODE_AT);
try {
// Class load the comparator
LdapComparator<?> comparator = classLoadComparator(schemaManager, oid, fqcn, byteCode);
// Update the common fields
setSchemaObjectProperties(comparator, entry, schema);
// return the resulting comparator
return comparator;
} catch (Exception e) {
throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, e.getMessage(), e);
}
}
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, NormalizerDescription normalizerDescription, Registries targetRegistries, String schemaName) throws LdapException {
checkDescription(normalizerDescription, SchemaConstants.NORMALIZER);
// The Comparator OID
String oid = getOid(normalizerDescription, SchemaConstants.NORMALIZER);
// Get the schema
Schema schema = getSchema(schemaName, targetRegistries);
if (schema == null) {
// The schema is not loaded. We can't create the requested Normalizer
String msg = I18n.err(I18n.ERR_16024_CANNOT_ADD_NORMALIZER, normalizerDescription.getName(), schemaName);
LOG.warn(msg);
throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
}
// The FQCN
String fqcn = getFqcn(normalizerDescription, SchemaConstants.NORMALIZER);
// get the byteCode
Attribute byteCode = getByteCode(normalizerDescription, SchemaConstants.NORMALIZER);
// Class load the normalizer
Normalizer normalizer = classLoadNormalizer(schemaManager, oid, fqcn, byteCode);
// Update the common fields
setSchemaObjectProperties(normalizer, normalizerDescription, schema);
return normalizer;
}
use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.
the class SchemaEntityFactory method setSchemaObjectProperties.
/**
* Process the common attributes to all SchemaObjects :
* - obsolete
* - description
* - names
* - schemaName
* - specification (if any)
* - extensions
* - isReadOnly
* - isEnabled
* @throws org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException
*/
private void setSchemaObjectProperties(SchemaObject schemaObject, Entry entry, Schema schema) throws LdapInvalidAttributeValueException {
// The isObsolete field
Attribute mObsolete = entry.get(MetaSchemaConstants.M_OBSOLETE_AT);
if (mObsolete != null) {
String val = mObsolete.getString();
schemaObject.setObsolete("TRUE".equalsIgnoreCase(val));
}
// The description field
Attribute mDescription = entry.get(MetaSchemaConstants.M_DESCRIPTION_AT);
if (mDescription != null) {
schemaObject.setDescription(getStringValue(mDescription));
}
// The names field
Attribute names = entry.get(MetaSchemaConstants.M_NAME_AT);
if (names != null) {
List<String> values = new ArrayList<>();
for (Value name : names) {
values.add(name.getValue());
}
schemaObject.setNames(values);
}
// The isEnabled field
Attribute mDisabled = entry.get(MetaSchemaConstants.M_DISABLED_AT);
// Otherwise, inherit it from the schema
if (mDisabled != null) {
String val = mDisabled.getString();
schemaObject.setEnabled(!"TRUE".equalsIgnoreCase(val));
} else {
schemaObject.setEnabled(schema.isEnabled());
}
// The specification field
/*
* TODO : create the M_SPECIFICATION_AT
EntryAttribute mSpecification = entry.get( MetaSchemaConstants.M_SPECIFICATION_AT );
if ( mSpecification != null )
{
so.setSpecification( mSpecification.getString() );
}
*/
// The schemaName field
schemaObject.setSchemaName(schema.getSchemaName());
// The extensions fields
// X-SCHEMA
Attribute xSchema = entry.get(MetaSchemaConstants.X_SCHEMA_AT);
if (xSchema != null) {
String schemaName = xSchema.getString();
if (!schema.getSchemaName().equalsIgnoreCase(schemaName)) {
LOG.warn(I18n.msg(I18n.MSG_16011_SCHEMA_XSCHEMA_DIFF, schema.getSchemaName(), schemaName, entry));
}
schemaObject.addExtension(MetaSchemaConstants.X_SCHEMA_AT, schemaName);
}
// X-NOT-HUMAN-READABLE
Attribute xNotHumanReadable = entry.get(MetaSchemaConstants.X_NOT_HUMAN_READABLE_AT);
if (xNotHumanReadable != null) {
String value = xNotHumanReadable.getString();
schemaObject.addExtension(MetaSchemaConstants.X_NOT_HUMAN_READABLE_AT, value);
}
// X-READ-ONLY
Attribute xReadOnly = entry.get(MetaSchemaConstants.X_READ_ONLY_AT);
if (xReadOnly != null) {
String value = xReadOnly.getString();
schemaObject.addExtension(MetaSchemaConstants.X_READ_ONLY_AT, value);
}
}
use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.
the class SchemaEntityFactory method getOid.
/**
* Get an OID from an entry. Handles the bad cases (null OID,
* not a valid OID, ...)
*/
private String getOid(Entry entry, String objectType, boolean strict) throws LdapInvalidAttributeValueException {
// The OID
Attribute mOid = entry.get(MetaSchemaConstants.M_OID_AT);
if (mOid == null) {
String msg = I18n.err(I18n.ERR_16011_NULL_ATTRIBUTE, objectType, MetaSchemaConstants.M_OID_AT);
LOG.warn(msg);
throw new IllegalArgumentException(msg);
}
String oid = mOid.getString();
if (strict && !Oid.isOid(oid)) {
String msg = I18n.err(I18n.ERR_16012_INVALID_COMPARATOR_OID, oid);
LOG.warn(msg);
throw new LdapInvalidAttributeValueException(ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, msg);
}
return oid;
}
Aggregations