Enhydra 3.0.3 API

org.enhydra.xml.xmlc.autocomp
Class XMLCAutoCompFactory

java.lang.Object
  |
  +--org.enhydra.xml.xmlc.autocomp.XMLCAutoCompFactory

public class XMLCAutoCompFactory
extends java.lang.Object
implements XMLCFactory

Factory class to create instances of XMLC-generated class with automatic recompilation if the class is out-of-date relative to a source file.

This class can create objects from classes derived from XMLC objects. It uses a constructor that takes a boolean argument which delays the creation of the DOM until the delegate can be set. If the derived class requires another constructor, this can be approached in two ways. Either deriving a factory that creates objects through the derived constructor or used this factory object inside of the derived class constructor, obtain the delegate with getUpdatedClass(). Such a constructor would contain:

    super(false);
    setDelegate(factory.getUpdatedClassInstance());
    buildDocument();
 
If a log channel is supplied, logging maybe performed. The following log levels are used:

See Also:
StandardRecompilationHandler, ResourceLoader, ResourceLoaderFactory

Fields inherited from interface org.enhydra.xml.xmlc.XMLCFactory
XMLC_DEBUG_LOG_LEVEL, XMLC_LOG_LEVEL
 
Constructor Summary
XMLCAutoCompFactory(RecompilationHandler recompiler, java.lang.ClassLoader classLoader, com.lutris.logging.LogChannel logChannel)
          Constructor.
XMLCAutoCompFactory(RecompilationHandler recompiler, ResourceLoader resourceLoader, com.lutris.logging.LogChannel logChannel)
          Constructor.
 
Method Summary
 XMLObject create(java.lang.Class xmlcBasedClass)
          Create an instance of a XMLC-generated class or a class derived from one, given either a class or an interface object.
 XMLObject create(java.lang.String xmlcClassName)
          Create an instance of a XMLC-generated class or a class derived from one, given the name of the class.
protected 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).
 com.lutris.logging.LogWriter getDebugLogWriter()
          Get the XMLC debugging log writer or null if no debug logging is to be done.
 com.lutris.logging.LogChannel getLogChannel()
          Get the log channel associated with this factory or null if none.
 com.lutris.logging.LogWriter getLogWriter()
          Get the XMLC informative log writer or null if no logging is to be done.
 int getRecompileCount()
          Get the count of the number of recompilations that have occured.
 int getReloadCount()
          Get the count of the number of reloads that have occured.
 ResourceLoader getResourceLoader()
          Get the ResourceLoader associate this this factory
 XMLObject getUpdatedClassInstance(java.lang.Class xmlcBasedClass)
          If a XMLC class has been updated, get a new instance of it.
protected  void incrRecompileCount()
          Increment the count of the number of recompilations that have occured.
protected  void incrReloadCount()
          Increment the count of the number of reloads that have occured.
 java.lang.Class loadUpdatedClass(java.lang.Class xmlcBasedClass)
          Given a class that is either a XMLC-generate class or a class derived from one, determine if the generate class is out-of-date; if so recompile and return the new class as the delegate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLCAutoCompFactory

public XMLCAutoCompFactory(RecompilationHandler recompiler,
                           ResourceLoader resourceLoader,
                           com.lutris.logging.LogChannel logChannel)
Constructor.
Parameters:
recompiler - Recompilation handler used to recompile objects. If null, classes will not be recompiled.
resourceLoader - ResourceLoader used to load classes and locate the source file. This is a wrapper around a class loader that implements functionality missing in the standard classloader interface.
logChannel - The log channel to use to log events and errors. If null, no logging is done. Level XMLC is used to log reloading and recompilation. Level ERROR is used for errors.

XMLCAutoCompFactory

public XMLCAutoCompFactory(RecompilationHandler recompiler,
                           java.lang.ClassLoader classLoader,
                           com.lutris.logging.LogChannel logChannel)
Constructor.
Parameters:
recompiler - Recompilation handler used to recompile objects. If null, classes will not be recompiled.
classLoader - Classloader used to load classes when a class name is specified. This must be one of the class loaders that we have built-in knowledge of. The currently supported classloaders are:
  • com.lutris.classloader.MultiClassLoader
  • org.apache.tomcat.util.NetworkClassLoader
logChannel - The log channel to use to log events and errors. If null, no logging is done. Level XMLC is used to log reloading and recompilation. Level ERROR is used for errors.
Method Detail

getClassConstant

protected 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).

loadUpdatedClass

public java.lang.Class loadUpdatedClass(java.lang.Class xmlcBasedClass)
Given a class that is either a XMLC-generate class or a class derived from one, determine if the generate class is out-of-date; if so recompile and return the new class as the delegate. This method is useful when building derived factory classes.
Parameters:
xmlcBasedClass - The XMLC-generate class or a subclass.
Returns:
The new version of the generated class, or null if the class is not out of date.
Throws:
XMLCAutoCompException - If an error occurs obtaining the class.

getUpdatedClassInstance

public XMLObject getUpdatedClassInstance(java.lang.Class xmlcBasedClass)
If a XMLC class has been updated, get a new instance of it. Don't build the DOM at this time.
Parameters:
xmlcBasedClass - The XMLC-generate class or a subclass.
Returns:
A new instance of the XMLC-generate class (not the subclass, sutiable for use as a delegate. If the class is not out of date, null is returned.
Throws:
XMLCAutoCompException - If an error occurs obtaining the class.

create

public XMLObject create(java.lang.String xmlcClassName)
Create an instance of a XMLC-generated class or a class derived from one, given the name of the class.

The class must have a constructor that takes a single boolean argument that will disable the immediate build of the DOM if false. XMLC creates such a constructor in the classes it generates.

Specified by:
create in interface XMLCFactory
Parameters:
xmlcClassName - The name of the XMLC class or derived class.
Returns:
The new object.
Throws:
XMLCAutoCompException - If an error occurs creating the object.
See Also:
create(Class)

create

public XMLObject create(java.lang.Class xmlcBasedClass)
Create an instance of a XMLC-generated class or a class derived from one, given either a class or an interface object.

If a class is given, then it should be either the XMLC generated class or a class derived from it.

If an interface is given, it is converted to the implementation name by appending "Impl" to the name. In this case, the implementation must be in the same package.

The class must have a constructor that takes a single boolean argument that will disable the immediate build of the DOM if false. XMLC creates such a constructor in the classes it generates.

Specified by:
create in interface XMLCFactory
Parameters:
xmlcBasedClass - The Class object for the class or interface.
Returns:
The new object.
Throws:
XMLCAutoCompException - If an error occurs creating the object.

getResourceLoader

public ResourceLoader getResourceLoader()
Get the ResourceLoader associate this this factory

getLogChannel

public com.lutris.logging.LogChannel getLogChannel()
Get the log channel associated with this factory or null if none.

getLogWriter

public com.lutris.logging.LogWriter getLogWriter()
Get the XMLC informative log writer or null if no logging is to be done.

getDebugLogWriter

public com.lutris.logging.LogWriter getDebugLogWriter()
Get the XMLC debugging log writer or null if no debug logging is to be done.

incrReloadCount

protected void incrReloadCount()
Increment the count of the number of reloads that have occured.

getReloadCount

public int getReloadCount()
Get the count of the number of reloads that have occured.

incrRecompileCount

protected void incrRecompileCount()
Increment the count of the number of recompilations that have occured.

getRecompileCount

public int getRecompileCount()
Get the count of the number of recompilations that have occured.

Enhydra 3.0.3 API