org.eclipse.emf.codegen.jet
Class JETEmitter

java.lang.Object
  extended by org.eclipse.emf.codegen.jet.JETEmitter

public class JETEmitter
extends java.lang.Object

A convenience class for compiling and invoking a template dynamically.


Nested Class Summary
protected static class JETEmitter.MyBaseJETCompiler
           
protected  class JETEmitter.MyJETCompiler
           
 
Field Summary
protected  java.lang.ClassLoader classLoader
           
protected  java.util.List<org.eclipse.jdt.core.IClasspathEntry> classpathEntries
           
protected  java.lang.String encoding
           
protected  java.util.Map<java.lang.String,java.lang.String> javaOptions
           
protected  java.lang.reflect.Method method
           
protected  java.lang.Object object
           
protected  java.lang.String projectName
           
protected  java.lang.String templateURI
           
protected  java.lang.String[] templateURIPath
           
 
Constructor Summary
JETEmitter(java.lang.String templateURI)
          Creates an instance with the specified template URI.
JETEmitter(java.lang.String[] templateURIPath, java.lang.String relativeTemplateURI)
          Creates an instance with the specified template URI path and relative template URI.
JETEmitter(java.lang.String[] templateURIPath, java.lang.String relativeTemplateURI, java.lang.ClassLoader classLoader)
          Creates an instance with the specified template URI path, relative template URI, and class loader.
JETEmitter(java.lang.String[] templateURIPath, java.lang.String relativeTemplateURI, java.lang.ClassLoader classLoader, java.lang.String encoding)
          Creates an instance with the specified template URI path, relative template URI, class loader, and encoding.
JETEmitter(java.lang.String templateURI, java.lang.ClassLoader classLoader)
          Creates an instance with the specified template URI and class loader.
 
Method Summary
 void addVariable(java.lang.String variableName, java.lang.String pluginID)
          Registers the specified classpath variable in the workspace and adds a classpath entry to the classpath entry list.
 java.lang.String generate(IProgressMonitor progressMonitor, java.lang.Object[] arguments)
          Invokes the emitter method on the compiled template and returns the result.
 java.lang.String generate(Monitor progressMonitor, java.lang.Object[] arguments)
          Invokes the emitter method on the compiled template and returns the result.
 java.lang.String generate(Monitor progressMonitor, java.lang.Object[] arguments, java.lang.String lineDelimiter)
          Invokes the emitter method on the compiled template and returns the result.
 java.util.List<org.eclipse.jdt.core.IClasspathEntry> getClasspathEntries()
          Returns a list of classpath entries that will be added to the classpath of the internal project where emitted JET templates are compiled.
 java.util.Map<java.lang.String,java.lang.String> getJavaOptions()
          Returns options that will be applied to the Java project the first time it's created.
 java.lang.reflect.Method getMethod()
          Returns the method that will be invoked when generate called.
 java.lang.Object getObject()
          Returns the object used as the target for the template.
 java.lang.Object getObject(java.lang.String lineDelimiter)
          Returns the object used as the target for the template; it ensures that the returned object is using the given lineDelimiter and creates a new one if necessary.
 java.lang.String getProjectName()
          Returns the name of the project where JET templates will be compiled.
 void initialize(IProgressMonitor progressMonitor)
          Compiles the template to set the method will be invoked to generate template results.
 void initialize(Monitor progressMonitor)
          Compiles the template to set the method will be invoked to generate template results.
 void setMethod(java.lang.reflect.Method method)
          Set the method that will be invoked when generate called.
 void setObject(java.lang.Object object)
          Sets the object used as the target of the template.
 void setProjectName(java.lang.String projectName)
          Sets the name of the project where JET templates will be compiled.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

projectName

protected java.lang.String projectName

method

protected java.lang.reflect.Method method

object

protected java.lang.Object object

templateURIPath

protected java.lang.String[] templateURIPath

templateURI

protected java.lang.String templateURI

classLoader

protected java.lang.ClassLoader classLoader

encoding

protected java.lang.String encoding

classpathEntries

protected java.util.List<org.eclipse.jdt.core.IClasspathEntry> classpathEntries

javaOptions

protected java.util.Map<java.lang.String,java.lang.String> javaOptions
Constructor Detail

JETEmitter

public JETEmitter(java.lang.String templateURI)
Creates an instance with the specified template URI.

Parameters:
templateURI - the URI of a JET template.

JETEmitter

public JETEmitter(java.lang.String[] templateURIPath,
                  java.lang.String relativeTemplateURI)
Creates an instance with the specified template URI path and relative template URI. The relative URI will be resolved against each path URI until a JET template is found.

Parameters:
templateURIPath - a sequence of URIs that will be searched.
relativeTemplateURI - the relative URI of a JET template.

JETEmitter

public JETEmitter(java.lang.String templateURI,
                  java.lang.ClassLoader classLoader)
