kevinross    2003/07/03 12:23:07

  Modified:    java/src/org/apache/xindice/core DocumentCache.java
  Log:
  PR: 21289
  Reporter: [EMAIL PROTECTED]
  Reviewed by: Kevin Ross
  
  Patch applied
  
  Revision  Changes    Path
  1.4       +95 -106   
xml-xindice/java/src/org/apache/xindice/core/DocumentCache.java
  
  Index: DocumentCache.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/src/org/apache/xindice/core/DocumentCache.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DocumentCache.java        31 Oct 2002 06:59:56 -0000      1.3
  +++ DocumentCache.java        3 Jul 2003 19:23:07 -0000       1.4
  @@ -58,7 +58,7 @@
    *
    * $Id$
    */
  - 
  +
   import org.apache.xindice.core.data.Key;
   import org.apache.xindice.xml.NodeSource;
   import org.apache.xindice.xml.SymbolTable;
  @@ -76,109 +76,98 @@
    */
   
   public final class DocumentCache {
  -   private Map table = new WeakHashMap();
  +     private Map table = new WeakHashMap();
   
  -   public Document getDocument(Collection col, Key key) {
  -      Object v = table.get(new CacheKey(col, key));
  -      Document doc = null;
  -      if ( v instanceof Document )
  -         doc = (Document)v;
  -      else if ( v instanceof byte[] ) {
  -         try {
  -            SymbolTable s = col.getSymbols();
  -            NodeSource ns = new NodeSource(col, key);
  -            doc = new DocumentImpl((byte[])v, s, ns);
  -         }
  -         catch ( Exception e ) {
  -         }
  -      }
  -      return doc;
  -   }
  -   
  -   public void putDocument(Collection col, Key key, byte[] bytes) {
  -      CacheKey ckey = new CacheKey(col, key);
  -      table.put(ckey, bytes);
  -   }
  -   
  -   public void putDocument(Collection col, Key key, Document doc) {
  -      CacheKey ckey = new CacheKey(col, key);
  -      table.put(ckey, doc);
  -   }
  -
  -   public void removeDocument(Collection col, Key key) {
  -      table.remove(new CacheKey(col, key));
  -   }
  -
  -   public static int getCacheControl(Document doc) {
  -      String cache = DBDocument.CACHE;
  -      NodeList childNodes = doc.getChildNodes();
  -      int size = childNodes.getLength();
  -      for ( int i = 0; i < size; i++ ) {
  -         Node n = childNodes.item(i);
  -         if ( n.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE
  -           && n.getNodeName().equals(DBDocument.CACHE_CONTROL) ) {
  -            cache = n.getNodeValue().trim();
  -            break;
  -         }
  -      }
  -
  -      if ( cache != null ) {
  -         if ( cache.equals(DBDocument.CACHE) )
  -            return -1;
  -         else if ( cache.equals(DBDocument.NOCACHE) )
  -            return 0;
  -         else
  -            return Integer.parseInt(cache);
  -      }
  -      else
  -         return -1;
  -   }
  -
  -
  -   /**
  -    * CacheKey
  -    */
  -   
  -   private class CacheKey {
  -      private Collection col;
  -      private String strVal;
  -      private Key key;
  -
  -      public CacheKey(Collection col, Key key) {
  -         this.col = col;
  -         this.key = key;
  -      }
  -
  -      public Collection getCollection() {
  -         return col;
  -      }
  -
  -      public Key getKey() {
  -         return key;
  -      }
  -
  -      public String toString() {
  -         if ( strVal == null )
  -            strVal = col.getCanonicalDocumentName(key);
  -         return strVal;
  -      }
  -
  -      public int hashCode() {
  -         if ( strVal == null )
  -            strVal = col.getCanonicalDocumentName(key);
  -         return strVal.hashCode();
  -      }
  -
  -      public boolean equals(Object o) {
  -         if ( o == null ) {
  -            return false;
  -         }
  -         
  -         CacheKey comp = (CacheKey)o;
  -         if ( col != comp.col )
  -            return false;
  -         return key.equals(comp.key );
  -      }
  -   }
  +     public Document getDocument(Collection col, Key key) {
  +             Object v = table.get(new CacheKey(col, key));
  +             Document doc = null;
  +             if (v instanceof Document)
  +                     doc = (Document) v;
  +             else if (v instanceof byte[]) {
  +                     try {
  +                             SymbolTable s = col.getSymbols();
  +                             NodeSource ns = new NodeSource(col, key);
  +                             doc = new DocumentImpl((byte[]) v, s, ns);
  +                     }
  +                     catch (Exception e) {}
  +             }
  +             return doc;
  +     }
  +
  +     public void putDocument(Collection col, Key key, byte[] bytes) {
  +             CacheKey ckey = new CacheKey(col, key);
  +             table.put(ckey, bytes);
  +     }
  +
  +     public void putDocument(Collection col, Key key, Document doc) {
  +             CacheKey ckey = new CacheKey(col, key);
  +             table.put(ckey, doc);
  +     }
  +
  +     public void removeDocument(Collection col, Key key) {
  +             table.remove(new CacheKey(col, key));
  +     }
  +
  +     public static int getCacheControl(Document doc) {
  +             String cache = DBDocument.CACHE;
  +             NodeList childNodes = doc.getChildNodes();
  +             int size = childNodes.getLength();
  +             for (int i = 0; i < size; i++) {
  +                     Node n = childNodes.item(i);
  +                     if (n.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE 
&& n.getNodeName().equals(DBDocument.CACHE_CONTROL)) {
  +                             cache = n.getNodeValue().trim();
  +                             break;
  +                     }
  +             }
  +
  +             if (cache != null) {
  +                     if (cache.equals(DBDocument.CACHE))
  +                             return -1;
  +                     else if (cache.equals(DBDocument.NOCACHE))
  +                             return 0;
  +                     else
  +                             return Integer.parseInt(cache);
  +             }
  +             else
  +                     return -1;
  +     }
  +
  +     /**
  +      * CacheKey
  +      */
  +
  +     private class CacheKey {
  +             private Collection col;
  +             private String strVal;
  +             private Key key;
  +
  +             public CacheKey(Collection col, Key key) {
  +                     this.col = col;
  +                     this.key = key;
  +             }
  +
  +             public Collection getCollection() {
  +                     return col;
  +             }
  +
  +             public Key getKey() {
  +                     return key;
  +             }
  +
  +             public String toString() {
  +                     if (strVal == null)
  +                             strVal = col.getCanonicalDocumentName(key);
  +                     return strVal;
  +             }
  +
  +             public int hashCode() {
  +                     if (strVal == null)
  +                             strVal = col.getCanonicalDocumentName(key);
  +                     return strVal.hashCode();
  +             }
  +
  +             public boolean equals(Object o) {
  +                     return o instanceof CacheKey && col == ((CacheKey) 
o).col && key.equals(((CacheKey) o).key);
  +             }
  +     }
   }
  -
  
  
  

Reply via email to