org.eclipse.jet.transform
Class TransformContextExtender

java.lang.Object
  extended by org.eclipse.jet.transform.TransformContextExtender

public final class TransformContextExtender
extends java.lang.Object

Extender to the JET2Context for supporting JET2 Transforms


Constructor Summary
TransformContextExtender(JET2Context context)
          Deprecated. Since 0.9.0 use getInstance(JET2Context).
 
Method Summary
 void addListener(TransformContextListener listener)
          Add a listener to the merge context events (commit, logStatistics, getSummary)
 void checkCanceled()
          Check whether the transformation has been canceled and throw a OperationCanceledException if so.
 void cleanup()
           
 void commit(org.eclipse.core.runtime.IProgressMonitor monitor)
          Commit changes.
 void execute(java.lang.String templatePath, boolean useSuper, JET2Writer writer)
          Execute the named template, writing all template output to the passed writer.
 void execute(java.lang.String templatePath, JET2Writer writer)
          Execute the named template, writing all template output to the passed writer.
 java.net.URL getBaseURL(java.lang.String urlContext)
          Return the base URL to use given an urlContext constant.
 IJETBundleDescriptor getBundleDescriptor()
          Return the bundle descriptor of the JET transform bundle.
 java.lang.String getId()
           
static TransformContextExtender getInstance(JET2Context context)
          Return the TransformContextExtender for the passed context.
 JET2TemplateLoader getLoader()
           
 java.lang.Object getShellContext()
          Return the current shell context or null if none is set
 java.lang.String getTemplatePath()
          Return the path of the current executing template
 boolean isCanceled()
          Test whether the transformation has been canceled.
static java.lang.Object loadModel(java.net.URL modelURL, java.lang.String modelLoaderID, java.lang.String fileType)
          Load a model, given an URL to a model, and optionally the model loader and the file type of the model.
static java.lang.Object loadModelFromString(java.lang.String modelContent, java.lang.String modelLoaderID, java.lang.String fileType)
          Load a model from a string form.
 void removeListener(TransformContextListener listener)
          Remove a listener of merge context events.
 void runSubTransform(java.lang.String id)
          Invoke another JET transformation
 void runSubTransform(java.lang.String id, BodyContentWriter writer)
          Invoke another JET transformation, recording the main template results in the specified writer
 void setBundleDescriptor(IJETBundleDescriptor descriptor)
          Set the description of the transform bundle.
 void setLoader(JET2TemplateLoader loader)
          Set the template loader
 void setOverride(java.lang.String id, org.eclipse.core.runtime.IProgressMonitor monitor)
           
 void setProgressMonitor(org.eclipse.core.runtime.IProgressMonitor monitor)
          Provide a progress monitor for template execution.
 void setShellContext(java.lang.Object shellContext)
          Set the org.eclipse.swt.widgets.Shell in which any dialogs should be open.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransformContextExtender

public TransformContextExtender(JET2Context context)
Deprecated. Since 0.9.0 use getInstance(JET2Context).

Create a TransformContextExtender for the current context.

Parameters:
context - the context.
Method Detail

getId

public java.lang.String getId()

getTemplatePath

public java.lang.String getTemplatePath()
Return the path of the current executing template

Returns:
the current template path or the empty string if there is not currently executing template

execute

public void execute(java.lang.String templatePath,
                    JET2Writer writer)
             throws JET2TagException
Execute the named template, writing all template output to the passed writer. Equivalent to execute(templatePath, false, writer).

Parameters:
templatePath - the project relative path of the template to load
writer - the writer to which the template output will be written
Throws:
JET2TagException - if an execution error occurs
See Also:
execute(String, boolean, JET2Writer)

checkCanceled

public void checkCanceled()
Check whether the transformation has been canceled and throw a OperationCanceledException if so.


isCanceled

public boolean isCanceled()
Test whether the transformation has been canceled.

Returns:
true if the transformation has been canceled, false otherwise

setProgressMonitor

public void setProgressMonitor(org.eclipse.core.runtime.IProgressMonitor monitor)
Provide a progress monitor for template execution. If provided, templates are executed with a progress monitor and may through an OperationCanceledException. Note that clients typically do not need to call this method as it is initialized from JET2Platform.runTransform(String, JET2Context, IProgressMonitor) and its variants.

Parameters:
monitor - a progress monitor
Throws:
java.lang.IllegalStateException - if a progress monitor has already been installed
See Also:
execute(String, JET2Writer), execute(String, boolean, JET2Writer), checkCanceled(), isCanceled()

execute

public void execute(java.lang.String templatePath,
                    boolean useSuper,
                    JET2Writer writer)
             throws JET2TagException
Execute the named template, writing all template output to the passed writer. If the transformation context executing this method has passed a progress monitor, then an appropriate subprogress monitor will be created for this template.

