org.eclipse.jet
Class JET2Context

java.lang.Object
  extended byorg.eclipse.jet.JET2Context

public final class JET2Context
extends java.lang.Object

Define the execution context for a JET2 transform or template.


Constructor Summary
JET2Context(java.lang.Object source)
          Create a JET2 context with the specified source argument and no variables.
JET2Context(java.lang.Object source, java.util.Map variables)
          Create a JET2 context with the specified source argument and the specified variables.
 
Method Summary
 java.util.Map extractVariables(java.lang.String variableNames)
          Extract a list of variables from the context
 java.lang.String getJETBundleId()
          Return the id of the JET Bundle defining the current template.
 org.eclipse.emf.common.util.Diagnostic getLogAsMultiStatus()
          Return all logged messages for the transformation as a multi-status IStatus object.
 java.lang.Object getSource()
          Return the source object for the transformation.
 TagFactory getTagFactory()
           
 java.lang.String getTemplatePath()
          Return the path for the executing template.
 java.lang.Object getVariable(java.lang.String var)
          Return the value of a context variable
 java.util.Map getVariables()
          Return a map of all variables currently defined in the context.
 boolean hasContextExtender(java.lang.Class extenderClass)
          Test whether the context has an extender of the pass class.
 boolean hasVariable(java.lang.String var)
          Test whether a variable is defined
 void logError(java.lang.String message)
          Log an error message
 void logError(java.lang.String templatePath, TagInfo tagInfo, java.lang.String message, java.lang.Throwable e)
          Log an error on the pass template
 void logError(java.lang.String message, java.lang.Throwable e)
          Deprecated. Please don't use, will be removed...
 void logError(TagInfo tagInfo, java.lang.String message, java.lang.Throwable exception)
          Log an error from the specified tag.
 void logError(java.lang.Throwable e)
          Log an exeception that occurred during execution
 void logInfo(java.lang.String message)
          Log an informational message
 void logWarning(java.lang.String message)
          Log a warning message
 void removeVariable(java.lang.String var)
          Remove a variable
 void restoreVariables(java.util.Map savedVariableValues)
          Restore variables in the passed map to the context.
 void setJETBundleId(java.lang.String jetBundleId)
          Set the id of the JET Bundle defining the current template.
 void setSource(java.lang.Object source)
          Set the source object for the transformation
 void setTagFactory(TagFactory tagFactory)
           
 void setTemplatePath(java.lang.String templatePath)
          Set the templatePath.
 void setVariable(java.lang.String var, java.lang.Object value)
          Assigne or create a variable, and set its value.
 void setVariables(java.util.Map variablesToPass)
          Set the context variables to only the variables in variablesToPass
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JET2Context

public JET2Context(java.lang.Object source,
                   java.util.Map variables)
Create a JET2 context with the specified source argument and the specified variables.

Parameters:
source - the source object
variables - A map of variable names to the object values.

JET2Context

public JET2Context(java.lang.Object source)
Create a JET2 context with the specified source argument and no variables.

This is exactly equivalent to:

 JET2Context(source, Collections.EMPTY_MAP)
 

Parameters:
source - the source object
Method Detail

setSource

public void setSource(java.lang.Object source)
Set the source object for the transformation

Parameters:
source -

getSource

public java.lang.Object getSource()
Return the source object for the transformation.

Returns:
the source object

getJETBundleId

public java.lang.String getJETBundleId()
Return the id of the JET Bundle defining the current template. Used in generating error messages.

Returns:
the JET Bundle id, or null if not defined.
See Also:
JET2Context.setJETBundleId(String)

setJETBundleId

public void setJETBundleId(java.lang.String jetBundleId)
Set the id of the JET Bundle defining the current template. Used in generating error messages. If not set, then the ID of the JET plugin is used.

Parameters:
jetBundleId - the JET Bundle ide.

logInfo

public void logInfo(java.lang.String message)
Log an informational message

Parameters:
message -

getTemplatePath

