catch ( Exception e )
{
// Not allowed.
String msg = I18n.err( I18n.ERR_04303, superiorOid, attributeType.getName() );
LdapSchemaException ldapSchemaException = new LdapSchemaException(
LdapSchemaExceptionCodes.AT_NONEXISTENT_SUPERIOR, msg, e );
ldapSchemaException.setSourceObject( attributeType );
ldapSchemaException.setRelatedId( superiorOid );
errors.add( ldapSchemaException );
LOG.info( msg );
// Get out now
return false;
}
if ( currentSuperior != null )
{
// a special case : if the superior is collective, this is an error
if ( currentSuperior.isCollective() )
{
String msg = I18n.err( I18n.ERR_04482_CANNOT_SUBTYPE_COLLECTIVE,
currentSuperior, attributeType.getName() );
LdapSchemaException ldapSchemaException = new LdapSchemaException(
LdapSchemaExceptionCodes.AT_CANNOT_SUBTYPE_COLLECTIVE_AT, msg );
ldapSchemaException.setSourceObject( attributeType );
errors.add( ldapSchemaException );
LOG.info( msg );
return false;
}
attributeType.setSuperior( currentSuperior );
// Recursively update the superior if not already done. We don't recurse
// if the superior's superior is not null, as it means it has already been
// handled.
if ( currentSuperior.getSuperior() == null )
{
registries.buildReference( errors, currentSuperior );
}
// Update the descendant MAP
try
{
attributeTypeRegistry.registerDescendants( attributeType, currentSuperior );
}
catch ( LdapException ne )
{
errors.add( ne );
LOG.info( ne.getMessage() );
return false;
}
// Check for cycles now
Set<String> superiors = new HashSet<String>();
superiors.add( attributeType.getOid() );
AttributeType tmp = currentSuperior;
boolean isOk = true;
while ( tmp != null )
{
if ( superiors.contains( tmp.getOid() ) )
{
// There is a cycle : bad bad bad !
// Not allowed.
String msg = I18n.err( I18n.ERR_04304, attributeType.getName() );
LdapSchemaException ldapSchemaException = new LdapSchemaException(
LdapSchemaExceptionCodes.AT_CYCLE_TYPE_HIERARCHY, msg );
ldapSchemaException.setSourceObject( attributeType );
errors.add( ldapSchemaException );
LOG.info( msg );
isOk = false;
break;
}
else
{
superiors.add( tmp.getOid() );
tmp = tmp.getSuperior();
}
}
superiors.clear();
return isOk;
}
else
{
// Not allowed.
String msg = I18n.err( I18n.ERR_04305, superiorOid, attributeType.getName() );
LdapSchemaException ldapSchemaException = new LdapSchemaException(
LdapSchemaExceptionCodes.AT_NONEXISTENT_SUPERIOR, msg );
ldapSchemaException.setSourceObject( attributeType );
ldapSchemaException.setRelatedId( superiorOid );
errors.add( ldapSchemaException );
LOG.info( msg );
// Get out now
return false;