akarasulu    2003/11/02 08:59:38

  Added:       merlin/util/defaults .cvsignore project.xml
               merlin/util/defaults/src/java/org/apache/avalon/defaults
                        Defaults.java DefaultsFinder.java
                        EnvDefaultsFinder.java SimpleDefaultsFinder.java
                        SystemDefaultsFinder.java
  Log:
  Moving default property value discovery code to a general util project.
  
  Revision  Changes    Path
  1.1                  avalon/merlin/util/defaults/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  .classpath
  .project
  target
  
  
  
  1.1                  avalon/merlin/util/defaults/project.xml
  
  Index: project.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  
  <project>
  
    <extend>${basedir}/../../project.xml</extend>
  
    <groupId>avalon-util</groupId>
    <id>avalon-util-defaults</id>
    <name>Avalon Property Defaults</name>
    <currentVersion>1.0</currentVersion>
  
    <package>org.apache.avalon.util.defaults</package>
  
    <inceptionYear>2003</inceptionYear>
    <shortDescription>Avalon utilities used to discover property 
defaults.</shortDescription>
  
    <build>
  
      <sourceDirectory>${basedir}/src/java/</sourceDirectory>
      <unitTestSourceDirectory>${basedir}/src/test/</unitTestSourceDirectory>
  
      <unitTest>
        <includes>
          <include>**/*Test.*</include>
          <include>**/*TestCase.*</include>
        </includes>
        <excludes>
          <exclude>**/Abstract*.*</exclude>
        </excludes>
        <resources>
          <resource>
            <directory>${basedir}/src/test</directory>
            <includes>
              <include>**/*.x*</include>
            </includes>
          </resource>
        </resources>
      </unitTest>
  
      <resources>
        <resource>
          <directory>${basedir}/src/java</directory>
          <includes> 
            <include>**/*.properties</include>
          </includes>
        </resource>
        <resource>
          <directory>${basedir}</directory>
          <includes> 
            <include>snapshot.properties</include>
          </includes>
        </resource>
      </resources>
  
      <jars></jars>
  
    </build>
  </project>
  
  
  
  1.1                  
