org.eclipse.mofscript.runtime
Class ExecutionEnvironment

java.lang.Object
  extended by org.eclipse.mofscript.runtime.ExecutionEnvironment
Direct Known Subclasses:
TraceabilityEnvironment

public class ExecutionEnvironment
extends java.lang.Object

Handels the 'memory' during execution. Stores variables, handles file streams etc. Part of the RuleExecutionStack

Author:
Jon Oldevik

Field Summary
protected static long _blockCounter
           
protected  java.io.OutputStream _currentStream
           
protected  boolean _inPrintAction
           
protected  java.util.HashMap<java.lang.String,java.lang.Object> _inputobjects
           
protected static int _lineNumber
           
protected  java.lang.String _objectId
           
protected static java.util.Hashtable<java.io.OutputStream,TraceabilityEnvironment.OffsetCounter> _offsets
           
protected static java.lang.String _openFileUri
           
protected  ExecutionEnvironment _parentEnv
           
protected static java.util.HashMap<java.io.OutputStream,java.io.PrintStream> _printStreams
           
protected static java.util.HashMap<java.lang.String,java.lang.String> _streamContexts
           
protected static java.util.HashMap<java.lang.String,java.io.OutputStream> _streams
           
protected static boolean _traceValue
           
 
Constructor Summary
ExecutionEnvironment()
          Default constructor
 
Method Summary
static void addBreakPoint(int lineNo, java.lang.String file)
           
 void addInputObject(java.lang.String name, java.lang.Object obj)
          Adds an input object
 void addModelVariables(java.util.List<VariableDeclaration> variables, MOFScriptObject owner)
           
protected  java.io.OutputStream addOutputStream(java.lang.String uri, java.io.OutputStream stream, java.lang.String context, boolean append)
          Adds an output stream
 void addVariable(Variable var)
           
 void addVariables(java.util.List<Variable> variables)
          Adds a list of variables (includes checking for exsistence)
 java.lang.Object assignVariableValue(java.lang.String varName, java.lang.Object value, AssignmentOperator operator, Expression assignedExpression, org.eclipse.emf.ecore.EObject varContext)
          Assignes a value to a variable
 java.lang.Object assignVariableValue(Variable var, java.lang.Object value, Expression assignedExpression, AssignmentOperator operator)
           
 void clean()
          Cleans current streams, streams and calls cleanLocal
protected  void cleanLocal()
          Cleans the environment
static void cleanResources()
          Clears the resources
 void clearInputObject(java.lang.String name)
          Clears an object with a given name
 void clearReferenceCache()
          Clears all cached refrences
static void contDebug()
           
 void endUnprotectedBlock()
           
(package private)  void evaluateVariables(RuleExecutor rExec)
           
protected  void finalize()
          Calls cleanLocal and finalizes
 Variable findVariable(java.lang.String varName, org.eclipse.emf.ecore.EObject varContext)
          Searches for a given variable name
static java.lang.Object getAssignValue(java.lang.String type, java.lang.Object input, java.lang.Object assignValue, AssignmentOperator operator)
          Returns the assign value
 java.lang.Object getCachedReference(java.lang.String refName)
          Retrieves an already chached refrence as an object
static boolean getContDebug()
           
 java.io.PrintStream getCurrentPrintStream()
           
 java.io.OutputStream getCurrentStream()
           
protected  java.lang.String getCurrentStreamUri()
          Gets the current stream's URI
 FileResourcesType getFileModel()
          Iterats the generated results and populates a EMF File Model (the frm model)
static java.lang.String getIndent()
          Returns the indent string
 java.lang.Object getInputObject(java.lang.String name)
          Gets an input object
 int getIteratorCount()
          The counter for an iterator index in a forEach The counter value is relative to the filter applied
 int getIteratorPosition()
          The "position" of an iterator index in a forEach iterator statement, relative to the full contents of the source of the iterator - i.e. ignoring any filter on the iterator
 int getLineNumber()
          Traceability testing
 java.io.OutputStream getOutputStream(java.lang.String uri)
          Gets the output stream from the environment, if null returns the parent environment's output stream
