commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@apache.org
Subject cvs commit: jakarta-commons-sandbox/resources/src/test/org/apache/commons/resources/tests FileResourcesExposerFactory.java
Date Fri, 27 Dec 2002 23:27:13 GMT
craigmcc    2002/12/27 15:27:12

  Modified:    resources/src/java/org/apache/commons/resources
                        ResourcesFactory.java XMLConfigurationReader.java
               resources/src/java/org/apache/commons/resources/file
                        FileResourcesFactory.java
               resources/src/java/org/apache/commons/resources/file/web
                        WebappFileResourcesFactory.java
               resources/src/java/org/apache/commons/resources/message
                        MessageResourcesFactory.java
                        PropertyMessageResourcesFactory.java
               resources/src/test/org/apache/commons/resources/tests
                        FileResourcesExposerFactory.java
  Log:
  Clean up ResourcesFactory, including converting it from an abstract class
  to an interface.  More work is definitely needed on the implementations,
  but that will occur as part of some refactoring.
  
  Revision  Changes    Path
  1.2       +43 -19    jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/ResourcesFactory.java
  
  Index: ResourcesFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/ResourcesFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ResourcesFactory.java	24 Oct 2001 19:35:55 -0000	1.1
  +++ ResourcesFactory.java	27 Dec 2002 23:27:12 -0000	1.2
  @@ -7,7 +7,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -62,27 +62,51 @@
   
   package org.apache.commons.resources;
   
  +
   import java.io.Serializable;
   
  +
   /**
  - * This class represents a basic factory pattern class for creating resources.
  - * When creating a resource, you must also create a Factory class to go with it.
  - * The factory class is what's defined in resources-config.xml, not the resource
  - * itself.<br />
  - * When developing an sub-class of a ResourcesFactory, keep in mind that in
  - * all likelyhood it will be instantiated using Class.forName(), so all
  - * initialization should go in a no-argument constructor.
  + * <a>A {@link ResourcesFactory} is a factory pattern interface for a
  + * class that can create {@link Resources} instances based on a logical
  + * name that is passed to the factory.  Repeated requests to return a
  + * {@link Resources} instance with the same name should return the same
  + * {@link Resources} instance each time.</p>
  + *
  + * <p>Implementations of {@link ResourcesFactory} <strong>MUST</strong>
  + * include a zero-arguments constructor so that instances of the factory
  + * can be dynamically created.  Therefore, configuration information
  + * above and beyond the configuration String will generally be specified
  + * via JavaBeans property setters o the {@link ResourcesFactory}
  + * implementation class.</p>
  + *
    * @author Mike Schachter (mschachter@hp.com)
  + * @author Craig R. McClanahan
    * @version $Revision$ $Date$
    */
  -public abstract class ResourcesFactory implements Serializable {
  +
  +public interface ResourcesFactory extends Serializable {
       
  +
       /**
  -     * Basic factory method, subclasses will create a resource based on
  -     * the value of config
  -     * @param config A String representing how the resource will configure
  -     *               itself, whether it be a file path, a URL, or a long
  -     *               name-value pair String
  +     * <p>Create (if necessary) and return a {@link Resources} instance
  +     * for the specified logical name.</p>
  +     *
  +     * @param name Logical name of the {@link Resources} instance to
  +     *  be returned
  +     *
  +     * @exception ResourcesException if a {@link Resources} instance
  +     *  of the specified logical name cannot be returned.
        */
  -    public abstract Resources createResource(String config);
  +    public Resources getResources(String name)
  +        throws ResourcesException;
  +
  +
  +    /**
  +     * <p>Release any internal references to {@link Resources} instances
  +     * that have been returned previously.</p>
  +     */
  +    public void release();
  +
  +
   }
  
  
  
  1.8       +5 -5      jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/XMLConfigurationReader.java
  
  Index: XMLConfigurationReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/XMLConfigurationReader.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XMLConfigurationReader.java	27 Dec 2002 21:15:18 -0000	1.7
  +++ XMLConfigurationReader.java	27 Dec 2002 23:27:12 -0000	1.8
  @@ -262,7 +262,7 @@
               Class clazz = loader.loadClass(factoryClass);
               if ((ResourcesFactory.class).isAssignableFrom(clazz)) {
                   factory = (ResourcesFactory) clazz.newInstance();
  -                resource = factory.createResource(config);
  +                resource = factory.getResources(config);
               }
               else {
                   throw new ResourcesException(
  
  
  
  1.2       +8 -6      jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/file/FileResourcesFactory.java
  
  Index: FileResourcesFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/file/FileResourcesFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FileResourcesFactory.java	24 Oct 2001 19:35:55 -0000	1.1
  +++ FileResourcesFactory.java	27 Dec 2002 23:27:12 -0000	1.2
  @@ -71,8 +71,10 @@
    * @author Mike Schachter (mschachter@hp.com)
    * @version $Revision$ $Date$
    */
  -public class FileResourcesFactory extends ResourcesFactory {
  -    public Resources createResource(String config) {
  +public class FileResourcesFactory implements ResourcesFactory {
  +    public Resources getResources(String config) {
           return new FileResources();
  +    }
  +    public void release() {
       }
   }
  
  
  
  1.2       +9 -6      jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/file/web/WebappFileResourcesFactory.java
  
  Index: WebappFileResourcesFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/file/web/WebappFileResourcesFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WebappFileResourcesFactory.java	25 Oct 2001 19:33:22 -0000	1.1
  +++ WebappFileResourcesFactory.java	27 Dec 2002 23:27:12 -0000	1.2
  @@ -68,12 +68,15 @@
    * @author Mike Schachter (mschachter@hp.com)
    * @version $Revision$ $Date$
    */
  -public class WebappFileResourcesFactory extends ResourcesFactory {
  +public class WebappFileResourcesFactory implements ResourcesFactory {
   
       /**
        * Basic implementation, just creates a new instance of WebappFileResources.
        */
  -    public Resources createResource(String config) {
  +    public Resources getResources(String config) {
           return new WebappFileResources();
       }
  +    public void release() {
  +    }
  +
   }
  
  
  
  1.4       +9 -7      jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/message/MessageResourcesFactory.java
  
  Index: MessageResourcesFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/message/MessageResourcesFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MessageResourcesFactory.java	24 Oct 2001 19:35:56 -0000	1.3
  +++ MessageResourcesFactory.java	27 Dec 2002 23:27:12 -0000	1.4
  @@ -86,8 +86,7 @@
    */
   
   public abstract class MessageResourcesFactory
  -    extends ResourcesFactory
  -    implements Serializable {
  +    implements ResourcesFactory, Serializable {
   
   
       // ---------------------------------------------------- Instance Properties
  @@ -122,10 +121,13 @@
       /**
        * Implementation of ResourcesFactory method
        */
  -    public Resources createResource(String config) {
  +    public Resources getResources(String config) {
           return createResources(config);
       }       
   
  +
  +    public void release() {
  +    }
   
       // ------------------------------------------------------ Static Properties
   
  
  
  
  1.2       +13 -5     jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/message/PropertyMessageResourcesFactory.java
  
  Index: PropertyMessageResourcesFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/resources/src/java/org/apache/commons/resources/message/PropertyMessageResourcesFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PropertyMessageResourcesFactory.java	27 Jun 2001 22:07:24 -0000	1.1
  +++ PropertyMessageResourcesFactory.java	27 Dec 2002 23:27:12 -0000	1.2
  @@ -63,6 +63,9 @@
   package org.apache.commons.resources.message;
   
   
  +import org.apache.commons.resources.Resources;
  +
  +
   /**
    * Factory for <code>PropertyMessageResources</code> instances.  The
    * configuration paramter for such instances is the base Java package
  @@ -79,13 +82,18 @@
       // --------------------------------------------------------- Public Methods
   
   
  +    public MessageResources createResources(String config) {
  +        return ((MessageResources) getResources(config));
  +    }
  +
  +
       /**
        * Create and return a newly instansiated <code>MessageResources</code>.
        * This method must be implemented by concrete subclasses.
        *
        * @param config Configuration parameter(s) for the requested bundle
        */
  -    public MessageResources createResources(String config) {
  +    public Resources getResources(String config) {
   
           return new PropertyMessageResources(this, config, this.returnNull);
   
  
  
  
  1.2       +6 -2      jakarta-commons-sandbox/resources/src/test/org/apache/commons/resources/tests/FileResourcesExposerFactory.java
  
  Index: FileResourcesExposerFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/resources/src/test/org/apache/commons/resources/tests/FileResourcesExposerFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FileResourcesExposerFactory.java	24 Oct 2001 19:35:56 -0000	1.1
  +++ FileResourcesExposerFactory.java	27 Dec 2002 23:27:12 -0000	1.2
  @@ -7,11 +7,15 @@
    * This class creates FileResourcesExposer resources, which expose
    * the protected methods of the FileResources class for testing
    */
  -public class FileResourcesExposerFactory extends ResourcesFactory {
  +public class FileResourcesExposerFactory implements ResourcesFactory {
       
    
  -    public Resources createResource(String config) {
  +    public Resources getResources(String config) {
           return new FileResourcesExposer();
       }
  +
  +    public void release() {
  +    }
  +
       
   }
  
  
  

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


Mime
View raw message