public java.lang.String getTemplatePath()
Return the path for the executing template. This is used in creating error messages.

Returns:
the template path or null if no templatePath is defined.
See Also:
JET2Context.setTemplatePath(String)

setTemplatePath

public void setTemplatePath(java.lang.String templatePath)
Set the templatePath. The templatePath is used in generating error messages.

Parameters:
templatePath - the template path or null to indicate no executing template.

logWarning

public void logWarning(java.lang.String message)
Log a warning message

Parameters:
message -

logError

public void logError(java.lang.String message)
Log an error message

Parameters:
message -

logError

public void logError(java.lang.Throwable e)
Log an exeception that occurred during execution

Parameters:
e -

logError

public void logError(java.lang.String message,
                     java.lang.Throwable e)
Deprecated. Please don't use, will be removed...

Log an exception that occured during execution, along with a message.

Parameters:
message -
e -

getLogAsMultiStatus

public org.eclipse.emf.common.util.Diagnostic getLogAsMultiStatus()
Return all logged messages for the transformation as a multi-status IStatus object.

Returns:
the transformation log, as an IStatus

logError

public void logError(TagInfo tagInfo,
                     java.lang.String message,
                     java.lang.Throwable exception)
Log an error from the specified tag.

Parameters:
tagInfo -
message - the error message to display, or null
exception -

hasContextExtender

public boolean hasContextExtender(java.lang.Class extenderClass)
Test whether the context has an extender of the pass class.

Parameters:
extenderClass - the extender class
Returns:
true if the context has a registered extender of the passed class.

logError

public void logError(java.lang.String templatePath,
                     TagInfo tagInfo,
                     java.lang.String message,
                     java.lang.Throwable e)
Log an error on the pass template

Parameters:
templatePath -
tagInfo -
message -
e -

setVariable

public void setVariable(java.lang.String var,
                        java.lang.Object value)
                 throws JET2TagException
Assigne or create a variable, and set its value.

Parameters:
var - the variable name. Cannot be null.
value - the variable value.
Throws:
JET2TagException

getVariable

public java.lang.Object getVariable(java.lang.String var)
                             throws JET2TagException
Return the value of a context variable

Parameters:
var - the variable name
Returns:
the value of the variable
Throws:
JET2TagException - if the variable does not exist.

getVariables

public java.util.Map getVariables()
Return a map of all variables currently defined in the context. The map is a copy of the variables maintained by the context; changes to the map have no affect on the context.

Returns:
a Map of variables, where the key is a variable name, and the value is the variable value.

removeVariable

public void removeVariable(java.lang.String var)
                    throws JET2TagException
Remove a variable

Parameters:
var - the variable name
Throws:
JET2TagException

hasVariable

public boolean hasVariable(java.lang.String var)
Test whether a variable is defined

Parameters:
var - the variable name
Returns:
true if defined, false otherwise.

getTagFactory

public final TagFactory getTagFactory()
Returns:
the tagFactory

setTagFactory

public final void setTagFactory(TagFactory tagFactory)
Parameters:
tagFactory - the tagFactory to set

extractVariables

public java.util.Map extractVariables(java.lang.String variableNames)
                               throws JET2TagException
Extract a list of variables from the context

Parameters:
variableNames - a comma separated list of variables. May be null.
Returns:
a Map keyed by variable name. Will be null if variableNames is null.
Throws:
JET2TagException - if variableNames contains an invalid variable name.

restoreVariables

public void restoreVariables(java.util.Map savedVariableValues)
                      throws JET2TagException
Restore variables in the passed map to the context.

Parameters:
savedVariableValues - a Map keyed by variable name. If null the method does nothing.
Throws:
JET2TagException - if a variable name is invalid

setVariables

public void setVariables(java.util.Map variablesToPass)
                  throws JET2TagException
Set the context variables to only the variables in variablesToPass

Parameters:
variablesToPass - a non-null map keyed by variable name.
Throws:
JET2TagException - if a variable name is invalid

Copyright 2006 IBM Corporation and others.
All Rights Reserved.