Creates an instance with the specified template URI and class loader.

Parameters:
templateURI - the URI of a JET template.
classLoader - the class loader used to load classes when compiling the template.

JETEmitter

public JETEmitter(java.lang.String[] templateURIPath,
                  java.lang.String relativeTemplateURI,
                  java.lang.ClassLoader classLoader)
Creates an instance with the specified template URI path, relative template URI, and class loader. The relative URI will be resolved against each path URI until a JET template is found.

Parameters:
templateURIPath - a sequence of URIs that will be searched.
relativeTemplateURI - the relative URI of a JET template.
classLoader - the class loader used to load classes when compiling the template.

JETEmitter

public JETEmitter(java.lang.String[] templateURIPath,
                  java.lang.String relativeTemplateURI,
                  java.lang.ClassLoader classLoader,
                  java.lang.String encoding)
Creates an instance with the specified template URI path, relative template URI, class loader, and encoding. The relative URI will be resolved against each path URI until a JET template is found.

Parameters:
templateURIPath - a sequence of URIs that will be searched.
relativeTemplateURI - the relative URI of a JET template.
classLoader - the class loader used to load classes when compiling the template.
encoding - the encoding that will be used to read the templates.
Method Detail

getProjectName

public java.lang.String getProjectName()
Returns the name of the project where JET templates will be compiled.

Returns:
the name of the project where JET templates will be compiled.

setProjectName

public void setProjectName(java.lang.String projectName)
Sets the name of the project where JET templates will be compiled.

Parameters:
projectName - the name of the project.

getClasspathEntries

public java.util.List<org.eclipse.jdt.core.IClasspathEntry> getClasspathEntries()
Returns a list of classpath entries that will be added to the classpath of the internal project where emitted JET templates are compiled.

This method must be called before initialize or generate are called.

Returns:
a list of classpath entries.

getJavaOptions

public java.util.Map<java.lang.String,java.lang.String> getJavaOptions()
Returns options that will be applied to the Java project the first time it's created.

Returns:
the Java options.

getObject

public java.lang.Object getObject()
Returns the object used as the target for the template.

Returns:
the object used as target for the template.

getObject

public java.lang.Object getObject(java.lang.String lineDelimiter)
Returns the object used as the target for the template; it ensures that the returned object is using the given lineDelimiter and creates a new one if necessary.

Returns:
the object used as target for the template.
Since:
2.3

setObject

public void setObject(java.lang.Object object)
Sets the object used as the target of the template.

Parameters:
object - the object used as target of the template.

getMethod

public java.lang.reflect.Method getMethod()
Returns the method that will be invoked when generate called.

Returns:
the generator method.

setMethod

public void setMethod(java.lang.reflect.Method method)
Set the method that will be invoked when generate called.

Parameters:
method - the generator method.

initialize

public void initialize(IProgressMonitor progressMonitor)
                throws JETException
Compiles the template to set the method will be invoked to generate template results.

Parameters:
progressMonitor - the progress monitor for tracking progress.
Throws:
JETException

initialize

public void initialize(Monitor progressMonitor)
                throws JETException
Compiles the template to set the method will be invoked to generate template results.

Parameters:
progressMonitor - the progress monitor for tracking progress.
Throws:
JETException

addVariable

public void addVariable(java.lang.String variableName,
                        java.lang.String pluginID)
                 throws JETException
Registers the specified classpath variable in the workspace and adds a classpath entry to the classpath entry list. The variable is bound to the first runtime library JAR file in the list of runtime libraries of the specified plugin. When generate is called and it needs to generate the method to invoke, it will call initialize which will add the classpath entries to the project created to hold and compile the emitted template.

This method must be called before initialize or generate are called.

The specified plugin ID must be the ID of an existing plugin. The referenced plugin must have at least one runtime library JAR file in its plugin descriptor. If the plugin descriptor's list of runtime libraries contains more than one JAR file, the classpath variable will be bound to the first library in the list.

Parameters:
variableName - name of the classpath variable
pluginID - the ID of an existing plugin
Throws:
JETException

generate

public java.lang.String generate(IProgressMonitor progressMonitor,
                                 java.lang.Object[] arguments)
                          throws JETException
Invokes the emitter method on the compiled template and returns the result.

Returns:
the template result.
Throws:
JETException

generate

public java.lang.String generate(Monitor progressMonitor,
                                 java.lang.Object[] arguments)
                          throws JETException
Invokes the emitter method on the compiled template and returns the result.

Returns:
the template result.
Throws:
JETException

generate

public java.lang.String generate(Monitor progressMonitor,
                                 java.lang.Object[] arguments,
                                 java.lang.String lineDelimiter)
                          throws JETException
Invokes the emitter method on the compiled template and returns the result.

Returns:
the template result.
Throws:
JETException
Since:
2.3

Copyright 2001-2006 IBM Corporation and others.
All Rights Reserved.