}
// Looping on schemas from the first list
for ( Schema schemaFromL1 : l1 )
{
Schema schemaFromL2 = mapL2.get( Strings.toLowerCase( schemaFromL1.getSchemaName() ) );
if ( schemaFromL2 == null )
{
SchemaDifference schemaDifference = new SchemaDifference( schemaFromL1, null, DifferenceType.REMOVED );
differences.add( schemaDifference );
// Adding attribute types
for ( AttributeType at : schemaFromL1.getAttributeTypes() )
{
schemaDifference.addAttributeTypeDifference( new AttributeTypeDifference( null, at,
DifferenceType.REMOVED ) );
}
// Adding object classes
for ( ObjectClass oc : schemaFromL1.getObjectClasses() )
{
schemaDifference.addObjectClassDifference( new ObjectClassDifference( null, oc,
DifferenceType.REMOVED ) );
}
}
else
{
SchemaDifference schemaDifference = new SchemaDifference( schemaFromL1, schemaFromL2,
DifferenceType.IDENTICAL );
differences.add( schemaDifference );
// Building Maps for attribute types
Map<String, AttributeType> atMapL1 = new HashMap<String, AttributeType>();
for ( AttributeType at : schemaFromL1.getAttributeTypes() )
{
atMapL1.put( at.getOid(), at );
}
Map<String, AttributeType> atMapL2 = new HashMap<String, AttributeType>();
for ( AttributeType at : schemaFromL2.getAttributeTypes() )
{
atMapL2.put( at.getOid(), at );
}
// Looping on the attribute types from the Schema from the first list
for ( AttributeType atFromL1 : schemaFromL1.getAttributeTypes() )
{
AttributeType atFromL2 = atMapL2.get( atFromL1.getOid() );
if ( atFromL2 == null )
{
AttributeTypeDifference attributeTypeDifference = new AttributeTypeDifference( atFromL1, null,
DifferenceType.REMOVED );
schemaDifference.addAttributeTypeDifference( attributeTypeDifference );
schemaDifference.setType( DifferenceType.MODIFIED );
}
else
{
AttributeTypeDifference attributeTypeDifference = new AttributeTypeDifference( atFromL1,
atFromL2, DifferenceType.IDENTICAL );
schemaDifference.addAttributeTypeDifference( attributeTypeDifference );
List<PropertyDifference> atDifferences = getDifferences( atFromL1, atFromL2 );
if ( atDifferences.size() > 0 )
{
attributeTypeDifference.setType( DifferenceType.MODIFIED );
attributeTypeDifference.addDifferences( atDifferences );
schemaDifference.setType( DifferenceType.MODIFIED );
}
}
}
// Looping on the attribute types from the Schema from the second list
for ( AttributeType atFromL2 : schemaFromL2.getAttributeTypes() )
{
AttributeType atFromL1 = atMapL1.get( atFromL2.getOid() );
if ( atFromL1 == null )
{
AttributeTypeDifference attributeTypeDifference = new AttributeTypeDifference( null, atFromL2,
DifferenceType.ADDED );
schemaDifference.addAttributeTypeDifference( attributeTypeDifference );
schemaDifference.setType( DifferenceType.MODIFIED );
}
// If atFromL1 exists, then it has already been processed when looping on the first list.
}
// Building Maps for object classes
Map<String, ObjectClass> ocMapL1 = new HashMap<String, ObjectClass>();
for ( ObjectClass oc : schemaFromL1.getObjectClasses() )
{
ocMapL1.put( oc.getOid(), oc );
}
Map<String, ObjectClass> ocMapL2 = new HashMap<String, ObjectClass>();
for ( ObjectClass oc : schemaFromL2.getObjectClasses() )
{
ocMapL2.put( oc.getOid(), oc );
}
// Looping on the object classes from the Schema from the first list
for ( ObjectClass ocFromL1 : schemaFromL1.getObjectClasses() )
{
ObjectClass ocFromL2 = ocMapL2.get( ocFromL1.getOid() );
if ( ocFromL2 == null )
{
ObjectClassDifference objectClassDifference = new ObjectClassDifference( ocFromL1, null,
DifferenceType.REMOVED );
schemaDifference.addObjectClassDifference( objectClassDifference );
schemaDifference.setType( DifferenceType.MODIFIED );
}
else
{
ObjectClassDifference objectClassDifference = new ObjectClassDifference( ocFromL1, ocFromL2,
DifferenceType.IDENTICAL );
schemaDifference.addObjectClassDifference( objectClassDifference );
List<PropertyDifference> ocDifferences = getDifferences( ocFromL1, ocFromL2 );
if ( ocDifferences.size() > 0 )
{
objectClassDifference.setType( DifferenceType.MODIFIED );
objectClassDifference.addDifferences( ocDifferences );
schemaDifference.setType( DifferenceType.MODIFIED );
}
}
}
// Looping on the object classes from the Schema from the second list
for ( ObjectClass ocFromL2 : schemaFromL2.getObjectClasses() )
{
ObjectClass ocFromL1 = ocMapL1.get( ocFromL2.getOid() );
if ( ocFromL1 == null )
{
ObjectClassDifference objectClassDifference = new ObjectClassDifference( null, ocFromL2,
DifferenceType.ADDED );
schemaDifference.addObjectClassDifference( objectClassDifference );
schemaDifference.setType( DifferenceType.MODIFIED );
}
// If ocFromL1 exists, then it has already been processed when looping on the first list.
}
}
}
// Looping on schemas from the second list
for ( Schema schemaFromL2 : l2 )
{
Schema schemaFromL1 = mapL1.get( Strings.toLowerCase( schemaFromL2.getSchemaName() ) );
if ( schemaFromL1 == null )
{
SchemaDifference schemaDifference = new SchemaDifference( null, schemaFromL2, DifferenceType.ADDED );
differences.add( schemaDifference );