}
private XmlPlexusConfiguration buildTopDownMergedConfiguration( PlexusConfiguration dominant,
PlexusConfiguration recessive )
{
XmlPlexusConfiguration result = new XmlPlexusConfiguration( dominant.getName() );
String value = dominant.getValue( null );
if ( StringUtils.isEmpty( value ) && recessive != null )
{
value = recessive.getValue( null );
}
if ( StringUtils.isNotEmpty( value ) )
{
result.setValue( value );
}
String[] attributeNames = dominant.getAttributeNames();
for ( int i = 0; i < attributeNames.length; i++ )
{
String attributeValue = dominant.getAttribute( attributeNames[i], null );
result.setAttribute( attributeNames[i], attributeValue );
}
if ( recessive != null )
{
attributeNames = recessive.getAttributeNames();
for ( int i = 0; i < attributeNames.length; i++ )
{
String attributeValue = recessive.getAttribute( attributeNames[i], null );
// TODO: recessive seems to be dominant here?
result.setAttribute( attributeNames[i], attributeValue );
}
}
PlexusConfiguration[] children = dominant.getChildren();
for ( int i = 0; i < children.length; i++ )
{
PlexusConfiguration childDom = children[i];
PlexusConfiguration childRec = recessive == null ? null : recessive.getChild( childDom.getName(), false );
if ( childRec != null )
{
result.addChild( buildTopDownMergedConfiguration( childDom, childRec ) );
}
else
{ // FIXME: copy, or use reference?
result.addChild( copyConfiguration( childDom ) );
}
}
return result;
}