cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: xml-cocoon2/src/org/apache/cocoon/components/store FilesystemQueueObject.java FilesystemStore.java MemoryStore.java Store.java StoreJanitor.java
Date Thu, 22 Nov 2001 10:21:11 GMT
cziegeler    01/11/22 02:21:11

  Modified:    src/org/apache/cocoon/components/store
                        FilesystemQueueObject.java FilesystemStore.java
                        MemoryStore.java Store.java StoreJanitor.java
  Log:
  Finished cleanup code
  
  Revision  Changes    Path
  1.2       +17 -17    xml-cocoon2/src/org/apache/cocoon/components/store/FilesystemQueueObject.java
  
  Index: FilesystemQueueObject.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/store/FilesystemQueueObject.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FilesystemQueueObject.java	2001/10/23 11:55:19	1.1
  +++ FilesystemQueueObject.java	2001/11/22 10:21:11	1.2
  @@ -12,26 +12,26 @@
    *
    * @author <a href="mailto:g-froehlich@gmx.de">Gerhard Froehlich</a>
    */
  -public class FilesystemQueueObject implements Comparable {
  -  private Object object;
  -  private Object key;
  +public final class FilesystemQueueObject
  +implements Comparable {
   
  -  public FilesystemQueueObject (Object key, Object object) {
  -    this.object = object;
  -    this.key = key;
  -  }
  +    private Object object;
  +    private Object key;
   
  -  public FilesystemQueueObject() {}
  +    public FilesystemQueueObject (Object key, Object object) {
  +        this.object = object;
  +        this.key = key;
  +    }
   
  -  public Object getKey() {
  -    return this.key;
  -  }
  +    public Object getKey() {
  +        return this.key;
  +    }
   
  -  public Object getObject() {
  -    return this.object;
  -  }
  +    public Object getObject() {
  +        return this.object;
  +    }
   
  -  public int compareTo(Object o) {
  -    return 0;
  -  }
  +    public int compareTo(Object o) {
  +        return 0;
  +    }
   }
  
  
  
  1.11      +204 -198  xml-cocoon2/src/org/apache/cocoon/components/store/FilesystemStore.java
  
  Index: FilesystemStore.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/store/FilesystemStore.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- FilesystemStore.java	2001/11/22 10:02:42	1.10
  +++ FilesystemStore.java	2001/11/22 10:21:11	1.11
  @@ -19,7 +19,7 @@
   import java.io.IOException;
   import java.util.Enumeration;
   
  -public class FilesystemStore
  +public final class FilesystemStore
   extends AbstractLoggable
   implements Contextualizable, Store, ThreadSafe {
   
  @@ -30,11 +30,13 @@
       /**
        * Sets the repository's location
        */
  -    public void setDirectory(String directory) throws IOException {
  +    public void setDirectory(final String directory)
  +    throws IOException {
           this.setDirectory(new File(directory));
       }
   
  -    public void contextualize(Context context) throws ContextException {
  +    public void contextualize(final Context context)
  +    throws ContextException {
           try {
               setDirectory((File) context.get(Constants.CONTEXT_WORK_DIR));
           } catch (Exception e) {
  @@ -42,205 +44,209 @@
           }
       }
   
  -  /**
  -   * Sets the repository's location
  -   */
  -  public void setDirectory(File directory) throws IOException {
  -    this.directoryFile = directory;
  -
  -    /* Save directory path prefix */
  -    this.directoryPath = IOUtils.getFullFilename(this.directoryFile);
  -    this.directoryPath += File.separator;
  -
  -    /* Does directory exist? */
  -    if (!this.directoryFile.exists()) {
  -      /* Create it anew */
  -      if (!this.directoryFile.mkdir()) {
  -        throw new IOException(
  -      "Error creating store directory '" + this.directoryPath + "': "
  -    );
  -      }
  -    }
  -
  -    /* Is given file actually a directory? */
  -    if (!this.directoryFile.isDirectory()) {
  -      throw new IOException("'" + this.directoryPath + "' is not a directory");
  -    }
  -
  -    /* Is directory readable and writable? */
  -    if (!(this.directoryFile.canRead() && this.directoryFile.canWrite())) {
  -      throw new IOException(
  -        "Directory '" + this.directoryPath + "' is not readable/writable"
  -      );
  -    }
  -  }
  -
  -  /**
  -   * Returns the repository's full pathname
  -   */
  -  public String getDirectoryPath() {
  -    return this.directoryPath;
  -  }
  -
  -  /**
  -   * Get the file associated with the given unique key name.
  -   */
  -  public Object get(Object key) {
  -    getLogger().debug("FilesystemStore get(): Get file with key: " + key.toString());
  -    File file = fileFromKey(key);
  -
  -    if (file != null && file.exists()) {
  -      getLogger().debug("FilesystemStore get(): Found file with key: " + key.toString());
  -      return file;
  -    }
  -    return null;
  -  }
  -
  -  /**
  -   * Store the given object in a persistent state.
  -   * 1) Null values generate empty directories.
  -   * 2) String values are dumped to text files
  -   * 3) Object values are serialized
  -   */
  -  public void store(Object key, Object value) throws IOException {
  -      File file = fileFromKey(key);
  -
  -      /* Create subdirectories as needed */
  -      File parent = file.getParentFile();
  -      if (parent != null) {
  -        parent.mkdirs();
  -      }
  -
  -      /* Store object as file */
  -      if (value == null) { /* Directory */
  -        if (file.exists()) {
  -          if (!file.delete()) { /* FAILURE */
  -           getLogger().error("File cannot be deleted: " + file.toString());
  -           return;
  -          }
  -        }
  -
  -        file.mkdir();
  -      } else if (value instanceof String) { /* Text file */
  -        IOUtils.serializeString(file, (String) value);
  -      } else { /* Serialized Object */
  -        IOUtils.serializeObject(file, value);
  -      }
  -  }
  -
  -  /**
  -   * Holds the given object in a volatile state.
  -   */
  -  public void hold(Object key, Object value) throws IOException {
  -    this.store(key, value);
  -    File file = (File) this.get(key);
  -    if (file != null) {
  -      file.deleteOnExit();
  -    }
  -  }
  -
  -  /**
  -   * Remove the object associated to the given key.
  -   */
  -  public void remove(Object key) {
  -    File file = fileFromKey(key);
  -    if (file != null) {
  -      file.delete();
  -    }
  -  }
  -
  -  /**
  -   * Indicates if the given key is associated to a contained object.
  -   */
  -  public boolean containsKey(Object key) {
  -    File file = fileFromKey(key);
  -    if (file == null) {
  -      return false;
  -    }
  -    return file.exists();
  -  }
  -
  -  /**
  -   * Returns the list of stored files as an Enumeration of Files
  -   */
  -  public Enumeration keys() {
  -    FSEnumeration enum = new FSEnumeration();
  -    this.addKeys(enum, this.directoryFile);
  -    return enum;
  -  }
  -
  -  protected void addKeys(FSEnumeration enum,
  -                         File  directory) {
  -      final int subStringBegin = this.directoryFile.getAbsolutePath().length() + 1;
  -      final File[] files = directory.listFiles();
  -      for(int i=0; i<files.length; i++) {
  -          if (files[i].isDirectory() == true) {
  -              this.addKeys(enum, files[i]);
  -          } else {
  -              enum.add(files[i].getAbsolutePath().substring(subStringBegin));
  -          }
  -      }
  -  }
  -
  -  final class FSEnumeration implements Enumeration {
  -      private String[] array;
  -      private int      index;
  -      private int      length;
  -
  -      FSEnumeration() {
  -          this.array = new String[16];
  -          this.length = 0;
  -          this.index = 0;
  -      }
  -
  -      public void add(String key) {
  -          if (this.length == array.length) {
  -              String[] newarray = new String[this.length + 16];
  -              System.arraycopy(this.array, 0, newarray, 0, this.array.length);
  -              this.array = newarray;
  -          }
  -          this.array[this.length] = key;
  -          this.length++;
  -      }
  -
  -      public boolean hasMoreElements() {
  -          return (this.index < this.length);
  -      }
  -
  -      public Object nextElement() {
  -          if (this.hasMoreElements() == true) {
  -              this.index++;
  -              return this.array[index-1];
  -          }
  -          return null;
  -      }
  -  }
  -
  -  /* Utility Methods*/
  -  protected File fileFromKey(Object key) {
  -    String name = key.toString();
  -    return IOUtils.createFile(this.directoryFile, name);
  -  }
  -
  -  public String getString(Object key) throws IOException {
  -    File file = (File) this.get(key);
  -    if (file != null) {
  -      return IOUtils.deserializeString(file);
  +    /**
  +     * Sets the repository's location
  +     */
  +    public void setDirectory(final File directory)
  +    throws IOException {
  +        this.directoryFile = directory;
  +
  +        /* Save directory path prefix */
  +        this.directoryPath = IOUtils.getFullFilename(this.directoryFile);
  +        this.directoryPath += File.separator;
  +
  +        /* Does directory exist? */
  +        if (!this.directoryFile.exists()) {
  +            /* Create it anew */
  +            if (!this.directoryFile.mkdir()) {
  +                throw new IOException(
  +                "Error creating store directory '" + this.directoryPath + "': ");
  +            }
  +        }
  +
  +        /* Is given file actually a directory? */
  +        if (!this.directoryFile.isDirectory()) {
  +            throw new IOException("'" + this.directoryPath + "' is not a directory");
  +        }
  +
  +        /* Is directory readable and writable? */
  +        if (!(this.directoryFile.canRead() && this.directoryFile.canWrite())) {
  +            throw new IOException(
  +                "Directory '" + this.directoryPath + "' is not readable/writable"
  +            );
  +        }
       }
   
  -    return null;
  -  }
  +    /**
  +     * Returns the repository's full pathname
  +     */
  +    public String getDirectoryPath() {
  +        return this.directoryPath;
  +    }
   
  -  public void free() {}
  +    /**
  +     * Get the file associated with the given unique key name.
  +     */
  +    public Object get(final Object key) {
  +        if (this.getLogger().isDebugEnabled() == true)
  +            getLogger().debug("FilesystemStore get(): Get file with key: " + key.toString());
  +        final File file = fileFromKey(key);
  +
  +        if (file != null && file.exists()) {
  +            if (this.getLogger().isDebugEnabled() == true)
  +                getLogger().debug("FilesystemStore get(): Found file with key: " + key.toString());
  +            return file;
  +        }
  +        return null;
  +    }
   
  -  public Object getObject(Object key)
  -    throws IOException, ClassNotFoundException
  -  {
  -    File file = (File) this.get(key);
  -    if (file != null) {
  -      return IOUtils.deserializeObject(file);
  +    /**
  +     * Store the given object in a persistent state.
  +     * 1) Null values generate empty directories.
  +     * 2) String values are dumped to text files
  +     * 3) Object values are serialized
  +     */
  +    public void store(final Object key, final Object value)
  +    throws IOException {
  +        final File file = fileFromKey(key);
  +
  +        /* Create subdirectories as needed */
  +        final File parent = file.getParentFile();
  +        if (parent != null) {
  +            parent.mkdirs();
  +        }
  +
  +        /* Store object as file */
  +        if (value == null) { /* Directory */
  +            if (file.exists()) {
  +                if (!file.delete()) { /* FAILURE */
  +                    getLogger().error("File cannot be deleted: " + file.toString());
  +                    return;
  +                }
  +            }
  +
  +            file.mkdir();
  +        } else if (value instanceof String) { /* Text file */
  +            IOUtils.serializeString(file, (String) value);
  +        } else { /* Serialized Object */
  +            IOUtils.serializeObject(file, value);
  +        }
  +    }
  +
  +    /**
  +     * Holds the given object in a volatile state.
  +     */
  +    public void hold(final Object key, final Object value)
  +    throws IOException {
  +        this.store(key, value);
  +        final File file = (File) this.get(key);
  +        if (file != null) {
  +          file.deleteOnExit();
  +        }
  +    }
  +
  +    /**
  +     * Remove the object associated to the given key.
  +     */
  +    public void remove(final Object key) {
  +        final File file = fileFromKey(key);
  +        if (file != null) {
  +            file.delete();
  +        }
       }
   
  -    return null;
  -  }
  +    /**
  +     * Indicates if the given key is associated to a contained object.
  +     */
  +    public boolean containsKey(final Object key) {
  +        final File file = fileFromKey(key);
  +        if (file == null) {
  +            return false;
  +        }
  +        return file.exists();
  +    }
  +
  +    /**
  +     * Returns the list of stored files as an Enumeration of Files
  +     */
  +   public Enumeration keys() {
  +        final FSEnumeration enum = new FSEnumeration();
  +        this.addKeys(enum, this.directoryFile);
  +        return enum;
  +    }
  +
  +    protected void addKeys(FSEnumeration enum,
  +                           File  directory) {
  +        final int subStringBegin = this.directoryFile.getAbsolutePath().length() + 1;
  +        final File[] files = directory.listFiles();
  +        for(int i=0; i<files.length; i++) {
  +            if (files[i].isDirectory() == true) {
  +                this.addKeys(enum, files[i]);
  +            } else {
  +                enum.add(files[i].getAbsolutePath().substring(subStringBegin));
  +            }
  +        }
  +    }
  +
  +    final class FSEnumeration implements Enumeration {
  +        private String[] array;
  +        private int      index;
  +        private int      length;
  +
  +        FSEnumeration() {
  +            this.array = new String[16];
  +            this.length = 0;
  +            this.index = 0;
  +        }
  +
  +        public void add(String key) {
  +            if (this.length == array.length) {
  +                String[] newarray = new String[this.length + 16];
  +                System.arraycopy(this.array, 0, newarray, 0, this.array.length);
  +                this.array = newarray;
  +            }
  +            this.array[this.length] = key;
  +            this.length++;
  +        }
  +
  +        public boolean hasMoreElements() {
  +            return (this.index < this.length);
  +        }
  +
  +        public Object nextElement() {
  +            if (this.hasMoreElements() == true) {
  +                this.index++;
  +                return this.array[index-1];
  +            }
  +            return null;
  +        }
  +    }
  +
  +    /* Utility Methods*/
  +    protected File fileFromKey(final Object key) {
  +        return IOUtils.createFile(this.directoryFile, key.toString());
  +    }
  +
  +    public String getString(final Object key)
  +    throws IOException {
  +        final File file = (File) this.get(key);
  +        if (file != null) {
  +            return IOUtils.deserializeString(file);
  +        }
  +
  +        return null;
  +    }
  +
  +    public void free() {}
  +
  +    public Object getObject(final Object key)
  +    throws IOException, ClassNotFoundException
  +    {
  +        final File file = (File) this.get(key);
  +        if (file != null) {
  +            return IOUtils.deserializeObject(file);
  +        }
  +
  +        return null;
  +    }
   }
  
  
  
  1.7       +0 -0      xml-cocoon2/src/org/apache/cocoon/components/store/MemoryStore.java
  
  Index: MemoryStore.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/store/MemoryStore.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- MemoryStore.java	2001/11/22 10:02:42	1.6
  +++ MemoryStore.java	2001/11/22 10:21:11	1.7
  @@ -20,7 +20,7 @@
    *         (Apache Software Foundation)
    * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
    *         (Apache Software Foundation, Exoffice Technologies)
  - * @version CVS $Revision: 1.6 $ $Date: 2001/11/22 10:02:42 $
  + * @version CVS $Revision: 1.7 $ $Date: 2001/11/22 10:21:11 $
    */
   public class MemoryStore implements Store, ThreadSafe {
       /* WARNING: Hashtable is threadsafe, whereas HashMap is not.
  
  
  
  1.8       +0 -0      xml-cocoon2/src/org/apache/cocoon/components/store/Store.java
  
  Index: Store.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/store/Store.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Store.java	2001/11/22 10:02:42	1.7
  +++ Store.java	2001/11/22 10:21:11	1.8
  @@ -20,7 +20,7 @@
    *         (Apache Software Foundation)
    * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
    *         (Apache Software Foundation, Exoffice Technologies)
  - * @version CVS $Revision: 1.7 $ $Date: 2001/11/22 10:02:42 $
  + * @version CVS $Revision: 1.8 $ $Date: 2001/11/22 10:21:11 $
    */
   public interface Store extends Component {
   
  
  
  
  1.4       +5 -5      xml-cocoon2/src/org/apache/cocoon/components/store/StoreJanitor.java
  
  Index: StoreJanitor.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/store/StoreJanitor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StoreJanitor.java	2001/10/11 07:28:19	1.3
  +++ StoreJanitor.java	2001/11/22 10:21:11	1.4
  @@ -16,11 +16,11 @@
    */
   public interface StoreJanitor extends Component {
   
  -  String ROLE = "org.apache.cocoon.components.store.StoreJanitor";
  +    String ROLE = "org.apache.cocoon.components.store.StoreJanitor";
   
  -  /** register method for the stores */
  -  void register(Store store);
  +    /** register method for the stores */
  +    void register(Store store);
   
  -  /** unregister method for the stores */
  -  void unregister(Store store);
  +    /** unregister method for the stores */
  +    void unregister(Store store);
   }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message