use of org.apache.directory.api.ldap.model.exception.LdapSchemaViolationException in project directory-ldap-api by apache.
the class Registries method resolve.
/**
* Check if the Comparator, Normalizer and the syntax are
* existing for a matchingRule.
*/
private void resolve(MatchingRule matchingRule, List<Throwable> errors) {
// Process the Syntax. It can't be null
String syntaxOid = matchingRule.getSyntaxOid();
if (syntaxOid != null) {
// Check if the Syntax is present in the registries
try {
ldapSyntaxRegistry.lookup(syntaxOid);
} catch (LdapException ne) {
// This MR's syntax has not been loaded into the Registries.
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OID_ALREADY_REGISTERED, I18n.err(I18n.ERR_13748_MATCHING_RULE_NO_SYNTAX, matchingRule.getOid()), ne);
ldapSchemaException.setSourceObject(matchingRule);
errors.add(ldapSchemaException);
}
} else {
// This is an error.
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OID_ALREADY_REGISTERED, I18n.err(I18n.ERR_13748_MATCHING_RULE_NO_SYNTAX, matchingRule.getOid()));
ldapSchemaException.setSourceObject(matchingRule);
errors.add(ldapSchemaException);
}
// Process the Normalizer
Normalizer normalizer = matchingRule.getNormalizer();
if (normalizer == null) {
// Ok, no normalizer, this is an error
Throwable error = new LdapSchemaViolationException(ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err(I18n.ERR_13220_NO_NORMALIZER, matchingRule.getOid()));
errors.add(error);
}
// Process the Comparator
LdapComparator<?> comparator = matchingRule.getLdapComparator();
if (comparator == null) {
// Ok, no comparator, this is an error
Throwable error = new LdapSchemaViolationException(ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err(I18n.ERR_04296, matchingRule.getOid()));
errors.add(error);
}
}
use of org.apache.directory.api.ldap.model.exception.LdapSchemaViolationException in project directory-ldap-api by apache.
the class WrappedPartialResultException method wrap.
/**
* Wraps a LDAP exception into a NaingException
*
* @param t The original exception
* @throws NamingException The wrapping JNDI exception
*/
public static void wrap(Throwable t) throws NamingException {
if (t instanceof NamingException) {
throw (NamingException) t;
}
NamingException ne;
if ((t instanceof LdapAffectMultipleDsaException) || (t instanceof LdapAliasDereferencingException) || (t instanceof LdapLoopDetectedException) || (t instanceof LdapAliasException) || (t instanceof LdapOperationErrorException) || (t instanceof LdapOtherException)) {
ne = new NamingException(t.getLocalizedMessage());
} else if (t instanceof LdapAttributeInUseException) {
ne = new AttributeInUseException(t.getLocalizedMessage());
} else if (t instanceof LdapAuthenticationException) {
ne = new AuthenticationException(t.getLocalizedMessage());
} else if (t instanceof LdapAuthenticationNotSupportedException) {
ne = new AuthenticationNotSupportedException(t.getLocalizedMessage());
} else if (t instanceof LdapContextNotEmptyException) {
ne = new ContextNotEmptyException(t.getLocalizedMessage());
} else if (t instanceof LdapEntryAlreadyExistsException) {
ne = new NameAlreadyBoundException(t.getLocalizedMessage());
} else if (t instanceof LdapInvalidAttributeTypeException) {
ne = new InvalidAttributeIdentifierException(t.getLocalizedMessage());
} else if (t instanceof LdapInvalidAttributeValueException) {
ne = new InvalidAttributeValueException(t.getLocalizedMessage());
} else if (t instanceof LdapInvalidDnException) {
ne = new InvalidNameException(t.getLocalizedMessage());
} else if (t instanceof LdapInvalidSearchFilterException) {
ne = new InvalidSearchFilterException(t.getLocalizedMessage());
} else if (t instanceof LdapNoPermissionException) {
ne = new NoPermissionException(t.getLocalizedMessage());
} else if (t instanceof LdapNoSuchAttributeException) {
ne = new NoSuchAttributeException(t.getLocalizedMessage());
} else if (t instanceof LdapNoSuchObjectException) {
ne = new NameNotFoundException(t.getLocalizedMessage());
} else if (t instanceof LdapProtocolErrorException) {
ne = new CommunicationException(t.getLocalizedMessage());
} else if (t instanceof LdapReferralException) {
ne = new WrappedReferralException((LdapReferralException) t);
} else if (t instanceof LdapPartialResultException) {
ne = new WrappedPartialResultException((LdapPartialResultException) t);
} else if (t instanceof LdapSchemaViolationException) {
ne = new SchemaViolationException(t.getLocalizedMessage());
} else if (t instanceof LdapServiceUnavailableException) {
ne = new ServiceUnavailableException(t.getLocalizedMessage());
} else if (t instanceof LdapTimeLimitExceededException) {
ne = new TimeLimitExceededException(t.getLocalizedMessage());
} else if (t instanceof LdapUnwillingToPerformException) {
ne = new OperationNotSupportedException(t.getLocalizedMessage());
} else {
ne = new NamingException(t.getLocalizedMessage());
}
ne.setRootCause(t);
throw ne;
}
use of org.apache.directory.api.ldap.model.exception.LdapSchemaViolationException in project directory-ldap-api by apache.
the class Registries method resolveRecursive.
/**
* Check AttributeType referential integrity
*/
private void resolveRecursive(AttributeType attributeType, Set<String> processed, List<Throwable> errors) {
// Process the Superior, if any
String superiorOid = attributeType.getSuperiorOid();
AttributeType superior = null;
if (superiorOid != null) {
// Check if the Superior is present in the registries
try {
superior = attributeTypeRegistry.lookup(superiorOid);
} catch (LdapException ne) {
// This AT's superior has not been loaded into the Registries.
if (!processed.contains(superiorOid)) {
errors.add(ne);
}
}
// processed yet.
if (superior != null) {
if (!processed.contains(superiorOid)) {
resolveRecursive(superior, processed, errors);
processed.add(attributeType.getOid());
} else {
// Not allowed : we have a cyle
Throwable error = new LdapSchemaViolationException(ResultCodeEnum.OTHER, I18n.err(I18n.ERR_13749_AT_WITH_CYCLE, attributeType.getOid()));
errors.add(error);
return;
}
}
}
// Process the Syntax. If it's null, the attributeType must have
// a Superior.
String syntaxOid = attributeType.getSyntaxOid();
if (syntaxOid != null) {
// Check if the Syntax is present in the registries
try {
ldapSyntaxRegistry.lookup(syntaxOid);
} catch (LdapException ne) {
// This AT's syntax has not been loaded into the Registries.
errors.add(ne);
}
} else {
// No Syntax : get it from the AttributeType's superior
if (superior == null) {
// This is an error. if the AT does not have a Syntax,
// then it must have a superior, which syntax is get from.
Throwable error = new LdapSchemaViolationException(ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err(I18n.ERR_04298, attributeType.getOid()));
errors.add(error);
}
}
// Process the EQUALITY MatchingRule. It may be null, but if it's not
// it must have been processed before
String equalityOid = attributeType.getEqualityOid();
if (equalityOid != null) {
// Check if the MatchingRule is present in the registries
try {
matchingRuleRegistry.lookup(equalityOid);
} catch (LdapException ne) {
// This AT's EQUALITY matchingRule has not been loaded into the Registries.
errors.add(ne);
}
}
// Process the ORDERING MatchingRule. It may be null, but if it's not
// it must have been processed before
String orderingOid = attributeType.getOrderingOid();
if (orderingOid != null) {
// Check if the MatchingRule is present in the registries
try {
matchingRuleRegistry.lookup(orderingOid);
} catch (LdapException ne) {
// This AT's ORDERING matchingRule has not been loaded into the Registries.
errors.add(ne);
}
}
// Process the SUBSTR MatchingRule. It may be null, but if it's not
// it must have been processed before
String substringOid = attributeType.getSubstringOid();
if (substringOid != null) {
// Check if the MatchingRule is present in the registries
try {
matchingRuleRegistry.lookup(substringOid);
} catch (LdapException ne) {
// This AT's SUBSTR matchingRule has not been loaded into the Registries.
errors.add(ne);
}
}
}
Aggregations