avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pro...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/configuration/src/java/org/apache/excalibur/configuration/merged Constants.java ConfigurationMerger.java NamedConfigurationMatcher.java KeyAttributeConfigurationMatcher.java ConfigurationMatcher.java
Date Fri, 26 Jul 2002 19:17:53 GMT
proyal      2002/07/26 12:17:53

  Modified:    configuration/src/java/org/apache/excalibur/configuration/merged
                        ConfigurationMerger.java
  Added:       configuration/src/java/org/apache/excalibur/configuration/merged
                        Constants.java
  Removed:     configuration/src/java/org/apache/excalibur/configuration/merged
                        NamedConfigurationMatcher.java
                        KeyAttributeConfigurationMatcher.java
                        ConfigurationMatcher.java
  Log:
  * Move constants to separate interface
  * Remove matchers and use ConfigurationUtil.match instead
  * Added ref to ConfigurationSplitter
  
  Revision  Changes    Path
  1.3       +26 -51    jakarta-avalon-excalibur/configuration/src/java/org/apache/excalibur/configuration/merged/ConfigurationMerger.java
  
  Index: ConfigurationMerger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/configuration/src/java/org/apache/excalibur/configuration/merged/ConfigurationMerger.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ConfigurationMerger.java	23 Jul 2002 20:49:12 -0000	1.2
  +++ ConfigurationMerger.java	26 Jul 2002 19:17:53 -0000	1.3
  @@ -13,6 +13,7 @@
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
   import org.apache.avalon.framework.configuration.DefaultConfiguration;
  +import org.apache.excalibur.configuration.ConfigurationUtil;
   
   /**
    * The ConfigurationMerger will take a Configuration object and layer it over another.
  @@ -32,15 +33,11 @@
    *   </li>
    * </ol>
    *
  + * @see ConfigurationSplitter
    * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
    */
   public class ConfigurationMerger
   {
  -    private static final String MERGE_METADATA_PREFIX = "excalibur-configuration:";
  -
  -    private static final String MERGE_ATTR = MERGE_METADATA_PREFIX + "merge";
  -    private static final String KEY_ATTR = MERGE_METADATA_PREFIX + "key-attribute";
  -
       /**
        * Merge two configurations.
        *
  @@ -49,7 +46,7 @@
        *
        * @return Result of merge
        *
  -     * @exception ConfigurationException if
  +     * @exception ConfigurationException if unable to merge
        */
       public static Configuration merge( final Configuration layer, final Configuration base
)
           throws ConfigurationException
  @@ -81,8 +78,7 @@
   
           for( int i = 0; i < lc.length; i++ )
           {
  -            final String name = lc[i].getName();
  -            final Configuration mergeWith = getMergePartner( lc[i], lc, bc );
  +            final Configuration mergeWith = getMergePartner( lc[i], layer, base );
   
               if( null == mergeWith )
               {
  @@ -106,60 +102,39 @@
       }
   
       private static Configuration getMergePartner( final Configuration toMerge,
  -                                                  final Configuration[] layerKids,
  -                                                  final Configuration[] baseKids )
  +                                                  final Configuration layer,
  +                                                  final Configuration base )
           throws ConfigurationException
       {
  -        if( toMerge.getAttributeAsBoolean( MERGE_ATTR, false ) )
  +        if( toMerge.getAttributeAsBoolean( Constants.MERGE_ATTR, false ) )
           {
  -            final String keyAttribute = toMerge.getAttribute( KEY_ATTR, null );
  -            ConfigurationMatcher matcher;
  +            final String keyAttribute = toMerge.getAttribute( Constants.KEY_ATTR, null
);
  +            final String keyvalue =
  +                keyAttribute == null ? null : toMerge.getAttribute( keyAttribute );
   
  -            if( null == keyAttribute )
  -            {
  -                matcher = new NamedConfigurationMatcher( toMerge.getName() );
  -            }
  -            else
  -            {
  -                matcher
  -                    = new KeyAttributeConfigurationMatcher( toMerge.getName(),
  -                                                            keyAttribute,
  -                                                            toMerge.getAttribute( keyAttribute
) );
  -            }
  +            final Configuration[] layerKids = ConfigurationUtil.match( layer,
  +                                                                       toMerge.getName(),
  +                                                                       keyAttribute,
  +                                                                       keyvalue );
   
  -            final int layerMatch = getMatchingConfiguration( matcher, layerKids );
  -            final int baseMatch = getMatchingConfiguration( matcher, baseKids );
  +            final Configuration[] baseKids = ConfigurationUtil.match( base,
  +                                                                      toMerge.getName(),
  +                                                                      keyAttribute,
  +                                                                      keyvalue );
   
  -            if( layerMatch >= 0 && baseMatch >= 0 )
  +            if( layerKids.length == 1 && baseKids.length == 1 )
               {
  -                return baseKids[baseMatch];
  +                return baseKids[0];
               }
  -        }
  -
  -        return null;
  -    }
  -
  -    private static int getMatchingConfiguration( ConfigurationMatcher matcher,
  -                                                 Configuration list[] )
  -    {
  -        int match = -1;
  -
  -        for( int i = 0; i < list.length; i++ )
  -        {
  -            if( matcher.isMatch( list[i] ) )
  +            else
               {
  -                if( match >= 0 )
  -                {
  -                    return -1;
  -                }
  -                else
  -                {
  -                    match = i;
  -                }
  +                throw new ConfigurationException( "Unable to merge configuration item,
"
  +                                                  + "multiple matches on child or base
[name: "
  +                                                  + toMerge.getName() + "]" );
               }
           }
   
  -        return match;
  +        return null;
       }
   
       private static String getValue( final Configuration layer, final Configuration base
)
  @@ -182,7 +157,7 @@
   
           for( int i = 0; i < names.length; i++ )
           {
  -            if( !names[i].startsWith( MERGE_METADATA_PREFIX ) )
  +            if( !names[i].startsWith( Constants.MERGE_METADATA_PREFIX ) )
               {
                   dest.setAttribute( names[i], source.getAttribute( names[i] ) );
               }
  
  
  
  1.1                  jakarta-avalon-excalibur/configuration/src/java/org/apache/excalibur/configuration/merged/Constants.java
  
  Index: Constants.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.excalibur.configuration.merged;
  
  /**
   * Constants used by this package
   *
   * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
   */
  interface Constants
  {
      String MERGE_METADATA_PREFIX = "excalibur-configuration:";
      String MERGE_ATTR = MERGE_METADATA_PREFIX + "merge";
      String KEY_ATTR = MERGE_METADATA_PREFIX + "key-attribute";
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message