org.enhydra.xml.xmlc.deferredparsing
Class DocumentLoaderImpl

java.lang.Object
  |
  +--org.enhydra.xml.xmlc.deferredparsing.DocumentLoaderImpl
All Implemented Interfaces:
DocumentLoader
Direct Known Subclasses:
StandardDocumentLoader

public class DocumentLoaderImpl
extends Object
implements DocumentLoader

Default implementation of the DocumentLoader interface.

This implementation maintains a global cache of loaded DOM objects. If a DOM object is found in cache and the cached copy is up to date with regard to the source document and XMLC metadata object, a copy of the cached object is handed out. Otherwise, the document is reparsed from the source document, the DOM edits specified in the document metadata are performed and the document is stored in cache as a template. Note that the cache may be a WeakHashMap or a map with similar semantics that frees up entries if memory gets low.

This class can be used as the basis for specialized document loaders.


Inner Class Summary
protected static class DocumentLoaderImpl.CacheEntry
          Helper class for storing cached DOMs
 
Constructor Summary
DocumentLoaderImpl()
          Default constructor.
DocumentLoaderImpl(Map cache)
          Constructor.
 
Method Summary
protected  EditDOM createDOMEditor(Class docClass, MetaData metaData)
          Create the DOM editor to use.
protected  Parse createParser(Class docClass, ErrorReporter errorReporter, PrintWriter verboseOut)
          Create the parser to use.
protected  URL findSourceUrl(Class docClass)
          Find the URL of the source document associated with docClass
protected  DocumentLoaderImpl.CacheEntry getCacheEntry(Class docClass)
          Get the cache entry for a document, initialize one of not already exists Note that the cache entry does not necessarily hold a template - it may need to be initialized first.
static Object getClassConstant(Class xmlcBasedClass, String constName)
          Get one of the compiled-in constants in a XMLC-generated class (or subclass).
protected  long getCurrentTimestamp(Class docClass, URL src)
          Get the current timestamp of the *ML template for docClass.
 Document getDocument(Class docClass)
          Get a DOM instance representing the specified document.
protected  XMLCDeferredParsingFactory getFactory()
          Get the associated factory
protected  XMLCLogger getLogger()
          Get the associated logger
protected  String getSourceFileName(Class docClass)
          Get the name of the source file associated with docClass
 void init(XMLCDeferredParsingFactory factory)
          Bind to a factory.
protected  MetaData loadMetaData(Class docClass, ErrorReporter errorReporter)
          Load the XMLC meta-data file.
protected  String metaDataFileName(Class docClass)
          Get the meta-data file path.
protected  Document parseDocument(Class docClass, URL src)
          Create a new template DOM for docClass
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DocumentLoaderImpl

public DocumentLoaderImpl()
Default constructor. Uses a Cache as template DOM cache.
See Also:
DocumentLoaderImpl(Map)

DocumentLoaderImpl

public DocumentLoaderImpl(Map cache)
Constructor. Uses the specified map as template cache.
Parameters:
cache - the cache to use.
Method Detail

getCacheEntry

protected DocumentLoaderImpl.CacheEntry getCacheEntry(Class docClass)
Get the cache entry for a document, initialize one of not already exists Note that the cache entry does not necessarily hold a template - it may need to be initialized first. Subclasses overriding this method must make sure that new cache entries are constructed and put in the cache in a thread safe manner.
Parameters:
docClass - the class to get the cache entry for.
Returns:
a cache entry. The returned object is suitable as mutex for document intialization.

getDocument

public Document getDocument(Class docClass)
                     throws XMLCRuntimeException
Get a DOM instance representing the specified document.
Specified by:
getDocument in interface DocumentLoader
Parameters:
docClass - the XMLC generated class to get the DOM for.
Returns:
the DOM representing objects of docClass

getClassConstant

public static Object getClassConstant(Class xmlcBasedClass,
                                      String constName)
Get one of the compiled-in constants in a XMLC-generated class (or subclass).

getSourceFileName

protected String getSourceFileName(Class docClass)
                            throws XMLCRuntimeException
Get the name of the source file associated with docClass

findSourceUrl

protected URL findSourceUrl(Class docClass)
                     throws XMLCRuntimeException
Find the URL of the source document associated with docClass

metaDataFileName

protected String metaDataFileName(Class docClass)
                           throws XMLCRuntimeException
Get the meta-data file path. This id the name the interface name for class with .xmlc extension.

loadMetaData

protected MetaData loadMetaData(Class docClass,
                                ErrorReporter errorReporter)
                         throws XMLCException
Load the XMLC meta-data file.
Parameters:
docClass - the class to load the metadata for
errorReporter - the error handler to use

getCurrentTimestamp

protected long getCurrentTimestamp(Class docClass,
                                   URL src)
Get the current timestamp of the *ML template for docClass.
Parameters:
docClass - the class to get the information for
src - the source URL for this class, as returned by findSourceUrl(Class)
Returns:
the timestamp, or -1 to force a reload.

parseDocument

protected Document parseDocument(Class docClass,
                                 URL src)
Create a new template DOM for docClass
Parameters:
docClass - the class to laod the DOM for
src - the source file for this class, as returned by #findSourceFile

createParser

protected Parse createParser(Class docClass,
                             ErrorReporter errorReporter,
                             PrintWriter verboseOut)
Create the parser to use. Override this if you need a special version

createDOMEditor

protected EditDOM createDOMEditor(Class docClass,
                                  MetaData metaData)
Create the DOM editor to use. Override this if you need a special version

init

public void init(XMLCDeferredParsingFactory factory)
Bind to a factory.
Specified by:
init in interface DocumentLoader
Parameters:
factory - Factory that is creating the object.

getFactory

protected XMLCDeferredParsingFactory getFactory()
Get the associated factory

getLogger

protected XMLCLogger getLogger()
Get the associated logger


Copyright © 1999-2002 enhydra.org (Mark Diekhans, David Li, Richard Kunze). All Rights reserved.