protected  java.io.OutputStream getOutputStreamForContext(java.lang.String context)
          Gets an output stream for a given context
 ExecutionEnvironment getParentEnvironment()
          Gets the execution environment's parent environment
protected  java.io.PrintStream getPrintStreamForContext(java.lang.String context)
           
static java.util.Vector<java.lang.String> getResources()
           
static boolean getStepDebug()
           
static boolean getStopDebug()
           
 boolean getTrace()
           
 boolean getUseFileModel()
          The value of useFileModel defines if a file model is used rather than physical files
 boolean getUseLog()
           
 Variable getVariable(java.lang.String varName, org.eclipse.emf.ecore.EObject varContext)
          Fetches a variable by name
 java.lang.Object getVariableImplementation(java.lang.String varName, org.eclipse.emf.ecore.EObject varContext)
           
 java.lang.Object getVariableImplementation(Variable var)
           
 java.util.Collection<Variable> getVariables()
           
 java.lang.Object getVariableValue(java.lang.String varName)
           
 void increaseIteratorCount()
          Increases iterator counter
 void increaseIteratorPosition()
          Increase position counter
static void increaseLineNumber(java.lang.String s)
          Traceability testing Handels line number in file
static void indent()
          Increases the indentation for printing
 void initIteratorCounters()
          Resets itarator counters
static boolean isBreakPoint(int lineNo, java.lang.String context)
           
static boolean isDebugging()
           
 boolean isInPrintAction()
          Checks if execution is in print action
 boolean isUnprotectedBlock()
          Checks if a block is unprotected
 void log(java.lang.String s)
          Logs the string with date
 void notifyError(java.lang.String error, ExpressionEvaluator expEval)
           
 void notifyMessage(java.lang.String msg)
          notifies about some events....
 void print(java.lang.String s, boolean println)
          Prints a string to the correct context
 void println(java.lang.String s)
          Prints the string s
static void removeBreakPointAt(int lineNo, java.lang.String file)
          Removes a break point at a specific line in a specific resource
static void removeBreakPoints()
           
 void removeVariable(Variable var)
          Removes a given Variable completely from the var storage
static void resetBlockCounter()
           
static void resetDebug()
           
 void saveTargetModel(java.lang.String fileLoc, org.eclipse.emf.ecore.EObject model, org.eclipse.emf.ecore.resource.Resource originalResource, org.eclipse.emf.ecore.EObject originalModel)
           
 void setCachedReference(java.lang.String refname, java.lang.Object value)
          Puts a refrence into the cache
 void setCurrentStream(java.lang.String contextReference)
          Set the current stream
 void setCurrentStream(java.lang.String uri, java.lang.String context, boolean append)
          Creates a new file and stream
static void setDebug(boolean tf)
           
 void setInPrintAction(boolean inPrintAction)
          Sets the _inPrintAction flag
 void setOwnerStack(RuleExecutionStack stack)
          Sets the owner stack
 void setParentEnvironment(ExecutionEnvironment parent)
          Sets the parent environment
static void setPrintContext(java.lang.String context)
          Sets the print context
 void setRootDirectory(java.lang.String rootDir)
          Defines the root directory for file generation
static void setStepDebug(boolean tf)
           
static void setTrace(boolean tV)
          Traceability testing Set if print statement and not stdout
 void setTypeForVariable(Variable varDecl, java.lang.Object varValue)
          Sets the type of a variable
 void setUnprotectedBlock(boolean unprotected)
           
 void setUseFileModel(boolean useModel)
          Defines if a file model shall be used rather than writing to physical files.
 void setUseLog(boolean useLog)
          Defines the execution should use a system log or not.
 void setUseParentCache(boolean useParentCache)
          Sets if the parent cache is to be used
 void setVariable(java.lang.String varName, Variable val)
          Puts the variable into the _variables Hashtable
 void startUnprotectedBlock(java.lang.String objectUri)
           
static void stopDebug()
           
 void storeFiles()
          Stores the OutputStream
 void storeInputObject(java.lang.Object ret)
           
 void storeResource(org.eclipse.emf.ecore.resource.Resource toStore)
          Stores a resorce to its current location
 void storeResource(org.eclipse.emf.ecore.resource.Resource toStore, java.lang.String newLoc)
          Stores a resource to a new location
