avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/validity NOPValidity.java TimeStampValidity.java
Date Mon, 17 Dec 2001 10:02:21 GMT
cziegeler    01/12/17 02:02:21

  Modified:    src/scratchpad/org/apache/avalon/excalibur/source
                        Source.java URLSource.java
  Added:       src/scratchpad/org/apache/avalon/excalibur/monitor
                        Monitorable.java SourceResource.java
               src/scratchpad/org/apache/avalon/excalibur/source
                        SourceValidity.java
               src/scratchpad/org/apache/avalon/excalibur/source/validity
                        NOPValidity.java TimeStampValidity.java
  Log:
  * Added Monitorable Interface for Resource monitoring of arbitrary objects.
  * Linked packages source and monitor
  * Changed support for caching of Source objects from too specific lastModified
    to validity objects (e.g. to support expire dates etc.)
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/monitor/Monitorable.java
  
  Index: Monitorable.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.monitor;
  
  /**
   * Describes an object which can be monitored.
   *
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   */
  public interface Monitorable {
  
      /**
       *  Get the corresponding Resource object for monitoring.
       */
      Resource getResource()
      throws Exception;
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/monitor/SourceResource.java
  
  Index: SourceResource.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.monitor;
  
  import org.apache.avalon.excalibur.source.Source;
  import org.apache.avalon.excalibur.source.SourceValidity;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.OutputStream;
  import java.io.Reader;
  import java.io.Writer;
  
  /**
   *
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version $Id: SourceResource.java,v 1.1 2001/12/17 10:02:21 cziegeler Exp $
   */
  public final class SourceResource extends StreamResource
  {
      private final Source source;
      private SourceValidity validity;
  
      /**
       * Instantiate the SourceResource 
       */
      public SourceResource ( Source source)
      throws Exception
      {
          super( source.getSystemId() );
  
          this.source = source;
          m_previousModified = System.currentTimeMillis();
          this.validity = source.getValidity();
      }
  
      /**
       * Determines the last time this resource was modified
       */
      public long lastModified()
      {
          if (this.validity == null) {
              return System.currentTimeMillis();
          } else {
              SourceValidity newVal = this.source.getValidity();
              if ( newVal != null && this.validity.isValid( newVal ) == true) {
                  return m_previousModified;
              } else {
                  this.validity = newVal;
                  return System.currentTimeMillis();
              }
          }
      }
  
      /**
       * Sets the resource value with an OutputStream
       */
      public InputStream getResourceAsStream() throws IOException
      {
          return this.source.getInputStream();
      }
  
      /**
       * Sets the resource value with a Writer
       */
      public Reader getResourceAsReader() throws IOException
      {
          return new InputStreamReader( this.getResourceAsStream() );
      }
  
      /**
       * Sets the resource value with an OutputStream
       */
      public OutputStream setResourceAsStream() throws IOException
      {
          throw new IOException("setResourceAsStream() not supported for URLResource");
      }
  
      /**
       * Sets the resource value with a Writer
       */
      public Writer setResourceAsWriter() throws IOException
      {
           throw new IOException("setResourceAsWriter() not supported for URLResource");
      }
  }
  
  
  
  1.7       +37 -33    jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/Source.java
  
  Index: Source.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/Source.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Source.java	2001/12/11 09:53:36	1.6
  +++ Source.java	2001/12/17 10:02:21	1.7
  @@ -20,39 +20,43 @@
    *
    * @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.6 $ $Date: 2001/12/11 09:53:36 $
  + * @version CVS $Revision: 1.7 $ $Date: 2001/12/17 10:02:21 $
    */
   public interface Source {
  -  /**
  -   * Get the last modification date of the source or 0 if it
  -   * is not possible to determine the date.
  -   */
  -  long getLastModified();
  -
  -  /**
  -   * Get the content length of the source or -1 if it
  -   * is not possible to determine the length.
  -   */
  -  long getContentLength();
  -
  -  /**
  -   * Return an <code>InputStream</code> object to read from the source.
  -   */
  -  InputStream getInputStream()
  -  throws IOException;
  -
  -  /**
  -   * Return an <code>InputSource</code> object to read the XML
  -   * content.
  -   *
  -   * @return an <code>InputSource</code> value
  -   * @exception IOException if an error occurs
  -   */
  -  InputSource getInputSource()
  -  throws IOException;
  -
  -  /**
  -   * Return the unique identifer for this source
  -   */
  -  String getSystemId();
  +
  +    /**
  +     * Get the content length of the source or -1 if it
  +     * is not possible to determine the length.
  +     */
  +    long getContentLength();
  +
  +    /**
  +     * Return an <code>InputStream</code> object to read from the source.
  +     */
  +    InputStream getInputStream()
  +    throws IOException;
  +
  +    /**
  +     * Return an <code>InputSource</code> object to read the XML
  +     * content.
  +     *
  +     * @return an <code>InputSource</code> value
  +     * @exception IOException if an error occurs
  +     */
  +    InputSource getInputSource()
  +    throws IOException;
  +
  +    /**
  +     * 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();
  +
   }
  
  
  
  1.8       +37 -3     jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/URLSource.java
  
  Index: URLSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/URLSource.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- URLSource.java	2001/12/11 09:53:36	1.7
  +++ URLSource.java	2001/12/17 10:02:21	1.8
  @@ -9,6 +9,11 @@
   
   import org.apache.avalon.framework.component.Composable;
   import org.apache.avalon.framework.component.ComponentManager;
  +import org.apache.avalon.excalibur.monitor.FileResource;
  +import org.apache.avalon.excalibur.monitor.Monitorable;
  +import org.apache.avalon.excalibur.monitor.Resource;
  +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.XMLConsumer;
   import org.apache.avalon.excalibur.xml.XMLizable;
  @@ -26,10 +31,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.7 $ $Date: 2001/12/11 09:53:36 $
  + * @version CVS $Revision: 1.8 $ $Date: 2001/12/17 10:02:21 $
    */
   
  -public final class URLSource implements ModifiableSource, XMLizable {
  +public final class URLSource 
  +implements ModifiableSource, XMLizable, Monitorable {
   
       /** Identifier for file urls */
       private final String FILE = "file:";
  @@ -83,7 +89,7 @@
       private void getInfos() {
           if (this.gotInfos == false) {
               if (this.isFile == true) {
  -                File file = new File(systemId.substring(FILE.length()));
  +                File file = new File(this.systemId.substring(FILE.length()));
                   this.lastModificationDate = file.lastModified();
                   this.contentLength = file.length();
               } else {
  @@ -116,6 +122,19 @@
       }
   
       /**
  +     *  Get the corresponding Resource object for monitoring.
  +     */
  +    public Resource getResource() 
  +    throws Exception {
  +        this.getInfos();
  +        if (this.isFile == true) {
  +            return new FileResource(this.systemId.substring(FILE.length()));
  +        } else {
  +            return new SourceResource(this);
  +        }
  +    }
  +
  +    /**
        * Get the content length of the source or -1 if it
        * is not possible to determine the length.
        */
  @@ -194,6 +213,21 @@
        */
       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() {
  +        final long lm = this.getLastModified();
  +        if (lm == -1) {
  +            return null;
  +        } else {
  +            return new TimeStampValidity(lm);
  +        }
       }
   
       /**
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/SourceValidity.java
  
  Index: SourceValidity.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.source;
  
  /**
   * A Validity object contains all information to check if a Source object is
   * still valid.
   *
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/12/17 10:02:21 $
   */
  public interface SourceValidity 
  extends java.io.Serializable {
  
      /**
       * Check if the component is still valid.
       * This is only true, if the incoming Validity is of the same
       * type and has the same values.
       * The invocation order is that the isValid method of the
       * old Validity object is called with the new one as a parameter
       */
      boolean isValid(SourceValidity newValidity);
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/validity/NOPValidity.java
  
  Index: NOPValidity.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.source.validity;
  
  import org.apache.avalon.excalibur.source.SourceValidity;
  
  /**
   * A validation object which is always valid.
   *
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/12/17 10:02:21 $
   */
  public final class NOPValidity
  implements SourceValidity {
  
      public boolean isValid(SourceValidity newValidity) {
          return newValidity instanceof NOPValidity;
      }
  
      public String toString() {
          return "NOPValidity";
      }
  
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/validity/TimeStampValidity.java
  
  Index: TimeStampValidity.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.source.validity;
  
  import org.apache.avalon.excalibur.source.SourceValidity;
  
  /**
   * A validation object for time-stamps.
   *
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/12/17 10:02:21 $
   */
  public final class TimeStampValidity
  implements SourceValidity {
  
      private long timeStamp;
  
      public TimeStampValidity(long timeStamp) {
          this.timeStamp = timeStamp;
      }
  
      public boolean isValid(SourceValidity newValidity) {
          if (newValidity instanceof TimeStampValidity) {
              return this.timeStamp == ((TimeStampValidity)newValidity).getTimeStamp();
          }
          return false;
      }
  
      public long getTimeStamp() {
          return this.timeStamp;
      }
  
      public String toString() {
          return "TimeStampValidity: " + this.timeStamp;
      }
  
  }
  
  
  

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


Mime
View raw message