Parameters:
templatePath - the project relative path of the template to load
useSuper - if true, attempt to load the template from override transformation, if it exists
writer - the writer to which the template output will be written
Throws:
JET2TagException - if an execution error occurs or the template cannot be found
See Also:
setProgressMonitor(IProgressMonitor)

getLoader

public JET2TemplateLoader getLoader()

setLoader

public void setLoader(JET2TemplateLoader loader)
Set the template loader

Parameters:
loader -

addListener

public void addListener(TransformContextListener listener)
Add a listener to the merge context events (commit, logStatistics, getSummary)

Parameters:
listener -

removeListener

public void removeListener(TransformContextListener listener)
Remove a listener of merge context events.

Parameters:
listener -
See Also:
addListener(TransformContextListener)

commit

public void commit(org.eclipse.core.runtime.IProgressMonitor monitor)
Commit changes.

Parameters:
monitor - a progress monitor

getShellContext

public final java.lang.Object getShellContext()
Return the current shell context or null if none is set

Returns:
Returns the shellContext.
See Also:
getShellContext()

setShellContext

public final void setShellContext(java.lang.Object shellContext)
Set the org.eclipse.swt.widgets.Shell in which any dialogs should be open. If null is passed, or if this method is not called, then no dialogs will be displayed, and the transformation will make suitable choices in lieu of displaying a dialog.

An Object is passed to avoid dependencies on the SWT plugins. This method is used primarily to support the use of IWorkspace.validateEdit(org.eclipse.core.resources.IFile[], java.lang.Object) although the shell context may be used by other task, too.

Parameters:
shellContext - The shellContext to set, which must be null or an instance of org.eclipse.swt.widgets.Shell.

setBundleDescriptor

public void setBundleDescriptor(IJETBundleDescriptor descriptor)
Set the description of the transform bundle.

Parameters:
descriptor - the bundle descriptor.
Throws:
java.lang.IllegalStateException - if the bundle descriptor has already been set.

getBundleDescriptor

public IJETBundleDescriptor getBundleDescriptor()
Return the bundle descriptor of the JET transform bundle.

Returns:
a bundle descriptor

getBaseURL

public java.net.URL getBaseURL(java.lang.String urlContext)
                        throws JET2TagException
Return the base URL to use given an urlContext constant. The supported URL contexts are:
  • "transform" - relative to the currently executing transform
  • "workspace" - relative to the current eclipse workspace
  • null - equivalent to "transform"
  • Parameters:
    urlContext - one of "transform", "workspace" or null
    Returns:
    the base URL
    Throws:
    JET2TagException

    getInstance

    public static TransformContextExtender getInstance(JET2Context context)
    Return the TransformContextExtender for the passed context.

    Parameters:
    context - a JET context
    Returns:
    the TransformContextExtender

    loadModel

    public static java.lang.Object loadModel(java.net.URL modelURL,
                                             java.lang.String modelLoaderID,
                                             java.lang.String fileType)
                                      throws java.io.IOException,
                                             CoreJETException
    Load a model, given an URL to a model, and optionally the model loader and the file type of the model.

    Parameters:
    modelURL - the URL of the model to load
    modelLoaderID - the model loader id, or null if the model loader is to be determined from the file type.
    fileType - the file type to use in selecting the model loader, or null if the file type is to be extracted from the model URL (by finding a file extension).
    Returns:
    the root of the loaded model
    Throws:
    java.io.IOException - if the model could not be read.
    CoreJETException - if an appropriate model loader could not be found.

    loadModelFromString

    public static java.lang.Object loadModelFromString(java.lang.String modelContent,
                                                       java.lang.String modelLoaderID,
                                                       java.lang.String fileType)
                                                throws CoreJETException,
                                                       java.io.IOException
    Load a model from a string form.

    Parameters:
    modelContent - the model content, in its string form.
    modelLoaderID - the model loader id, or null if the loader is to be calculated from the file type.
    fileType - the type of the file to load, or null if the type is irrelevant to the loader.
    Returns:
    the root of the loaded model
    Throws:
    CoreJETException - if an appropriate model loader could not be found.
    java.io.IOException - if the model could not be read.

    setOverride

    public void setOverride(java.lang.String id,
                            org.eclipse.core.runtime.IProgressMonitor monitor)
                     throws JET2TagException
    Throws:
    JET2TagException

    cleanup

    public void cleanup()

    runSubTransform

    public void runSubTransform(java.lang.String id)
                         throws JET2TagException
    Invoke another JET transformation

    Parameters:
    id - the JET transformation ID
    Throws:
    JET2TagException - if an execution error occurs

    runSubTransform

    public void runSubTransform(java.lang.String id,
                                BodyContentWriter writer)
                         throws JET2TagException
    Invoke another JET transformation, recording the main template results in the specified writer

    Parameters:
    id - the JET transformation ID
    writer - a template writer
    Throws:
    JET2TagException - if an execution error occurs

    Copyright 2006 IBM Corporation and others.
    All Rights Reserved.