static void undent()
          Decreases the indentation for printing
static boolean useIndent()
          Whether indenting is used or not
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_inputobjects

protected java.util.HashMap<java.lang.String,java.lang.Object> _inputobjects

_streams

protected static java.util.HashMap<java.lang.String,java.io.OutputStream> _streams

_printStreams

protected static java.util.HashMap<java.io.OutputStream,java.io.PrintStream> _printStreams

_streamContexts

protected static java.util.HashMap<java.lang.String,java.lang.String> _streamContexts

_parentEnv

protected ExecutionEnvironment _parentEnv

_currentStream

protected java.io.OutputStream _currentStream

_lineNumber

protected static int _lineNumber

_offsets

protected static java.util.Hashtable<java.io.OutputStream,TraceabilityEnvironment.OffsetCounter> _offsets

_traceValue

protected static boolean _traceValue

_inPrintAction

protected boolean _inPrintAction

_openFileUri

protected static java.lang.String _openFileUri

_blockCounter

protected static long _blockCounter

_objectId

protected java.lang.String _objectId
Constructor Detail

ExecutionEnvironment

public ExecutionEnvironment()
Default constructor

Method Detail

setUseFileModel

public void setUseFileModel(boolean useModel)
Defines if a file model shall be used rather than writing to physical files.

Parameters:
useModel -

getUseFileModel

public boolean getUseFileModel()
The value of useFileModel defines if a file model is used rather than physical files

Returns:
boolean value

addBreakPoint

public static void addBreakPoint(int lineNo,
                                 java.lang.String file)
Parameters:
lineNo -
file -

removeBreakPoints

public static void removeBreakPoints()

removeBreakPointAt

public static void removeBreakPointAt(int lineNo,
                                      java.lang.String file)
Removes a break point at a specific line in a specific resource

Parameters:
lineNo -
file -

isBreakPoint

public static boolean isBreakPoint(int lineNo,
                                   java.lang.String context)
Parameters:
lineNo -
context -
Returns:

setDebug

public static void setDebug(boolean tf)
Parameters:
tf -

isDebugging

public static boolean isDebugging()
Returns:

getStopDebug

public static boolean getStopDebug()
Returns:

getContDebug

public static boolean getContDebug()
Returns:

setStepDebug

public static void setStepDebug(boolean tf)

getStepDebug

public static boolean getStepDebug()

stopDebug

public static void stopDebug()

contDebug

public static void contDebug()

resetDebug

public static void resetDebug()

setUseLog

public void setUseLog(boolean useLog)
Defines the execution should use a system log or not.

Parameters:
useLog -

getUseLog

public boolean getUseLog()
Returns:
true if execution is set to use log

getFileModel

public FileResourcesType getFileModel()
Iterats the generated results and populates a EMF File Model (the frm model)

Returns:
the file model

setRootDirectory

public void setRootDirectory(java.lang.String rootDir)
Defines the root directory for file generation

Parameters:
rootDir -

indent

public static void indent()
Increases the indentation for printing


undent

public static void undent()
Decreases the indentation for printing


getIndent

public static java.lang.String getIndent()
Returns the indent string

Returns:

useIndent

public static boolean useIndent()
Whether indenting is used or not

Returns:
true if indent is used

getVariable

public Variable getVariable(java.lang.String varName,
                            org.eclipse.emf.ecore.EObject varContext)
Fetches a variable by name

Parameters:
varName -
Returns:
variable or null

getVariables

public java.util.Collection<Variable> getVariables()
Returns:

notifyMessage

public void notifyMessage(java.lang.String msg)
notifies about some events....

Parameters:
msg -

notifyError

public void notifyError(java.lang.String error,
                        ExpressionEvaluator expEval)
Parameters:
error -

getIteratorCount

public int getIteratorCount()
The counter for an iterator index in a forEach The counter value is relative to the filter applied

Returns:

getIteratorPosition

