You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by mp...@apache.org on 2002/03/13 20:04:23 UTC

cvs commit: jakarta-turbine-stratum/src/java/org/apache/stratum/configuration ConfigurationConverter.java

mpoeschl    02/03/13 11:04:23

  Modified:    src/java/org/apache/stratum/configuration
                        ConfigurationConverter.java
  Log:
  add a converter for standard Properties
  add javadocs
  
  Revision  Changes    Path
  1.2       +36 -8     jakarta-turbine-stratum/src/java/org/apache/stratum/configuration/ConfigurationConverter.java
  
  Index: ConfigurationConverter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/configuration/ConfigurationConverter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConfigurationConverter.java	6 Feb 2002 14:59:37 -0000	1.1
  +++ ConfigurationConverter.java	13 Mar 2002 19:04:23 -0000	1.2
  @@ -54,42 +54,70 @@
    * <http://www.apache.org/>.
    */
   
  +import java.util.Enumeration;
   import java.util.Iterator;
  +import java.util.Properties;
   import org.apache.commons.collections.ExtendedProperties;
   
   
   /**
  - * Configuration <-> ExtendedProperties converter
  + * Configuration converter. <br>
  + * Helper class to convert between Configuration, ExtendedProperties and
  + * standard Properties.
    *
    * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
  - * @version $Id: ConfigurationConverter.java,v 1.1 2002/02/06 14:59:37 mpoeschl Exp $
  + * @version $Id: ConfigurationConverter.java,v 1.2 2002/03/13 19:04:23 mpoeschl Exp $
    */
   public class ConfigurationConverter
   {
  +    /**
  +     * Convert a ExtendedProperties class into a Configuration class.
  +     *
  +     * @param ep ExtendedProperties object to convert
  +     * @return Configuration created from the ExtendedProperties
  +     */
       public static Configuration getConfiguration(ExtendedProperties ep)
       {
           Configuration config = (Configuration) new BaseConfiguration();
  -
           for (Iterator i = ep.getKeys() ; i.hasNext() ;)
           {
               String key = (String) i.next();
  -            config.setProperty( key, ep.getProperty(key) );
  +            config.setProperty(key, ep.getProperty(key));
           }
  +        return config;
  +    }
   
  +    /**
  +     * Convert a standard properties class into a configuration class.
  +     *
  +     * @param p properties object to convert
  +     * @return Configuration configuration created from the Properties
  +     */
  +    public static Configuration getConfiguration(Properties p)
  +    {
  +        Configuration config = (Configuration) new BaseConfiguration();
  +        for (Enumeration e = p.keys(); e.hasMoreElements() ; )
  +        {
  +            String key = (String) e.nextElement();
  +            config.setProperty(key, p.getProperty(key));
  +        }
           return config;
       }
   
  +    /**
  +     * Convert a Configuration class into a ExtendedProperties class.
  +     *
  +     * @param c Configuration object to convert
  +     * @return ExtendedProperties created from the Configuration
  +     */
       public static ExtendedProperties getExtendedProperties(Configuration c)
       {
           ExtendedProperties props = new ExtendedProperties();
  -
           for (Iterator i = c.getKeys() ; i.hasNext() ;)
           {
               String key = (String) i.next();
  -            props.setProperty( key, c.getProperty(key) );
  +            props.setProperty(key, c.getProperty(key));
           }
  -
           return props;
       }
  -
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>