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 java.lang.Object
implements DocumentLoader

Default implementation of the DocumentBuilder 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.


Nested Class Summary
protected static class DocumentLoaderImpl.CacheEntry
          Helper class for storing cached DOMs
 
Constructor Summary
DocumentLoaderImpl()
          Default constructor.
DocumentLoaderImpl(java.util.Map cache)
          Constructor.
 
Method Summary
protected  EditDOM createDOMEditor(java.lang.Class docClass, MetaData metaData)
          Create the DOM editor to use.
protected  Parse createParser(java.lang.Class docClass, ErrorReporter errorReporter, java.io.PrintWriter verboseOut)
          Create the parser to use.
protected  java.io.File findSourceFile(java.lang.Class docClass)
          Find the source file associated with docClass
protected  DocumentLoaderImpl.CacheEntry getCacheEntry(java.lang.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 java.lang.Object getClassConstant(java.lang.Class xmlcBasedClass, java.lang.String constName)
          Get one of the compiled-in constants in a XMLC-generated class (or subclass).
protected  long getCurrentTimestamp(java.lang.Class docClass, java.io.File src)
          Get the current timestamp of the *ML template for docClass.
 org.w3c.dom.Document getDocument(java.lang.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  java.lang.String getSourceFileName(java.lang.Class docClass)
          Get the name of the source file associated with docClass
 void init(XMLCDeferredParsingFactory factory)
          Bind to a factory.
protected  MetaData loadMetaData(java.lang.Class docClass, ErrorReporter errorReporter)
          Load the XMLC meta-data file.
protected  java.lang.String metaDataFileName(java.lang.Class docClass)
          Get the meta-data file path.
protected  org.w3c.dom.Document parseDocument(java.lang.Class docClass, java.io.File 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(java.util.Map cache)
Constructor. Uses the specified map as template cache.

Parameters:
cache - the cache to use.
Method Detail

getCacheEntry

protected DocumentLoaderImpl.CacheEntry getCacheEntry(java.lang.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 org.w3c.dom.Document getDocument(java.lang.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
XMLCRuntimeException

getClassConstant

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


getSourceFileName

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

XMLCRuntimeException

findSourceFile

protected java.io.File findSourceFile(java.lang.Class docClass)
                               throws XMLCRuntimeException
Find the source file associated with docClass

XMLCRuntimeException

metaDataFileName

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

XMLCRuntimeException

loadMetaData

protected MetaData loadMetaData(java.lang.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
XMLCException

getCurrentTimestamp

protected long getCurrentTimestamp(java.lang.Class docClass,
                                   java.io.File src)
Get the current timestamp of the *ML template for docClass.

Parameters:
docClass - the class to get the information for
src - the source file for this class, as returned by findSourceFile(java.lang.Class)
Returns:
the timestamp, or -1 to force a reload.

parseDocument

protected org.w3c.dom.Document parseDocument(java.lang.Class docClass,
                                             java.io.File 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(java.lang.Class)

createParser

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


createDOMEditor

protected EditDOM createDOMEditor(java.lang.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.