org.eclipse.actf.validation.valdoc.codeproc
Class AbstractCodeProcessor

java.lang.Object
  extended by org.eclipse.actf.validation.valdoc.codeproc.AbstractCodeProcessor
All Implemented Interfaces:
ICodeProcessor
Direct Known Subclasses:
AbstractCodeInterpreter

public abstract class AbstractCodeProcessor
extends Object
implements ICodeProcessor

This abstract class implements the basic functionality of a ICodeProcessor whether it be a compiler or interpreter processor. This class should not be extended other than by AbstractCodeInterpreter. Those wishing to implement this functionality in other contexts should extend one of the latter two classes.

Author:
Mike Squillace

Field Summary
protected  String classpath
           
protected  IConfiguration configuration
           
protected  String language
           
protected  IModel model
           
 
Fields inherited from interface org.eclipse.actf.validation.valdoc.codeproc.ICodeProcessor
DEFAULT_CODEPROCESSOR_FACTORY, FACTORY_PROCESSOR_KEY, SCRIPTLANG_ID
 
Constructor Summary
AbstractCodeProcessor(String language, IModel model)
           
 
Method Summary
 void addScript(String scriptName, InputStream scriptStream)
          add the code in the given stream to be executed later by this processor
 void addScripts(Map scriptMap)
          add the given scripts to this compiler for later compilation.
 String getClasspath()
          returns the classpath being used from within script code or to compile source code generated during argument evaluation.
protected  String getFileContents(InputStream file)
           
 String getLanguage()
          get the language identifier for this processor
 IModel getModel()
          return model used by this processor
protected  boolean isIdVisible(String id, String vParam)
          should be called from within setLocal to determine whether or not the id to be declared is visible.
 String[] makeExpressionList(String str)
          split the specified string into "expressions" bounded by the delimiter returned by getExpressionDelimiter.
 String prepareCode(String code)
          prepare code for execution.
 void setClasspath(String cp)
          set the classpath for this processor.
 void setIdVisibility(String visibility)
          set the visibility for symbols in the XML document.
 void setLanguage(String lang)
          set the language identifier for this processor.
 void setModel(IModel model)
          set the model for this processor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.actf.validation.valdoc.codeproc.ICodeProcessor
addScript, addScript, evaluateArguments, evaluateArguments, getEnvironment, getExpressionDelimiter, getInitCode, getScript, isCompilerProcessor, processCode, setEnvironment, setLocal
 

Field Detail

configuration

protected IConfiguration configuration

model

protected IModel model

language

protected String language

classpath

protected String classpath
Constructor Detail

AbstractCodeProcessor

public AbstractCodeProcessor(String language,
                             IModel model)
Method Detail

setModel

public void setModel(IModel model)
set the model for this processor

Specified by:
setModel in interface ICodeProcessor
Parameters:
model - -- model

getModel

public IModel getModel()
return model used by this processor

Specified by:
getModel in interface ICodeProcessor
Returns:
model used by this processor

setClasspath

public void setClasspath(String cp)
set the classpath for this processor. The classpath is used in one of two ways, depending upon the type of processor being used:

The classpath for a processor isnot necessarily the same as that used by ACTF validation engines. A default value is supplied in the ValidationConstants.CODE_PROCESSOR_CLASSPATH_KEY property in the raven.xml file.

Specified by:
setClasspath in interface ICodeProcessor
Parameters:
cp - - classpath to use
See Also:
"resources/raven.xml"

getClasspath

public String getClasspath()
returns the classpath being used from within script code or to compile source code generated during argument evaluation. This classpath is not necessarily the same as that used by the ACTF validation engine.

Specified by:
getClasspath in interface ICodeProcessor
Returns:
classpath being used by underlying interpreter or compiler
See Also:
ICodeProcessor.setClasspath(String)

setLanguage

public void setLanguage(String lang)
set the language identifier for this processor. This should match one of the keys in the 'scriptlang' pool of the actf.xml file.

Specified by:
setLanguage in interface ICodeProcessor
Parameters:
lang - -- language identifier for this processor
See Also:
"resources/actf.xml"

getLanguage

public String getLanguage()
get the language identifier for this processor

Specified by:
getLanguage in interface ICodeProcessor
Returns:
language identifier for this processor

addScript

public void addScript(String scriptName,
                      InputStream scriptStream)
add the code in the given stream to be executed later by this processor

Specified by:
addScript in interface ICodeProcessor
Parameters:
scriptName - -- name of script
scriptStream - -- stream containing code for script

addScripts

public void addScripts(Map scriptMap)
add the given scripts to this compiler for later compilation. The map is typically keyed by script name and contains values holding the code to be executed for event handlers.

Specified by:
addScripts in interface ICodeProcessor
Parameters:
scriptMap - -- map keyed by script names with values containing code to be executed

prepareCode

public String prepareCode(String code)
prepare code for execution. This default implementation resolves entity references and removes CDATA tags. Other preparations can be made by implementations of this method in sub-classes so long as this method is called first.

Specified by:
prepareCode in interface ICodeProcessor
Parameters:
code - -- code to be prepared for execution
Returns:
code readied for execution

setIdVisibility

public void setIdVisibility(String visibility)
                     throws IllegalArgumentException
set the visibility for symbols in the XML document. Visibility determines which (if any) of the symbols declared via the rib:id attribute will be visible in scripts or compiled classes. Options for this parameter include:

The setLocal method of implementations of this interface should take care to set the environment according to the constraints of this property.

Note: Not utilized in ACTF

Specified by:
setIdVisibility in interface ICodeProcessor
Parameters:
visibility - -- one of "ALL", "NONE", or "<reg_expression>"
Throws:
IllegalArgumentException - if argument cannot be processed

isIdVisible

protected boolean isIdVisible(String id,
                              String vParam)
should be called from within setLocal to determine whether or not the id to be declared is visible.

Parameters:
id - -- identifier to be tested
vParam - -- visibility parameter (value of rib:visible attribute if present)

getFileContents

protected String getFileContents(InputStream file)

makeExpressionList

public String[] makeExpressionList(String str)
                            throws IllegalArgumentException
split the specified string into "expressions" bounded by the delimiter returned by getExpressionDelimiter. Although what constitutes an expression is language-dependent, this method will insure that each String in the given list is consistent and complete. The following tokens can be recognized:

The default implementation in both org.eclipse.actf.validation.valdoc.scripting.AbstractCodeInterpreter and org.eclipse.actf.validation.valdoc.scripting.BaseCodeCompiler implement this method in the manner described above.

Specified by:
makeExpressionList in interface ICodeProcessor
Parameters:
str - -- string to be split
Returns:
array of String objects representing tokens in specified string
Throws:
IllegalArgumentException - if symbol mismatch occurs