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