avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/all/src/scratchpad/org/apache/avalon/excalibur/configuration CascadingConfiguration.java
Date Fri, 03 May 2002 03:19:27 GMT
mcconnell    02/05/02 20:19:27

  Modified:    all/src/scratchpad/org/apache/avalon/excalibur/configuration
                        CascadingConfiguration.java
  Log:
  update to include static utility operation to list configuration
  
  Revision  Changes    Path
  1.4       +94 -33    jakarta-avalon-excalibur/all/src/scratchpad/org/apache/avalon/excalibur/configuration/CascadingConfiguration.java
  
  Index: CascadingConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/all/src/scratchpad/org/apache/avalon/excalibur/configuration/CascadingConfiguration.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- CascadingConfiguration.java	21 Apr 2002 21:48:23 -0000	1.3
  +++ CascadingConfiguration.java	3 May 2002 03:19:27 -0000	1.4
  @@ -1,8 +1,11 @@
  -/**
  - * File: CascadingConfiguration.java
  - * License: etc/LICENSE.TXT
  - * Copyright: Copyright (C) The Apache Software Foundation. All rights reserved.
  - * Copyright: OSM SARL 2001-2002, All Rights Reserved.
  +/*
  + * 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.
  + *
  + * Original contribution by OSM SARL, http://www.osm.net
    */
   
   package org.apache.avalon.excalibur.configuration;
  @@ -12,7 +15,7 @@
   import org.apache.avalon.framework.configuration.DefaultConfiguration;
   
   /**
  - * The CascadingConfiguration is a classic Configuration backed by parent
  + * The CascadingConfiguration is a classic Configuration backed by parent 
    * Configuration.  Operations such as getChild return a CascadingConfiguration
    * encapsulating both a primary and parent configuration.  Requests for attribute
    * values are resolved against the base configuration initially.  If the result
  @@ -36,19 +39,19 @@
   
       /**
        * Create a CascadingConfiguration with specified parent.  The base
  -     * configuration shall override a parent configuration on request for
  +     * configuration shall override a parent configuration on request for 
        * attribute values and configuration body values.  Unresolved request
        * are redirected up the parent chain until a classic configuration is
  -     * reached.  Request for child configurations will return a
  -     * new CascadingConfiguration referencing the child of the base and
  +     * reached.  Request for child configurations will return a 
  +     * new CascadingConfiguration referencing the child of the base and 
        * the child of the primary (i.e. a child configuration chain).
        *
        * @param base the base Configuration
  -     * @param parent the parent Configuration
  +     * @param parent the parent Configuration 
        */
  -    public CascadingConfiguration( final Configuration base, final Configuration parent
)
  +    public CascadingConfiguration( final Configuration base , final Configuration parent
)
       {
  -        if( base == null )
  +        if( base == null ) 
           {
               m_base = new DefaultConfiguration( "-", null );
           }
  @@ -56,7 +59,7 @@
           {
               m_base = base;
           }
  -        if( parent == null )
  +        if( parent == null ) 
           {
               m_parent = new DefaultConfiguration( "-", null );
           }
  @@ -121,8 +124,8 @@
        * @param child The name of the child node.
        * @param createNew If <code>true</code>, a new <code>Configuration</code>
        * will be created and returned if the specified child does not exist in either
  -     * the base or parent configuratioin. If <code>false</code>, <code>null</code>
  -     * will be returned when the specified child doesn't exist in either the base or
  +     * the base or parent configuratioin. If <code>false</code>, <code>null</code>

  +     * will be returned when the specified child doesn't exist in either the base or 
        * the parent.
        * @return Configuration
        */
  @@ -136,27 +139,27 @@
   
       /**
        * Return an <code>Array</code> of <code>Configuration</code>
  -     * elements containing all node children of both base and parent configurations.
  +     * elements containing all node children of both base and parent configurations. 
        * The array order will reflect the order in the source config file, commencing
        * with the base configuration.
        *
  -     * @return All child nodes
  +     * @return All child nodes 
        */
       public Configuration[] getChildren()
       {
  -        Configuration[] b = m_base.getChildren();
  -        Configuration[] p = m_parent.getChildren();
  +        Configuration[] b = m_base.getChildren( );
  +        Configuration[] p = m_parent.getChildren( );
           Configuration[] result = new Configuration[ b.length + p.length ];
  -        System.arraycopy( b, 0, result, 0, b.length );
  -        System.arraycopy( p, 0, result, b.length, p.length );
  +        System.arraycopy(b, 0, result, 0, b.length );
  +        System.arraycopy(p, 0, result, b.length, p.length );
           return result;
       }
   
       /**
        * Return an <code>Array</code> of <code>Configuration</code>
  -     * elements containing all node children with the specified name from
  +     * elements containing all node children with the specified name from 
        * both base and parent configurations. The array
  -     * order will reflect the order in the source config file commencing
  +     * order will reflect the order in the source config file commencing 
        * with the base configuration.
        *
        * @param name The name of the children to get.
  @@ -167,8 +170,8 @@
           Configuration[] b = m_base.getChildren( name );
           Configuration[] p = m_parent.getChildren( name );
           Configuration[] result = new Configuration[ b.length + p.length ];
  -        System.arraycopy( b, 0, result, 0, b.length );
  -        System.arraycopy( p, 0, result, b.length, p.length );
  +        System.arraycopy(b, 0, result, 0, b.length );
  +        System.arraycopy(p, 0, result, b.length, p.length );
           return result;
       }
   
  @@ -187,20 +190,20 @@
           java.util.Vector vector = new java.util.Vector();
           String[] names = m_base.getAttributeNames();
           String[] names2 = m_parent.getAttributeNames();
  -        for( int i = 0; i < names.length; i++ )
  +        for( int i=0; i<names.length; i++ )
           {
  -            vector.add( names[ i ] );
  +            vector.add( names[i] );
           }
  -        for( int i = 0; i < names2.length; i++ )
  +        for( int i=0; i<names2.length; i++ )
           {
  -            if( vector.indexOf( names2[ i ] ) < 0 ) vector.add( names2[ i ] );
  +            if( vector.indexOf( names2[i] ) < 0 ) vector.add( names2[i] );
           }
  -        return (String[])vector.toArray( new String[ 0 ] );
  +        return (String[]) vector.toArray( new String[0] );
       }
   
       /**
        * Return the value of specified attribute.  If the base configuration
  -     * does not contain the attribute, the equivialent operation is applied to
  +     * does not contain the attribute, the equivialent operation is applied to 
        * the parent configuration.
        *
        * @param paramName The name of the parameter you ask the value of.
  @@ -243,7 +246,7 @@
        * Returns the value of the attribute specified by its name as a
        * <code>long</code>.
        *
  -     * @param name The name of the parameter you ask the value of.
  +     * @param paramName The name of the parameter you ask the value of.
        * @return long value of attribute
        * @exception ConfigurationException If no parameter with that name exists.
        *                                   or if conversion to <code>long</code>
fails.
  @@ -260,6 +263,7 @@
           }
       }
   
  +
       /**
        * Return the <code>float</code> value of the specified parameter contained
        * in this node.
  @@ -280,6 +284,7 @@
           }
       }
   
  +
       /**
        * Return the <code>boolean</code> value of the specified parameter contained
        * in this node.<br>
  @@ -318,6 +323,7 @@
           }
       }
   
  +
       /**
        * Return the <code>int</code> value of the node.
        *
  @@ -410,6 +416,7 @@
           }
       }
   
  +
       /**
        * Returns the value of the configuration element as an <code>int</code>.
        * If the configuration value is not set, the default value will be
  @@ -431,6 +438,7 @@
           }
       }
   
  +
       /**
        * Returns the value of the configuration element as a <code>long</code>.
        * If the configuration value is not set, the default value will be
  @@ -452,6 +460,7 @@
           }
       }
   
  +
       /**
        * Returns the value of the configuration element as a <code>float</code>.
        * If the configuration value is not set, the default value will be
  @@ -473,6 +482,7 @@
           }
       }
   
  +
       /**
        * Returns the value of the configuration element as a <code>boolean</code>.
        * If the configuration value is not set, the default value will be
  @@ -494,6 +504,7 @@
           }
       }
   
  +
       /**
        * Returns the value of the attribute specified by its name as a
        * <code>String</code>, or the default value if no attribute by
  @@ -608,4 +619,54 @@
               return m_parent.getAttributeAsBoolean( name, defaultValue );
           }
       }
  -}
  \ No newline at end of file
  +
  +    //=======================================================================
  +    // utilities
  +    //=======================================================================
  +
  +    public static String list( Configuration config )
  +    {
  +        final StringBuffer buffer = new StringBuffer();
  +        list( buffer, "  ", config );
  +        buffer.append("\n");
  +        return buffer.toString(); 
  +    }
  +
  +    private static void list( StringBuffer buffer, String lead, Configuration config )
  +    {
  +
  +        buffer.append( "\n" + lead + "<" + config.getName() );
  +        String[] names = config.getAttributeNames();
  +        if( names.length > 0 )
  +        {
  +            for( int i=0; i<names.length; i++ )
  +            {
  +                buffer.append( " " + names[i] + "=\"" + config.getAttribute( names[i],
"???" ) + "\"" ); 
  +            }
  +        }
  +        Configuration[] children = config.getChildren();
  +        if( children.length > 0 )
  +        {
  +            buffer.append(">");
  +            for( int j=0; j<children.length; j++ )
  +            {
  +                 list( buffer, lead + "  ", children[j] ); 
  +            }
  +            buffer.append( "\n" + lead + "</" + config.getName() + ">");
  +        }
  +        else
  +        {
  +            if( config.getValue( null ) != null )
  +            {
  +                buffer.append( ">...</" + config.getName() + ">");
  +            }
  +            else
  +            {
  +                buffer.append( "/>");
  +            }
  +        }
  +    }
  +}
  +
  +
  +
  
  
  

--
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