use of org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException in project directory-ldap-api by apache.
the class SchemaManagerLoadTest method testLoadCoreInetOrgPersonAndBad.
/**
* test loading the "InetOrgPerson", "core" and a bad schema
*/
@Test
public void testLoadCoreInetOrgPersonAndBad() throws Exception {
LdifSchemaLoader loader = new LdifSchemaLoader(schemaRepository);
SchemaManager schemaManager = new DefaultSchemaManager(loader);
assertTrue(schemaManager.load("system"));
try {
assertFalse(schemaManager.load("core", "bad", "cosine", "InetOrgPerson"));
fail();
} catch (LdapUnwillingToPerformException lonse) {
// expected
}
assertTrue(schemaManager.getErrors().isEmpty());
assertEquals(38, schemaManager.getAttributeTypeRegistry().size());
assertEquals(35, schemaManager.getComparatorRegistry().size());
assertEquals(35, schemaManager.getMatchingRuleRegistry().size());
assertEquals(35, schemaManager.getNormalizerRegistry().size());
assertEquals(9, schemaManager.getObjectClassRegistry().size());
assertEquals(59, schemaManager.getSyntaxCheckerRegistry().size());
assertEquals(59, schemaManager.getLdapSyntaxRegistry().size());
assertEquals(141, schemaManager.getGlobalOidRegistry().size());
assertEquals(1, schemaManager.getRegistries().getLoadedSchemas().size());
assertNotNull(schemaManager.getRegistries().getLoadedSchema("system"));
assertNull(schemaManager.getRegistries().getLoadedSchema("core"));
assertNull(schemaManager.getRegistries().getLoadedSchema("cosine"));
assertNull(schemaManager.getRegistries().getLoadedSchema("InetOrgPerson"));
}
use of org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException in project directory-ldap-api by apache.
the class SchemaEntityFactory method getSyntaxChecker.
/**
* {@inheritDoc}
*/
@Override
public SyntaxChecker getSyntaxChecker(SchemaManager schemaManager, SyntaxCheckerDescription syntaxCheckerDescription, Registries targetRegistries, String schemaName) throws LdapException {
checkDescription(syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER);
// The Comparator OID
String oid = getOid(syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER);
// Get the schema
Schema schema = getSchema(schemaName, targetRegistries);
if (schema == null) {
// The schema is not loaded. We can't create the requested SyntaxChecker
String msg = I18n.err(I18n.ERR_16019_CANNOT_ADD_SC, syntaxCheckerDescription.getName(), schemaName);
LOG.warn(msg);
throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
}
// The FQCN
String fqcn = getFqcn(syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER);
// get the byteCode
Attribute byteCode = getByteCode(syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER);
// Class load the SyntaxChecker
SyntaxChecker syntaxChecker = classLoadSyntaxChecker(schemaManager, oid, fqcn, byteCode);
// Update the common fields
setSchemaObjectProperties(syntaxChecker, syntaxCheckerDescription, schema);
return syntaxChecker;
}
use of org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException 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.exception.LdapUnwillingToPerformException 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.exception.LdapUnwillingToPerformException 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;
}
Aggregations