You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by di...@apache.org on 2002/02/02 12:29:42 UTC

cvs commit: jakarta-commons/latka/src/java/org/apache/commons/latka LatkaProperties.java

dion        02/02/02 03:29:41

  Modified:    latka/src/java/org/apache/commons/latka LatkaProperties.java
  Log:
  Fixed missing javadoc, changed system.err usage to log.error
  
  Revision  Changes    Path
  1.9       +103 -100  jakarta-commons/latka/src/java/org/apache/commons/latka/LatkaProperties.java
  
  Index: LatkaProperties.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/LatkaProperties.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- LatkaProperties.java	14 Sep 2001 19:58:51 -0000	1.8
  +++ LatkaProperties.java	2 Feb 2002 11:29:41 -0000	1.9
  @@ -76,134 +76,137 @@
    * object for a Thread to its default values.
    * 
    * @author Morgan Delagrange
  + * @author dIon Gillard (javadoc changes)
    */
   public class LatkaProperties {
   
  -  protected static final Category _log =
  -    Category.getInstance(LatkaProperties.class);
  +    /** log4j category to append output to */
  +    protected static final Category _log =
  +        Category.getInstance(LatkaProperties.class);
   
  -  // default Properties file for Latka
  -  protected static Properties _initProps = loadDefaultProps();
  +    /** default Properties file for Latka */
  +    protected static Properties _initProps = loadDefaultProps();
   
  -  static {
  -    _initProps.putAll(loadUserProps());
  -  }
  -
  -  /**
  -   * This ThreadLocal is automatically instantiated per thread
  -   * with a Properties object containing the default properties.
  -   */
  -  protected static ThreadLocal _propsThreadLocal =
  -    new LatkaThreadLocal(_initProps);
  -
  -  /**
  -   * Returns the unique Properties object for the current
  -   * Thread.  The Properties object is initialized with
  -   * the default Latka Properties.
  -   * 
  -   * @return Latka Properties object 
  -   */
  -  public static Properties getProperties() {
  -    return(Properties) _propsThreadLocal.get();
  -  }
  -
  -  /**
  -   * Resets the Latka properties to their initial value
  -   * (getProperties() will still return the same Object).
  -   * One use for this method is to reset state inside
  -   * a Thread-pooling environment.
  -   */
  -  public static void resetProperties() {
  -    Properties props = (Properties) _propsThreadLocal.get();
  -    props.clear();
  -    props.putAll(_initProps);
  -  }
  -
  -  /**
  -   * Loads the default Properties from the 
  -   * first "latka.properties" file located encountered 
  -   * in the classpath.
  -   * 
  -   * @return A Properties object generated from the contents of the
  -   *         default property file
  -   */
  -  protected static Properties loadDefaultProps() {
  +    static {
  +        _initProps.putAll(loadUserProps());
  +    }
   
  -    Properties properties  = new Properties();
  -    
  -    try {
  -      properties.putAll(loadPropsFromClasspath("latka.properties.internal"));
  -    } catch (IOException e) {
  -      _log.debug(e);
  -      System.out.println("Couldn't find latka.properties.internal file in the classpath");
  +    /**
  +     * This ThreadLocal is automatically instantiated per thread
  +     * with a Properties object containing the default properties.
  +     */
  +    protected static ThreadLocal _propsThreadLocal =
  +        new LatkaThreadLocal(_initProps);
  +
  +    /**
  +     * Returns the unique Properties object for the current
  +     * Thread.  The Properties object is initialized with
  +     * the default Latka Properties.
  +     * 
  +     * @return Latka Properties object 
  +     */
  +    public static Properties getProperties() {
  +        return(Properties) _propsThreadLocal.get();
       }
   
  -    return properties;
  +    /**
  +     * Resets the Latka properties to their initial value
  +     * (getProperties() will still return the same Object).
  +     * One use for this method is to reset state inside
  +     * a Thread-pooling environment.
  +     */
  +    public static void resetProperties() {
  +        Properties props = (Properties) _propsThreadLocal.get();
  +        props.clear();
  +        props.putAll(_initProps);
  +    }
   
  -  }
  +    /**
  +     * Loads the default Properties from the 
  +     * first "latka.properties" file located encountered 
  +     * in the classpath.
  +     * 
  +     * @return A Properties object generated from the contents of the
  +     *         default property file
  +     */
  +    protected static Properties loadDefaultProps() {
   
  -  protected static Properties loadUserProps() {
  +        Properties properties  = new Properties();
  +    
  +        try {
  +            properties.putAll(loadPropsFromClasspath("latka.properties.internal"));
  +        } catch (IOException e) {
  +            _log.error(
  +                "Couldn't find latka.properties.internal file in the classpath",
  +                e);
  +        }
   
  -    Properties properties  = new Properties();
  +        return properties;
   
  -    try {
  -      properties.putAll(loadPropsFromClasspath("latka.properties"));
  -    } catch (IOException e) {
  -      _log.debug(e);
  -      _log.warn("No user-defined latka.properties file in the classpath (optional)");
       }
   
  -    return properties;
  -   
  -  }
  +    protected static Properties loadUserProps() {
   
  -  protected static Properties loadPropsFromClasspath(String classpathLocation) 
  -  throws IOException {
  -    Properties properties  = new Properties();
  -    
  -    ClassLoader loader = Thread.currentThread().getContextClassLoader();
  +        Properties properties  = new Properties();
   
  -    InputStream stream = loader.getResourceAsStream(classpathLocation);
  +        try {
  +            properties.putAll(loadPropsFromClasspath("latka.properties"));
  +        } catch (IOException e) {
  +            _log.debug(e);
  +            _log.warn("No user-defined latka.properties file in the classpath (optional)");
  +        }
   
  -    if (stream == null) {
  -      throw new IOException("Could not find this file in classpath: " + classpathLocation);
  +        return properties;
  +   
       }
   
  -    properties.load(stream);
  +    protected static Properties loadPropsFromClasspath(String classpathLocation) 
  +                                throws IOException {
  +        Properties properties  = new Properties();
  +    
  +        ClassLoader loader = Thread.currentThread().getContextClassLoader();
   
  -    return properties;
  -  }
  +        InputStream stream = loader.getResourceAsStream(classpathLocation);
   
  -  /**
  -   * Custom ThreadLocal class that automatically initialized
  -   * the default Properties for the Thread.
  -   * 
  -   * @author Morgan Delagrange
  -   */
  -  private static class LatkaThreadLocal extends ThreadLocal {
  +        if (stream == null) {
  +            throw new IOException("Could not find this file in classpath: " + classpathLocation);
  +        }
   
  -    protected Properties _initProps = null;
  +        properties.load(stream);
   
  -    /**
  -     * Constructor specifying the default Properties object
  -     * for Latka
  -     * 
  -     * @param initProps default Properties object
  -     */
  -    public LatkaThreadLocal(Properties initProps) {
  -      _initProps = initProps;
  +        return properties;
       }
   
       /**
  -     * Returns a clone of the default Properties file
  -     * for Latka
  +     * Custom ThreadLocal class that automatically initialized
  +     * the default Properties for the Thread.
        * 
  -     * @return Latka Properties file for the current Thread
  +     * @author Morgan Delagrange
        */
  -    protected Object initialValue() {
  -      return _initProps.clone();
  -    }
  +    private static class LatkaThreadLocal extends ThreadLocal {
   
  -  }
  +        protected Properties _initProps = null;
  +
  +        /**
  +         * Constructor specifying the default Properties object
  +         * for Latka
  +         * 
  +         * @param initProps default Properties object
  +         */
  +        public LatkaThreadLocal(Properties initProps) {
  +            _initProps = initProps;
  +        }
  +
  +        /**
  +         * Returns a clone of the default Properties file
  +         * for Latka
  +         * 
  +         * @return Latka Properties file for the current Thread
  +         */
  +        protected Object initialValue() {
  +            return _initProps.clone();
  +        }
  +
  +    }
   
   }
  
  
  

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