public int getIteratorPosition()
The "position" of an iterator index in a forEach iterator statement, relative to the full contents of the source of the iterator - i.e. ignoring any filter on the iterator

Returns:

initIteratorCounters

public void initIteratorCounters()
Resets itarator counters


increaseIteratorCount

public void increaseIteratorCount()
Increases iterator counter


increaseIteratorPosition

public void increaseIteratorPosition()
Increase position counter


getVariableValue

public java.lang.Object getVariableValue(java.lang.String varName)
Parameters:
varName -
Returns:

getVariableImplementation

public java.lang.Object getVariableImplementation(Variable var)
Parameters:
var -
Returns:

getVariableImplementation

public java.lang.Object getVariableImplementation(java.lang.String varName,
                                                  org.eclipse.emf.ecore.EObject varContext)
Returns:

setTypeForVariable

public void setTypeForVariable(Variable varDecl,
                               java.lang.Object varValue)
Sets the type of a variable

Parameters:
varDecl -
varValue -

assignVariableValue

public java.lang.Object assignVariableValue(java.lang.String varName,
                                            java.lang.Object value,
                                            AssignmentOperator operator,
                                            Expression assignedExpression,
                                            org.eclipse.emf.ecore.EObject varContext)
Assignes a value to a variable

Parameters:
varName -
value -

assignVariableValue

public java.lang.Object assignVariableValue(Variable var,
                                            java.lang.Object value,
                                            Expression assignedExpression,
                                            AssignmentOperator operator)
Parameters:
var -
val -
Returns:

getAssignValue

public static java.lang.Object getAssignValue(java.lang.String type,
                                              java.lang.Object input,
                                              java.lang.Object assignValue,
                                              AssignmentOperator operator)
Returns the assign value

Parameters:
input -
assignValue -
operator -
Returns:

setVariable

public void setVariable(java.lang.String varName,
                        Variable val)
Puts the variable into the _variables Hashtable

Parameters:
varName -
val -

findVariable

public Variable findVariable(java.lang.String varName,
                             org.eclipse.emf.ecore.EObject varContext)
Searches for a given variable name

Parameters:
varName -
Returns:
a variable declaration if foun, else NULL

getParentEnvironment

public ExecutionEnvironment getParentEnvironment()
Gets the execution environment's parent environment

Returns:
the parent environment

setParentEnvironment

public void setParentEnvironment(ExecutionEnvironment parent)
Sets the parent environment

Parameters:
parent -

setOwnerStack

public void setOwnerStack(RuleExecutionStack stack)
Sets the owner stack

Parameters:
stack -

addVariables

public void addVariables(java.util.List<Variable> variables)
Adds a list of variables (includes checking for exsistence)

Parameters:
variables -

addVariable

public void addVariable(Variable var)
Parameters:
var -

addModelVariables

public void addModelVariables(java.util.List<VariableDeclaration> variables,
                              MOFScriptObject owner)
Parameters:
variables -

evaluateVariables

void evaluateVariables(RuleExecutor rExec)
Parameters:
rExec -

removeVariable

public void removeVariable(Variable var)
Removes a given Variable completely from the var storage

Parameters:
var -

getInputObject

public java.lang.Object getInputObject(java.lang.String name)
Gets an input object

Parameters:
name -
Returns:

storeInputObject

public void storeInputObject(java.lang.Object ret)

addInputObject

public void addInputObject(java.lang.String name,
                           java.lang.Object obj)
Adds an input object

Parameters:
name -
obj -

clearInputObject

public void clearInputObject(java.lang.String name)
Clears an object with a given name

Parameters:
name -

setUseParentCache

public void setUseParentCache(boolean useParentCache)
Sets if the parent cache is to be used

Parameters:
useParentCache -

getCachedReference

public java.lang.Object getCachedReference(java.lang.String refName)
Retrieves an already chached refrence as an object

Parameters:
refName -
Returns:
a refrence with the given name

setCachedReference

public void setCachedReference(java.lang.String refname,
                               java.lang.Object value)
Puts a refrence into the cache

Parameters:
refname -
value -

clearReferenceCache

public void clearReferenceCache()
Clears all cached refrences


