org.apache.batik.refimpl.bridge
Class BufferedDocumentLoader

java.lang.Object
  |
  +--org.apache.batik.refimpl.bridge.BufferedDocumentLoader
All Implemented Interfaces:
DocumentLoader

public class BufferedDocumentLoader
extends java.lang.Object
implements DocumentLoader

A buffered document loader. This loader caches documents depending on the total number of nodes of each document. If the total number of cached nodes is greater than MAX_CACHED_NODE_COUNT, the oldest document is removed from the cache.


Field Summary
protected  int currentCachedNodeCount
          The current number of cached nodes.
protected  java.util.List documentList
          A list of the DocumentState.
protected  DocumentLoader documentLoader
          The enclosed document loader used to load the document when needed.
protected  java.util.HashMap documentMap
          The map that contains the Document indexed by the URI.
static int MAX_CACHED_NODE_COUNT
          The maximum number of cachable nodes.
 
Constructor Summary
BufferedDocumentLoader(DocumentLoader documentLoader)
          Constructs a new DocumentLoader using the specified document loader to load a document.
 
Method Summary
 void dispose()
          Disposes and releases all resources allocated by this document loader.
protected  org.apache.batik.refimpl.bridge.BufferedDocumentLoader.DocumentState getDocumentState(Document document)
          Returns the DocumentState of the specified Document.
protected  int getNodeCount(Node n)
          Returns the number of nodes in the specified document.
 Document loadDocument(java.lang.String uri)
          Returns the document associated to the specified URI.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_CACHED_NODE_COUNT

public static final int MAX_CACHED_NODE_COUNT
The maximum number of cachable nodes.

documentLoader

protected DocumentLoader documentLoader
The enclosed document loader used to load the document when needed.

documentMap

protected java.util.HashMap documentMap
The map that contains the Document indexed by the URI.

documentList

protected java.util.List documentList
A list of the DocumentState. Each time a document is loaded, the first item becomes this document.

currentCachedNodeCount

protected int currentCachedNodeCount
The current number of cached nodes.
Constructor Detail

BufferedDocumentLoader

public BufferedDocumentLoader(DocumentLoader documentLoader)
Constructs a new DocumentLoader using the specified document loader to load a document.
Parameters:
documentLoader - the document loader used to load a document
Method Detail

loadDocument

public Document loadDocument(java.lang.String uri)
                      throws DOMException,
                             SAXException,
                             java.lang.InterruptedException
Returns the document associated to the specified URI. First checks in the cache if the document has not already been loaded. If not, use the enclosed document loader to physically load it and update the cache.
Specified by:
loadDocument in interface DocumentLoader
Parameters:
uri - the uri of the document to return
Throws:
java.lang.InterruptedException - is thrown if this thread is interrupted.

dispose

public void dispose()
Description copied from interface: DocumentLoader
Disposes and releases all resources allocated by this document loader.
Specified by:
dispose in interface DocumentLoader

getDocumentState

protected org.apache.batik.refimpl.bridge.BufferedDocumentLoader.DocumentState getDocumentState(Document document)
Returns the DocumentState of the specified Document.
Parameters:
document - the document

getNodeCount

protected int getNodeCount(Node n)
Returns the number of nodes in the specified document.


Copyright © 2000 Apache Software Foundation. All Rights Reserved.