avalon/merlin/util/defaults/src/java/org/apache/avalon/defaults/Defaults.java
  
  Index: Defaults.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
      "Apache Software Foundation"  must not be used to endorse or promote
      products derived  from this  software without  prior written
      permission. For written permission, please contact [EMAIL PROTECTED]
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.avalon.defaults ;
  
  
  import java.util.ArrayList ;
  import java.util.Properties ;
  import java.util.Enumeration ;
  
  
  /**
   * Gets a set of default property values based on a sequence of default value
   * search components or finders.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
   * @author $Author: akarasulu $
   * @version $Revision: 1.1 $
   */
  public class Defaults extends Properties
  {
      /** single-valued property key names */ 
      private final String [] m_singles ;
      /** multi-valued or enumerated property key names */  
      private final String [] m_enumerated ; 
      /** array of finders that define the property default discovery process */
      private final DefaultsFinder [] m_finders ;
      
      
      // ------------------------------------------------------------------------
      // C O N S T R U C T O R S
      // ------------------------------------------------------------------------
  
      
      /**
       * Creates and populates a set of properties
       * 
       * @param a_singles single valued key names
       * @param a_enumerated multi-valued key names
       * @param a_finders search components used for staged discovery of defaults
       */
      public Defaults( String [] a_singles, String [] a_enumerated, 
                       DefaultsFinder [] a_finders )
      {
          m_finders = a_finders ;
          m_singles = a_singles ;
          m_enumerated = a_enumerated ;
          
          for ( int ii = 0; ii < m_finders.length; ii++ )
          {
              m_finders[ii].find( this ) ;
          }
      }
  
      
      // ------------------------------------------------------------------------
      // A C C E S S O R S 
      // ------------------------------------------------------------------------
      
      
      /**
       * Gets the base names of enumerated multi-valued keys.  Such keys are 
       * enumerated to have multiple values by appending an index onto a key base
       * like so: [base.key].1,[base.key].2,[base.key].3 ... [base.key].N.  The
       * returned keys are just the base key names of multi-valued properties and
       * do not include the appended index.
       * 
       * @return the base key names for multi-valued properties
       */
      public String[] getEnumerated()
      {
          return m_enumerated ;
      }
  
      
      /**
       * Gets the linear set of finders composing the search policy.
       * 
       * @return the finders used to discover property defaults
       */
      public DefaultsFinder[] getFinders()
      {
          return m_finders ;
      }
  
  
      /**
       * Gets the names of all the single valued properties. 
       * 
       * @return single valued property key names
       */
      public String[] getSingles()
      {
          return m_singles ;
      }
      
      
      /**
       * Gets the default values for an enumerated key.
       * 
       * @param a_base the base of the enumerated key
       * @return the values of the multi-valued property
       */
      public String[] getEnumerated( String a_base )
      {
          ArrayList l_values = new ArrayList() ;
          Enumeration l_list = keys() ;
  
          while ( l_list.hasMoreElements() )
          {
              String l_key = ( String ) l_list.nextElement() ;
              if ( l_key.startsWith( a_base ) )
              {
                  l_values.add( getProperty( l_key ) ) ;
              }
          }
          return ( String [] ) l_values.toArray( new String [0] ) ;
      }
  
      
      /**
       * Utility method that gets a key's value and returns a boolean value to 
       * represent it.
       * 
       * @param a_key the boolean property key
       * @return true if the property is 1, true, yes or on, and false otherwise 
       */
      public boolean getBoolean( String a_key )
      {
          String l_value = getProperty( a_key ) ;
          l_value = l_value.trim().toLowerCase() ;
          
          if ( l_value.equals( "1" )       ||
               l_value.equals( "on" )      ||
               l_value.equals( "yes" )     ||
               l_value.equals( "true" ) )
          {
              return true ;
          }
          
          return false ;
      }
      
      
      // ------------------------------------------------------------------------
      // S T A T I C   M E T H O D S
      // ------------------------------------------------------------------------
      
      
      /**
       * Merges a set of properties from source Properties into a Defaults 
       * instance.  Does not allow null overrides.
       * 
       * @param a_defaults the defaults to populate on discovery
       * @param a_sources the sources to search
       * @param a_haltOnDiscovery true to halt on first find or false to continue
       * to last find
       */
      public static void discover( Defaults a_defaults, Properties [] a_sources,
                                                                 boolean 
a_haltOnDiscovery )
      {
          if ( null == a_sources || null == a_defaults )
          {
              return ;
          }
          
          /*
           * H A N D L E   S I N G L E   V A L U E D   K E Y S  
           */
          String [] l_keys = a_defaults.getSingles() ;
          for ( int ii = 0; ii < l_keys.length; ii++ )
          {
              String l_key = l_keys[ii] ;
              String l_value = discover( l_key, a_sources, a_haltOnDiscovery ) ;
              
              if ( l_value != null )
              {
                  a_defaults.setProperty( l_key, l_value ) ;
              }
          }
          
          /*
           * H A N D L E   M U L T I - V A L U E D   K E Y S 
           */
          l_keys = a_defaults.getEnumerated() ;
          for ( int ii = 0; ii < l_keys.length; ii++ )
          {
              String l_base = l_keys[ii] ;
              
              for ( int jj = 0; jj < a_sources.length; jj++ )
              {
                  Enumeration l_list = a_sources[jj].propertyNames() ;
                  
                  while ( l_list.hasMoreElements() )
                  {
                      String l_key = ( String ) l_list.nextElement() ;
                      if ( ! l_key.startsWith( l_base ) )
                      {
                          continue ;
                      }
                      
                      String l_value = 
                          discover( l_key, a_sources, a_haltOnDiscovery ) ;
  
                      if ( l_value != null )
                      {
                          a_defaults.setProperty( l_key, l_value ) ;
                      }
                  }
              }
          }
      }
      
      
      /**
       * Discovers a value within a set of Properties either halting on the first
       * time the property is discovered or continuing on to take the last value
       * found for the property key.
       * 
       * @param a_key a property key
       * @param a_sources a set of source Properties
       * @param a_haltOnDiscovery true if we stop on finding a value, false 
       * otherwise
       * @return the value found or null
       */
      public static String discover( String l_key, Properties [] a_sources,
                                                                   boolean 
a_haltOnDiscovery )
      {
          String l_retval = null ;
          
          for( int ii = 0; ii < a_sources.length; ii++ )
          {
              if ( a_sources[ii].containsKey( l_key ) )
              {
                  l_retval = a_sources[ii].getProperty( l_key ) ;
                  
                  if ( a_haltOnDiscovery )
                  {
                      break ;
                  }
              }
          }
          
          return l_retval ;
      }
  
  
      /**
       * Expands out a set of property key macros in the following format 
       * ${foo.bar} where foo.bar is a property key, by dereferencing the value 
       * of the key using the original source Properties and other optional 
       * Properties.
       * 
       * If the original expanded Properties contain the value for the macro key 
       * foo.bar then dereferencing stops by using the value in the expanded 
       * Properties: the other optional Properties are NOT used at all.
       * 
       * If the original expanded Properties do NOT contain the value for the 
       * macro key, then the optional Properties are used in order.  The first of
       * the optionals to contain the value for the macro key (foo.bar) shorts the
       * search.  Hence the first optional Properties in the array to contain a 
       * value for the macro key (foo.bar) is used to set the expanded value.
       * 
       * If a macro cannot be expanded because it's key was not defined within the 
       * expanded Properties or one of the optional Properties then it is left as
       * is.
       * 
       * @param a_expanded the Properties to perform the macro expansion upon
       * @param a_optionals null or an optional set of Properties to use for 
       * dereferencing macro keys (foo.bar)
       */
      public static void macroExpand( Properties a_expanded, 
                                      Properties [] a_optionals )
      {
          // Handle null optionals
          if ( null == a_optionals )
          {
              a_optionals = new Properties [ 0 ] ;
          }
          
          Enumeration l_list = a_expanded.propertyNames() ;
          while ( l_list.hasMoreElements() )
          {
              String l_key = ( String ) l_list.nextElement() ;
              String l_macro = a_expanded.getProperty( l_key ) ;
              
              /*
               * Skip all regular properties that are not macros: used de Morgans
               * to convert ! l_key.startsWith( "${" ) && l_key.endsWith( "}" )
               * to conditional below since it is faster.
               */
              if ( ! l_macro.startsWith( "${" ) || ! l_macro.endsWith( "}" ) )
              {
                  continue ;
              }
              
              /*
               * Check if the macro key exists within the expanded Properties. If
               * so we continue onto the next macro skipping the optional props.
               */
              String l_macroKey = l_macro.substring( 2, l_macro.length() - 1 ) ;
              if ( a_expanded.containsKey( l_macroKey ) )
              {
                  a_expanded.put( l_key, a_expanded.getProperty( l_macroKey ) ) ;
                  continue ;
              }
              
              /*
               * Check if the macro key exists within the array of optional 
               * Properties.  Set expanded value to first Properties with the 
               * key and break out of the loop.
               */
              for ( int ii = 0; ii < a_optionals.length; ii++ )
              {
                  if ( a_optionals[ii].containsKey( l_macroKey ) )
                  {
                      String l_value = a_optionals[ii].getProperty( l_macroKey ) ;
                      a_expanded.put( l_key, l_value ) ;
                      break ;
                  }
              }
          }
      }
  }
  
  
  
  
  
  1.1                  
