You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by cz...@apache.org on 2002/04/17 15:38:48 UTC

cvs commit: jakarta-avalon-excalibur/all/src/scratchpad/org/apache/avalon/excalibur/source ResourceSource.java Source.java URLSource.java ModifiableSource.java

cziegeler    02/04/17 06:38:48

  Modified:    all/src/scratchpad/org/apache/avalon/excalibur/monitor
                        SourceResource.java
               all/src/scratchpad/org/apache/avalon/excalibur/source
                        ResourceSource.java Source.java URLSource.java
  Removed:     all/src/scratchpad/org/apache/avalon/excalibur/source
                        ModifiableSource.java
  Log:
  Unifying Source, ModifiableSource and XMLizable as discussed
  
  Revision  Changes    Path
  1.4       +3 -17     jakarta-avalon-excalibur/all/src/scratchpad/org/apache/avalon/excalibur/monitor/SourceResource.java
  
  Index: SourceResource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/all/src/scratchpad/org/apache/avalon/excalibur/monitor/SourceResource.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SourceResource.java	16 Mar 2002 00:05:48 -0000	1.3
  +++ SourceResource.java	17 Apr 2002 13:38:48 -0000	1.4
  @@ -13,21 +13,18 @@
   import java.io.OutputStream;
   import java.io.Reader;
   import java.io.Writer;
  -import org.apache.avalon.excalibur.source.ModifiableSource;
   import org.apache.avalon.excalibur.source.Source;
   import org.apache.avalon.excalibur.source.SourceValidity;
   
   /**
    *
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  - * @version $Id: SourceResource.java,v 1.3 2002/03/16 00:05:48 donaldp Exp $
  + * @version $Id: SourceResource.java,v 1.4 2002/04/17 13:38:48 cziegeler Exp $
    */
   public final class SourceResource extends StreamResource
   {
       /** The wrapped source object */
       private final Source source;
  -    /** Is this a modifiable source? */
  -    private final boolean isModifiableSource;
   
       /** The last validity object */
       private SourceValidity validity;
  @@ -42,15 +39,7 @@
   
           this.source = source;
           m_previousModified = System.currentTimeMillis();
  -        if( source instanceof ModifiableSource )
  -        {
  -            this.isModifiableSource = true;
  -            this.validity = ( (ModifiableSource)source ).getValidity();
  -        }
  -        else
  -        {
  -            this.isModifiableSource = false;
  -        }
  +        this.validity = source.getValidity();
       }
   
       /**
  @@ -58,16 +47,13 @@
        */
       public long lastModified()
       {
  -        if( !this.isModifiableSource )
  -            return 1;
  -
           if( this.validity == null )
           {
               return System.currentTimeMillis();
           }
           else
           {
  -            SourceValidity newVal = ( (ModifiableSource)this.source ).getValidity();
  +            SourceValidity newVal = this.source.getValidity();
               if( newVal != null && this.validity.isValid( newVal ) == true )
               {
                   return m_previousModified;
  
  
  
  1.4       +23 -3     jakarta-avalon-excalibur/all/src/scratchpad/org/apache/avalon/excalibur/source/ResourceSource.java
  
  Index: ResourceSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/all/src/scratchpad/org/apache/avalon/excalibur/source/ResourceSource.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ResourceSource.java	16 Mar 2002 00:05:49 -0000	1.3
  +++ ResourceSource.java	17 Apr 2002 13:38:48 -0000	1.4
  @@ -10,7 +10,6 @@
   import java.io.IOException;
   import java.io.InputStream;
   import org.apache.avalon.excalibur.xml.Parser;
  -import org.apache.avalon.excalibur.xml.XMLizable;
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.component.Composable;
   import org.xml.sax.ContentHandler;
  @@ -21,11 +20,11 @@
    * which gets a resource from the classloader.
    *
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  - * @version CVS $Revision: 1.3 $ $Date: 2002/03/16 00:05:49 $
  + * @version CVS $Revision: 1.4 $ $Date: 2002/04/17 13:38:48 $
    */
   
   public final class ResourceSource
  -    implements Composable, Source, XMLizable
  +    implements Composable, Source
   {
       /** The system identifier */
       private String systemId;
  @@ -104,6 +103,27 @@
       public String getSystemId()
       {
           return this.systemId;
  +    }
  +
  +    /**
  +     *  Get the Validity object. This can either wrap the last modification
  +     *  date or the expires information or...
  +     *  If it is currently not possible to calculate such an information
  +     *  <code>null</code> is returned.
  +     */
  +    public SourceValidity getValidity()
  +    {
  +        // we are always valid
  +        return org.apache.avalon.excalibur.source.validity.NOPValidity.SHARED_INSTANCE;
  +    }
  +
  +    /**
  +     * Refresh this object and update the last modified date
  +     * and content length.
  +     */
  +    public void discardValidity()
  +    {
  +        // nothing to do
       }
   
   }
  
  
  
  1.12      +47 -6     jakarta-avalon-excalibur/all/src/scratchpad/org/apache/avalon/excalibur/source/Source.java
  
  Index: Source.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/all/src/scratchpad/org/apache/avalon/excalibur/source/Source.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Source.java	16 Mar 2002 00:05:49 -0000	1.11
  +++ Source.java	17 Apr 2002 13:38:48 -0000	1.12
  @@ -7,15 +7,13 @@
    */
   package org.apache.avalon.excalibur.source;
   
  +import org.apache.avalon.excalibur.xml.XMLizable;
   import java.io.IOException;
   import java.io.InputStream;
   
   /**
    * Description of a source. This interface provides a simple interface
  - * for accessing a source of data. The source of data is assumed to
  - * <b>not change</b> during the lifetime of the Source object. If you
  - * have a data source that can change its content and you want it to
  - * reflect it, use a {@link ModifiableSource} object instead.
  + * for accessing a source of data.
    *
    * When the <code>Source</code> object is no longer needed
    * it must be released using the resolver. This is very similar like
  @@ -23,12 +21,41 @@
    * In fact a source object can implement most lifecycle interfaces
    * like Composable, Initializable, Disposable etc.
    *
  + * Thee data content can be constant or change over time.
  + * Using the getInputStream() method you get always the upto-date content.
  + * When you're done with using the source object, you have to release it.
  + * If you want to track changes of the source object, this interface
  + * offers you some support for it by providing a SourceValidity object.
  + *
  + * How does the caching work?
  + * The first time you get a Source object, you simply ask
  + * it for it's content via getInputStream() and then get the validity
  + * object by invoking getValidity. (Further calls to getValidity always
  + * return the same object! This is not updated!)
  + * The caching algorithm can now store this validity object together
  + * with the system identifier of the source.
  + * The next time, the caching algorithm wants to check if the cached
  + * content is still valid. It has a validity object already to check
  + * against.
  + *
  + * If it is still the same Source than the first time, you
  + * have to call discardValidity() in order to discard the stored validity
  + * in the Source object. If it is a new Source object,
  + * calling discardValidity() should do no harm.
  + * After that an upto-date validity object can retrieved by calling
  + * getValidity(). This can be used to test if the content is still valid
  + * as discribed in the source validity documentation.
  + * If the content is still valid, the cache knows what to do, if not,
  + * the new content can be get using getInputStream().
  + * So either after a call to getValidity() or the getInputStream the
  + * validity object must be the same until discardValidity is called!
  + *
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
    * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
  - * @version CVS $Revision: 1.11 $ $Date: 2002/03/16 00:05:49 $
  + * @version CVS $Revision: 1.12 $ $Date: 2002/04/17 13:38:48 $
    */
   public interface Source
  -{
  +  extends XMLizable {
   
       /**
        * Return an <code>InputStream</code> object to read from the source.
  @@ -43,5 +70,19 @@
        * Return the unique identifer for this source
        */
       String getSystemId();
  +
  +    /**
  +     *  Get the Validity object. This can either wrap the last modification
  +     *  date or the expires information or...
  +     *  If it is currently not possible to calculate such an information
  +     *  <code>null</code> is returned.
  +     */
  +    SourceValidity getValidity();
  +
  +    /**
  +     * Refresh the content of this object after the underlying data
  +     * content has changed.
  +     */
  +    void discardValidity();
   
   }
  
  
  
  1.16      +2 -3      jakarta-avalon-excalibur/all/src/scratchpad/org/apache/avalon/excalibur/source/URLSource.java
  
  Index: URLSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/all/src/scratchpad/org/apache/avalon/excalibur/source/URLSource.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- URLSource.java	16 Mar 2002 00:05:49 -0000	1.15
  +++ URLSource.java	17 Apr 2002 13:38:48 -0000	1.16
  @@ -23,7 +23,6 @@
   import org.apache.avalon.excalibur.monitor.SourceResource;
   import org.apache.avalon.excalibur.source.validity.TimeStampValidity;
   import org.apache.avalon.excalibur.xml.Parser;
  -import org.apache.avalon.excalibur.xml.XMLizable;
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.component.Composable;
   import org.xml.sax.ContentHandler;
  @@ -34,11 +33,11 @@
    * Description of a source which is described by an URL.
    *
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  - * @version CVS $Revision: 1.15 $ $Date: 2002/03/16 00:05:49 $
  + * @version CVS $Revision: 1.16 $ $Date: 2002/04/17 13:38:48 $
    */
   
   public final class URLSource
  -    implements Composable, ModifiableSource, XMLizable, Monitorable
  +    implements Source, Composable, Monitorable
   {
   
       /** With this parameter you can specify the method to use for a http request.
  
  
  

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