autohit.creator.compiler
Class XmlCompiler

java.lang.Object
  extended byautohit.creator.compiler.XmlCompiler
Direct Known Subclasses:
SimCompiler

public abstract class XmlCompiler
extends java.lang.Object

This is the a base XML compiler. It must be extended by a specific compiler. Users of an extended class will call the compile() method in this class, which will first parse the XML then call the abstract method build(). An extended class must override the build() method and use to to compile from the xml document tree.

This will load/cache the DTD by providing a new Resolver that will return a string reader to the cached DTD. It assumes that each execution of "build" is for a new compile.

WARNING!!! For the compiler to work, the root property must be set and passed in the prop to the constructor.

Version:
1.1 Version History EPG - Initial - 14Apr03
Author:
Erich P. Gatejen

Field Summary
 XmlParseErrorHandler myErrorHandler
          Handles parse/compile errors and warnings.
 AutohitLogInjectorWrapper myLog
           
 AutohitLogInjectorWrapper runtimeLog
          Runtime logger.
 
Constructor Summary
XmlCompiler()
          Constructor.
XmlCompiler(java.lang.String dtdURI, SystemContext sc)
          Constructor.
 
Method Summary
abstract  java.lang.Object build(org.w3c.dom.Document xd)
          Abstract build method.
 java.lang.Object compile(java.io.InputStream is)
          Compile a stream into object code.
 int numberErrors()
          Get error count.
 int numberWarnings()
          Get warning count.
 void resetRuntimeLog()
          This sets the runtime log back to be the same as the system log.
 void runtimeDebug(java.lang.String t)
          Posts a debug message to the runtime log.
 void runtimeError(java.lang.String t)
          Posts a warning to the runtime log and increments the error count.
 void runtimeWarning(java.lang.String t)
          Posts a warning to the runtime log and increments the error count.
 void setRuntimeLog(AutohitLogInjectorWrapper cl)
          This sets the runtime log.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

runtimeLog

public AutohitLogInjectorWrapper runtimeLog
Runtime logger. Used for compile-time logging. Use the two helper methods instead of using it directly--runtimeError and runtimeWarning.

See Also:
runtimeError(String t), runtimeWarning(String t)

myLog

public AutohitLogInjectorWrapper myLog

myErrorHandler

public XmlParseErrorHandler myErrorHandler
Handles parse/compile errors and warnings. Also serves as the ErrorHandler for the XML parser.

See Also:
XmlParseErrorHandler
Constructor Detail

XmlCompiler

public XmlCompiler(java.lang.String dtdURI,
                   SystemContext sc)
            throws java.lang.Exception
Constructor. You must use this and NOT the default. It will make sure that the DTD for the SimLanguage is available. If you use the defaulty constructor, the compiler will not know which DTD to use. That is a BAD THING(tm).

Parameters:
dtdURI - URI of the DTD used in the !DOCTYPE * SYSTEM clause in the compile targets.
sc - A system context containing valid references to a root logger and the system properties.
Throws:
java.lang.Exception - any exception invalidates the compiler.

XmlCompiler

public XmlCompiler()
            throws AutohitException
Constructor. Don't use the default--ever.

Method Detail

compile

public java.lang.Object compile(java.io.InputStream is)
Compile a stream into object code. It will abort on a major error and return a null instead of an object. This base class does not specify the format of the object code. Any compile errors or warnings can be found in the errors field.

Parameters:
is - An input stream to the text that is to be compiled.
Returns:
a reference to the target object.

runtimeWarning

public void runtimeWarning(java.lang.String t)
Posts a warning to the runtime log and increments the error count.

Parameters:
t - the warning message

runtimeError

public void runtimeError(java.lang.String t)
Posts a warning to the runtime log and increments the error count.

Parameters:
t - the error message

runtimeDebug

public void runtimeDebug(java.lang.String t)
Posts a debug message to the runtime log.

Parameters:
t - the debug message

numberErrors

public int numberErrors()
Get error count.

Returns:
number of errors

numberWarnings

public int numberWarnings()
Get warning count.

Returns:
number of warnings

setRuntimeLog

public void setRuntimeLog(AutohitLogInjectorWrapper cl)
This sets the runtime log. The runtime log will be used during compilation. The system (myLog) is used during overhead functions. These can be the same log. This method lets you point to a different log. This will clear the error and warning counts.

Parameters:
cl - a log injector

resetRuntimeLog

public void resetRuntimeLog()
This sets the runtime log back to be the same as the system log.


build

public abstract java.lang.Object build(org.w3c.dom.Document xd)
Abstract build method. Override with a method that builds the object code from the XML parse tree.

Parameters:
xd - A parsed XML document.
Returns:
Object reference to the object code.


Test.