avalon/merlin/util/defaults/src/java/org/apache/avalon/defaults/DefaultsFinder.java
  
  Index: DefaultsFinder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
      "Apache Software Foundation"  must not be used to endorse or promote
      products derived  from this  software without  prior written
      permission. For written permission, please contact [EMAIL PROTECTED]
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.avalon.defaults ;
  
  
  /**
   * Finds a set of default property values.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
   * @author $Author: akarasulu $
   * @version $Revision: 1.1 $
   */
  public interface DefaultsFinder
  {
     void find( Defaults a_defaults ) ; 
  }
  
  
  
  1.1                  
avalon/merlin/util/defaults/src/java/org/apache/avalon/defaults/EnvDefaultsFinder.java
  
  Index: EnvDefaultsFinder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
      "Apache Software Foundation"  must not be used to endorse or promote
      products derived  from this  software without  prior written
      permission. For written permission, please contact [EMAIL PROTECTED]
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.avalon.defaults ;
  
  
  /**
   * Finds property value defaults within shell environment parameters.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
   * @author $Author: akarasulu $
   * @version $Revision: 1.1 $
   */
  public class EnvDefaultsFinder implements DefaultsFinder
  {
  
      /**
       * Finds property value defaults within shell environment parameters.
       * 
       * @see org.apache.avalon.defaults.DefaultsFinder#find(
       * org.apache.avalon.defaults.Defaults)
       */
      public void find( Defaults a_defaults )
      {
          throw new UnsupportedOperationException( "STUB" ) ;
      }
  }
  
  
  
  1.1                  