addOutputStream

protected java.io.OutputStream addOutputStream(java.lang.String uri,
                                               java.io.OutputStream stream,
                                               java.lang.String context,
                                               boolean append)
Adds an output stream

Parameters:
uri -
stream -
context -
Returns:
An output stream

getOutputStreamForContext

protected java.io.OutputStream getOutputStreamForContext(java.lang.String context)
Gets an output stream for a given context

Parameters:
context -
Returns:
An output stream or NULL

getPrintStreamForContext

protected java.io.PrintStream getPrintStreamForContext(java.lang.String context)
Parameters:
context -
Returns:

getOutputStream

public java.io.OutputStream getOutputStream(java.lang.String uri)
Gets the output stream from the environment, if null returns the parent environment's output stream

Parameters:
uri -
Returns:
An output stream or NULL

setCurrentStream

public void setCurrentStream(java.lang.String uri,
                             java.lang.String context,
                             boolean append)
Creates a new file and stream

Parameters:
uri -
context -

setCurrentStream

public void setCurrentStream(java.lang.String contextReference)
Set the current stream

Parameters:
contextReference -

getCurrentStream

public java.io.OutputStream getCurrentStream()
Returns:
The current stream

getCurrentPrintStream

public java.io.PrintStream getCurrentPrintStream()
Returns:
PrintStream

getCurrentStreamUri

protected java.lang.String getCurrentStreamUri()
Gets the current stream's URI

Returns:
String containing URI or NULL

storeFiles

public void storeFiles()
Stores the OutputStream


clean

public void clean()
Cleans current streams, streams and calls cleanLocal


cleanLocal

protected void cleanLocal()
Cleans the environment


setPrintContext

public static void setPrintContext(java.lang.String context)
Sets the print context

Parameters:
context -

print

public void print(java.lang.String s,
                  boolean println)
Prints a string to the correct context

Parameters:
s -
println -

log

public void log(java.lang.String s)
Logs the string with date

Parameters:
s -

println

public void println(java.lang.String s)
Prints the string s

Parameters:
s -

getResources

public static java.util.Vector<java.lang.String> getResources()
Returns:
A (String) list of produced resources (files) (their names)

cleanResources

public static void cleanResources()
Clears the resources


finalize

protected void finalize()
                 throws java.lang.Throwable
Calls cleanLocal and finalizes

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

setInPrintAction

public void setInPrintAction(boolean inPrintAction)
Sets the _inPrintAction flag

Parameters:
inPrintAction -

isInPrintAction

public boolean isInPrintAction()
Checks if execution is in print action

Returns:

setTrace

public static void setTrace(boolean tV)
Traceability testing Set if print statement and not stdout

Parameters:
tV -

getTrace

public boolean getTrace()

increaseLineNumber

public static void increaseLineNumber(java.lang.String s)
Traceability testing Handels line number in file

Parameters:
s -

getLineNumber

public int getLineNumber()
Traceability testing

Returns:

resetBlockCounter

public static void resetBlockCounter()

startUnprotectedBlock

public void startUnprotectedBlock(java.lang.String objectUri)
Parameters:
objectUri -

endUnprotectedBlock

public void endUnprotectedBlock()

isUnprotectedBlock

public boolean isUnprotectedBlock()
Checks if a block is unprotected

Returns:
(true or false) the value of the variable _unprotectedBlock

setUnprotectedBlock

public void setUnprotectedBlock(boolean unprotected)

saveTargetModel

public void saveTargetModel(java.lang.String fileLoc,
                            org.eclipse.emf.ecore.EObject model,
                            org.eclipse.emf.ecore.resource.Resource originalResource,
                            org.eclipse.emf.ecore.EObject originalModel)
Parameters:
targetFile -
model -
originalResource - --> the resource that was associated the model originally

storeResource

public void storeResource(org.eclipse.emf.ecore.resource.Resource toStore)
Stores a resorce to its current location

Parameters:
toStore -

storeResource

public void storeResource(org.eclipse.emf.ecore.resource.Resource toStore,
                          java.lang.String newLoc)
Stores a resource to a new location