com.infoengine.SAK
Class TaskCompiler

java.lang.Object
  extended bycom.infoengine.SAK.TaskCompiler
All Implemented Interfaces:
Cloneable, Serializable

public class TaskCompiler
extends Object
implements Cloneable, Serializable

This class supports dynamic compilation of Info*Engine tasks.

See Also:
Serialized Form

Nested Class Summary
private  class TaskCompiler.Tag
          Inner class for parsing tags from a stream tokenizer.
private  class TaskCompiler.TaskClassLoader
          Inner class for loading tasklets.
private  class TaskCompiler.UnitDescriptor
          Inner class supporting task units ( ...
 
Field Summary
private  String codebase
           
private  Hashtable compiledClasses
           
private  String compilerClassPath
           
private static String ID_COMP_CLASSES
           
private static String ID_COMP_CLASSPATH
           
private static String ID_TASK_FILE_EXPIRY
           
private static String ID_TASK_SRC_EXPIRY
           
private static String ID_TASKS
           
private  int iteratorOrdinal
           
private  com.infoengine.log.LogWriter log
           
private  Vector processors
           
 boolean recoveryCode
           
static String RESOURCE
           
static String TAGLIB_URI
           
private  String tagPrefix
           
private  Hashtable taskFileExpiry
           
private  int taskOrdinal
           
private  String taskRoot
           
private  Hashtable tasks
           
private  Hashtable taskSourceExpiry
           
private  long timeToLive
           
static int VERSION
           
private  int webjectOrdinal
           
 
Constructor Summary
TaskCompiler()
          Constructs a simple instance.
 
Method Summary
 Tasklet compile(String url)
          Compiles a task and returns an instance that can be invoked.
private  void compileTask(String className, String uri)
          Parse task source and produce a Java tasklet from it.
private  void emitParam(String wsp, String prefix, TaskCompiler.Tag paramTag, String uri, int lineNumber, PrintWriter pw)
          Emits code to process a webject or task parameter.
private  String escape(String source)
          Returns the escaped version of a string that possibly contains characters that aren't suitable as contents of Java source strings, e.g., double quotes and backslashes.
private  void generateJavaSource(String className, String uri, BufferedReader rdr, PrintWriter pw)
          Parse a task file and produce a Java source file from it.
private  String getClassNameForTask(String uri)
          Return the class name associated with a task URI.
 String getCodebase()
          Returns the pathname of the file system root directory of the codebase to which generated code will be written.
private  String getCodebasePathForTask(String uri)
          Return the base pathname of the generated java and class files associated with a task URI.
 com.infoengine.log.LogWriter getLog()
          Returns the LogWriter to which log messages are currently written.
 String getTaskRoot()
          Returns the pathname of the file system directory where tasks specified by relative URL are found.
private  String indent(int depth)
          Returns a string of blanks reflecting the indenting depth.
private  boolean isTaskStale(String uri)
          Return true if the specified task file has been modified since the tasklet generated from it was last compiled.
private  Class loadTask(String className, String uri)
          Load the class associated with a specified tasklet.
private  String parseParamValue(String attr, String data, String deflt, String uri, int lineno, boolean runtimeSubst)
          Parses a tag attribute value to generate code for special substitution strings and embedded <%= ...
private  void parseTask(StreamTokenizer tokenizer, String uri, PrintWriter spw, PrintWriter dpw, PrintWriter cpw, TaskCompiler.Tag tag, int indentDepth, int parallelDepth, boolean inheritForm)
          Parses a TASK tag and generates Java source for it.
private  String parseWebject(StreamTokenizer tokenizer, String uri, PrintWriter spw, PrintWriter dpw, PrintWriter cpw, TaskCompiler.Tag tag, int indentDepth, int parallelDepth)
          Parses a WEBJECT tag and generates Java source for it.
 void setCodebase(String pathname)
          Sets the pathname of the file system root directory of the codebase to which generated code will be written.
 void setLog(com.infoengine.log.LogWriter log)
          Sets the LogWriter to which log messages will be written.
private  void setTaskFileExpiry(File taskFile)
          Sets the expiration on a task file if configured to do so.
 void setTaskRoot(String pathname)
          Sets the pathname of the default file system directory in which task source is found for tasks specified by relative URL.
private  String unescape(String source)
          Returns the unescaped version of a string that possibly contains escapes for characters that aren't valid characters for Java identifiers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TAGLIB_URI

public static final String TAGLIB_URI
See Also:
Constant Field Values

VERSION

public static final int VERSION
See Also:
Constant Field Values

RESOURCE

public static final String RESOURCE
See Also:
Constant Field Values

recoveryCode

public boolean recoveryCode

codebase

private String codebase

iteratorOrdinal

private int iteratorOrdinal

log

private com.infoengine.log.LogWriter log

processors

private Vector processors

tagPrefix

private String tagPrefix

taskOrdinal

private int taskOrdinal

taskRoot

private String taskRoot

timeToLive

private long timeToLive

webjectOrdinal

private int webjectOrdinal

ID_COMP_CLASSES

private static final String ID_COMP_CLASSES
See Also:
Constant Field Values

ID_COMP_CLASSPATH

private static final String ID_COMP_CLASSPATH
See Also:
Constant Field Values

ID_TASKS

private static final String ID_TASKS
See Also:
Constant Field Values

ID_TASK_SRC_EXPIRY

private static final String ID_TASK_SRC_EXPIRY
See Also:
Constant Field Values

ID_TASK_FILE_EXPIRY

private static final String ID_TASK_FILE_EXPIRY
See Also:
Constant Field Values

compiledClasses

private Hashtable compiledClasses

compilerClassPath

private String compilerClassPath

tasks

private Hashtable tasks

taskSourceExpiry

private Hashtable taskSourceExpiry

taskFileExpiry

private Hashtable taskFileExpiry
Constructor Detail

TaskCompiler

public TaskCompiler()
Constructs a simple instance.

Method Detail

setTaskRoot

public void setTaskRoot(String pathname)
Sets the pathname of the default file system directory in which task source is found for tasks specified by relative URL.

Parameters:
pathname - The pathname of the directory where tasks specified by relative URL are found.

getTaskRoot

public String getTaskRoot()
Returns the pathname of the file system directory where tasks specified by relative URL are found.

Returns:
The pathname of the directory where tasks specified by relative URL are found.

setCodebase

public void setCodebase(String pathname)
Sets the pathname of the file system root directory of the codebase to which generated code will be written.

Parameters:
pathname - The pathname of the root directory of the codebase.

getCodebase

public String getCodebase()
Returns the pathname of the file system root directory of the codebase to which generated code will be written.

Returns:
The pathname of the root directory of the codebase.

setLog

public void setLog(com.infoengine.log.LogWriter log)
Sets the LogWriter to which log messages will be written.

Parameters:
log - The LogWriter object.

getLog

public com.infoengine.log.LogWriter getLog()
Returns the LogWriter to which log messages are currently written.

Returns:
The current LogWriter.

compile

public Tasklet compile(String url)
                throws IEException,
                       IOException
Compiles a task and returns an instance that can be invoked. If the task has been compiled previously, and its source has not been updated since the last compilation, the task is not recompiled. Instead an instance of the previously compiled task is returned.

Parameters:
url - The URL of the task to be compiled. The URL can be a relative URL that is relative to the task root directory, it can be an LDAP URL that identifies a directory entry and associated attribute containing the source for a task, or it can be an HTTP URL that identifies the source for a task.
Returns:
An instance of the compiled task.
Throws:
IEException - if an error other than an I/O error occurs.
IOException - if an I/O error occurs.

getClassNameForTask

private String getClassNameForTask(String uri)
Return the class name associated with a task URI.

Parameters:
uri - task URI
Returns:
The class name associated with the task URI

getCodebasePathForTask

private String getCodebasePathForTask(String uri)
Return the base pathname of the generated java and class files associated with a task URI.

Parameters:
uri - task URI
Returns:
The base pathname of generated files associated with the URI

loadTask

private Class loadTask(String className,
                       String uri)
                throws IEException
Load the class associated with a specified tasklet.

Parameters:
className - the tasklet class name
uri - the URI of the task source
Returns:
The loaded tasklet class
Throws:
IEException

isTaskStale

private boolean isTaskStale(String uri)
Return true if the specified task file has been modified since the tasklet generated from it was last compiled.

Parameters:
uri - the URI of the task source
Returns:
true if recompilation is indicated

setTaskFileExpiry

private void setTaskFileExpiry(File taskFile)
Sets the expiration on a task file if configured to do so. This avoids checking file timestamps for each invocation which can be expensive on win32.

Parameters:
taskFile - The File object referencing the task.

compileTask

private void compileTask(String className,
                         String uri)
                  throws IEException
Parse task source and produce a Java tasklet from it.

Parameters:
className - the name of the class to be compiled
uri - the URI of the task source
Throws:
IEException

generateJavaSource

private void generateJavaSource(String className,
                                String uri,
                                BufferedReader rdr,
                                PrintWriter pw)
                         throws IEException
Parse a task file and produce a Java source file from it.

Parameters:
className - the name of the class to be generated
uri - the URI of the task for which to generate Java source
rdr - task source file reader
pw - Java output file writer
Throws:
IEException

parseWebject

private String parseWebject(StreamTokenizer tokenizer,
                            String uri,
                            PrintWriter spw,
                            PrintWriter dpw,
                            PrintWriter cpw,
                            TaskCompiler.Tag tag,
                            int indentDepth,
                            int parallelDepth)
                     throws IEException
Parses a WEBJECT tag and generates Java source for it.

Parameters:
tokenizer - The stream tokenizer from which to obtain webject tokens
uri - The URI of the task for which to generate Java source
spw - The PrintWriter on which to write normal text
dpw - The PrintWriter on which to write compiler directives
cpw - The PrintWriter on which to write class-level script text
tag - The webject tag
indentDepth - The current indentation level
parallelDepth - The current nesting level of tags
Returns:
The name of the webject variable assigned to the webject, or "null" if no webject is parsed.
Throws:
IEException

parseTask

private void parseTask(StreamTokenizer tokenizer,
                       String uri,
                       PrintWriter spw,
                       PrintWriter dpw,
                       PrintWriter cpw,
                       TaskCompiler.Tag tag,
                       int indentDepth,
                       int parallelDepth,
                       boolean inheritForm)
                throws IEException
Parses a TASK tag and generates Java source for it.

Parameters:
tokenizer - The stream tokenizer from which to obtain webject tokens
uri - The URI of the task for which to generate Java source
spw - The PrintWriter on which to write script text bracketed by <% and %>
dpw - The PrintWriter on which to write compiler directives
cpw - The PrintWriter on which to write class-level script text
tag - The task tag
indentDepth - The current indentation level
parallelDepth - The current nesting level of tags
inheritForm - true if the new task should inherit the FORM context group of its parent
Throws:
IEException

emitParam

private void emitParam(String wsp,
                       String prefix,
                       TaskCompiler.Tag paramTag,
                       String uri,
                       int lineNumber,
                       PrintWriter pw)
                throws IEException
Emits code to process a webject or task parameter.

Parameters:
wsp - The whitespace indentation.
prefix - The webject or task instance prefix.
paramTag - The parameter tag object instance.
uri - The URI of the task being compiled
pw - The PrintWriter on which to write the code.
Throws:
IEException

parseParamValue

private String parseParamValue(String attr,
                               String data,
                               String deflt,
                               String uri,
                               int lineno,
                               boolean runtimeSubst)
                        throws IEException
Parses a tag attribute value to generate code for special substitution strings and embedded <%= ... %> sequences.

Parameters:
attr - The tag attribute name
data - The value to parse
deflt - The default value for parameters
uri - The URI of the task being compiled
lineno - The current line number being parsed
runtimeSubst - true if runtime resolution of substitution syntax is allowed
Returns:
The parsed and rewritten value
Throws:
IEException

escape

private String escape(String source)
Returns the escaped version of a string that possibly contains characters that aren't suitable as contents of Java source strings, e.g., double quotes and backslashes.

Parameters:
source - The string containing unescaped characters
Returns:
The escaped version of the source

unescape

private String unescape(String source)
Returns the unescaped version of a string that possibly contains escapes for characters that aren't valid characters for Java identifiers.

Parameters:
source - The string containing escaped characters
Returns:
The unescaped version of the source

indent

private String indent(int depth)
Returns a string of blanks reflecting the indenting depth.

Parameters:
depth - The indenting depth
Returns:
The string of blanks