avalon/merlin/util/defaults/src/java/org/apache/avalon/defaults/SimpleDefaultsFinder.java
  
  Index: SimpleDefaultsFinder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
      "Apache Software Foundation"  must not be used to endorse or promote
      products derived  from this  software without  prior written
      permission. For written permission, please contact [EMAIL PROTECTED]
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.avalon.defaults ;
  
  
  import java.util.Properties ;
  
  
  /**
   * Attempts to discover defaults using an array of Properties as value sources.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
   * @author $Author: akarasulu $
   * @version $Revision: 1.1 $
   */
  public class SimpleDefaultsFinder implements DefaultsFinder
  {
      /** Properties array to use for discovery */
      private Properties [] m_sources ;
      /** halt on first finding flag */
      private boolean m_haltOnDiscovery = true ;
      
      
      /**
       * Creates a simple defaults filder that searches a set of source Properties
       * for default values.
       * 
       * @param a_sources the source Properties to discover values in
       * @param a_haltOnDiscovery true to halt search when first value is 
       * discovered, false to continue search overriding values until the last 
       * value is discovered.
       */
      public SimpleDefaultsFinder( Properties [] a_sources, 
                                     boolean a_haltOnDiscovery )
      {
          m_sources = a_sources ;
          m_haltOnDiscovery = a_haltOnDiscovery ;
      }
      
      
      /**
       * Applies default discovery using properties in array of properties.
       * 
       * @see org.apache.avalon.defaults.DefaultsFinder#find(
       * org.apache.avalon.defaults.Defaults)
       */
      public void find( Defaults a_defaults )
      {
          Defaults.discover( a_defaults, m_sources, m_haltOnDiscovery ) ;
      }
  }
  
  
  
  1.1                  
avalon/merlin/util/defaults/src/java/org/apache/avalon/defaults/SystemDefaultsFinder.java
  
  Index: SystemDefaultsFinder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
      "Apache Software Foundation"  must not be used to endorse or promote
      products derived  from this  software without  prior written
      permission. For written permission, please contact [EMAIL PROTECTED]
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.avalon.defaults ;
  
  
  import java.util.Properties ;
  
  
  /**
   * Finds default property values within the system properties.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
   * @author $Author: akarasulu $
   * @version $Revision: 1.1 $
   */
  public class SystemDefaultsFinder extends SimpleDefaultsFinder
  {
      /**
       * Finds default property values within the system properties.
       */
      public SystemDefaultsFinder()
      {
          super( new Properties [] { System.getProperties() }, true ) ;
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to