{
if ( !isExpectedElementType( me ) )
{
// if (getLogger().isErrorEnabled)
// getLogger().error ("Cannot Merge dissimilar elements. (Expected : '" + getClass ().getName () + "', found '" + me.getClass ().getName () + "')");
throw new MergeException( "Cannot Merge dissimilar elements. " + "(Expected : '" + getClass().getName() +
"', found '" + me.getClass().getName() + "')" );
}
// recessive Component Element.
AbstractMergeableElement rce = (AbstractMergeableElement) me;
Set allowedTags = new HashSet();
for ( int i = 0; i < getAllowedTags().length; i++ )
{
String tagName = getAllowedTags()[i].getTagName();
allowedTags.add( tagName );
List defaultConflictChecklist = new ArrayList();
defaultConflictChecklist.add( tagName );
if ( !isRecessiveElementInConflict( rce, defaultConflictChecklist ) &&
mergeableElementComesFromRecessive( rce, tagName ) )
{
this.addContent( (Element) rce.getChild( tagName ).clone() );
// else dominant wins in anycase!
}
else
if ( getAllowedTags()[i].isMergeable() && isRecessiveElementInConflict( rce, defaultConflictChecklist ) )
{
// this allows for merging multiple/list of elements.
try
{
getAllowedTags()[i].createMergeable( this.getChild( tagName ) )
.merge( getAllowedTags()[i].createMergeable( rce.getChild( tagName ) ),
getDefaultMergeStrategy() );
}
catch ( Exception e )
{
// TODO log to error
throw new MergeException(
"Unable to create Mergeable instance for tag " + "'" + getAllowedTags()[i] + "'.", e );
}
}
}