org.codehaus.plexus.configuration
Class PlexusConfigurationMerger

java.lang.Object
  extended byorg.codehaus.plexus.configuration.PlexusConfigurationMerger

public class PlexusConfigurationMerger
extends java.lang.Object

The ConfigurationMerger will take a Configuration object and layer it over another. It will use special attributes on the layer's children to control how children of the layer and base are combined. In order for a child of the layer to be merged with a child of the base, the following must hold true:

  1. The child in the layer Configuration has an attribute named phoenix-configuration:merge and its value is equal to a boolean TRUE
  2. There must be a single child in both the layer and base with the same getName() OR there exists an attribute named phoenix-configuration:key-attribute that names an attribute that exists on both the layer and base that can be used to match multiple children of the same getName()

Author:
Peter Royal

Constructor Summary
PlexusConfigurationMerger()
           
 
Method Summary
private static void copyAttributes(PlexusConfiguration source, DefaultPlexusConfiguration dest)
           
private static PlexusConfiguration getMergePartner(PlexusConfiguration toMerge, PlexusConfiguration layer, PlexusConfiguration base)
           
private static java.lang.String getValue(PlexusConfiguration layer, PlexusConfiguration base)
           
static PlexusConfiguration[] match(PlexusConfiguration config, java.lang.String element, java.lang.String attribute)
          Return all occurance of a configuration child containing the supplied attribute name.
static PlexusConfiguration[] match(PlexusConfiguration config, java.lang.String element, java.lang.String attribute, java.lang.String value)
          Return occurance of a configuration child containing the supplied attribute name and value.
static PlexusConfiguration merge(PlexusConfiguration layer, PlexusConfiguration base)
          Merge two configurations.
private static void mergeChildren(PlexusConfiguration layer, PlexusConfiguration base, DefaultPlexusConfiguration merged)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PlexusConfigurationMerger

public PlexusConfigurationMerger()
Method Detail

merge

public static PlexusConfiguration merge(PlexusConfiguration layer,
                                        PlexusConfiguration base)
                                 throws PlexusConfigurationException
Merge two configurations.

Parameters:
layer - Configuration to layer over the base
base - Configuration layer will be merged with
Returns:
Result of merge
Throws:
PlexusConfigurationException - if unable to merge

mergeChildren

private static void mergeChildren(PlexusConfiguration layer,
                                  PlexusConfiguration base,
                                  DefaultPlexusConfiguration merged)
                           throws PlexusConfigurationException
Throws:
PlexusConfigurationException

getMergePartner

private static PlexusConfiguration getMergePartner(PlexusConfiguration toMerge,
                                                   PlexusConfiguration layer,
                                                   PlexusConfiguration base)

getValue

private static java.lang.String getValue(PlexusConfiguration layer,
                                         PlexusConfiguration base)

copyAttributes

private static void copyAttributes(PlexusConfiguration source,
                                   DefaultPlexusConfiguration dest)
                            throws PlexusConfigurationException
Throws:
PlexusConfigurationException

match

public static PlexusConfiguration[] match(PlexusConfiguration config,
                                          java.lang.String element,
                                          java.lang.String attribute)
Return all occurance of a configuration child containing the supplied attribute name.

Parameters:
config - the configuration
element - the name of child elements to select from the configuration
attribute - the attribute name to filter (null will match any attribute name)
Returns:
an array of configuration instances matching the query

match

public static PlexusConfiguration[] match(PlexusConfiguration config,
                                          java.lang.String element,
                                          java.lang.String attribute,
                                          java.lang.String value)
Return occurance of a configuration child containing the supplied attribute name and value.

Parameters:
config - the configuration
element - the name of child elements to select from the configuration
attribute - the attribute name to filter (null will match any attribute name )
value - the attribute value to match (null will match any attribute value)
Returns:
an array of configuration instances matching the query