org.eclipse.emf.codegen.ecore.generator
Class AbstractGeneratorAdapter

java.lang.Object
  extended by org.eclipse.emf.common.notify.impl.SingletonAdapterImpl
      extended by org.eclipse.emf.codegen.ecore.generator.AbstractGeneratorAdapter
All Implemented Interfaces:
GeneratorAdapter, Adapter, Adapter.Internal
Direct Known Subclasses:
GenBaseGeneratorAdapter

public abstract class AbstractGeneratorAdapter
extends SingletonAdapterImpl
implements GeneratorAdapter

A base GeneratorAdapter implementation. This base provides support for JET-based generation of Java and other text artifacts, as well as GIFEmitter-based colourization of icons, via the following methods:

Code generation is supported in the Eclipse IDE or stand-alone. However, merging and formatting of Java code are not available in the latter scenario.

At a minimum, subclasses must implement canGenerate(Object, Object), to determine whether code can be generated for an object, and doGenerate(), to actually generate code for it.

They may also override getCanGenerateChildren(Object, Object), getCanGenerateParent(Object, Object), getGenerateChildren(Object, Object), and getGenerateParent(Object, Object), to involve more objects these operations, as well as doPreGenerate(Object, Object) and doPostGenerate(Object, Object), to perform setup and cleanup before and after code generation.

This class is designed to support singleton generator adapters, where a single adapter instance can be attached to multiple objects of the same type. State relevant to a single object is only cached during a call to preGenerate(Object, Object), generate(Object, Object, Monitor), or postGenerate(Object, Object).

Since:
2.2.0

Nested Class Summary
protected static class AbstractGeneratorAdapter.JETEmitterDescriptor
          The information required to construct and initialize a JETEmitter, namely the file name of the template (relative to the template path) and the qualified name of the template class.
 
Nested classes/interfaces inherited from interface org.eclipse.emf.common.notify.Adapter
Adapter.Internal
 
Field Summary
protected  GeneratorAdapterFactory adapterFactory
           
protected  java.lang.Object generatingObject
          The object for which this adapter is currently being used to generate code.
protected  GIFEmitter[] gifEmitters
          All the GIFEmitters used by this adapter.
protected  ImportManager importManager
          The ImportManager currently being used in generating Java code.
protected  JETEmitter[] jetEmitters
          All the JETEmitters used by this adapter.
protected  java.lang.String lineDelimiter
          The line delimiter currently being used in generating textual results.
protected static java.lang.String MANIFEST_ENCODING
           
protected  java.lang.String message
          The message describing what is being done.
protected static java.lang.Class<?>[] OBJECT_ARGUMENT
           
protected static java.lang.String PROPERTIES_ENCODING
           
protected  URIConverter uriConverter
          An appropriate URIConverter for use during code generation.
 
Fields inherited from class org.eclipse.emf.common.notify.impl.SingletonAdapterImpl
targets
 
Constructor Summary
AbstractGeneratorAdapter()
          If this default constructor is used, the setAdapterFactory() method must be called immediately to set the generator adapter factory that created this adapter.
AbstractGeneratorAdapter(GeneratorAdapterFactory adapterFactory)
           
 
Method Summary
protected  void addBaseTemplatePathEntries(java.util.List<java.lang.String> templatePath)
          Adds template locations to the base portion of the dynamic template path, an ordered list of URIs corresponding to locations under which to find templates.
protected  void addClasspathEntries(JETEmitter jetEmitter)
          Override this to add classpath variables to the JETEmitter.
abstract  boolean canGenerate(java.lang.Object object, java.lang.Object projectType)
          Returns whether code of the given object type can be generated for the specified object.
protected  void clearImportManager()
          Clears the cached ImportManager.
protected  java.lang.Object createCodeFormatter(java.util.Map<?,?> options, URI workspacePath)
          When running under Eclipse, returns a code formatter; when stand-alone, returns null.
protected  GIFEmitter createGIFEmitter(java.lang.String inputPathName)
          Creates a GIFEmitter based on the image at the give template-path-relative file name.
protected  void createImportManager(java.lang.String packageName, java.lang.String className)
          Creates and caches an ImportManager for use in generating Java code.
protected  java.io.InputStream createInputStream(URI workspacePath)
          Creates an InputStream for the file identified by the given workspace path URI.
protected  JETEmitter createJETEmitter(AbstractGeneratorAdapter.JETEmitterDescriptor jetEmitterDescriptor)
          Creates and initializes a JETEmitter according to the given descriptor.
protected  Monitor createMonitor(Monitor monitor, int ticks)
          Creates and returns a sub-monitor for the given progress monitor.
protected  java.io.OutputStream createOutputStream(URI workspacePath)
          Creates an OutputStream for the file identified by the given workspace path URI.
protected abstract  Diagnostic doGenerate(java.lang.Object object, java.lang.Object projectType, Monitor monitor)
          Implement this to perform code generation of the given project type for the specified object.
protected  Diagnostic doPostGenerate(java.lang.Object object, java.lang.Object projectType)
          Does nothing and returns OK.
protected  Diagnostic doPreGenerate(java.lang.Object object, java.lang.Object projectType)
          Does nothing and returns OK.
protected  void ensureContainerExists(URI workspacePath, Monitor monitor)
          Ensures that a container corresponding to the specified relative URI exists.
protected  void ensureProjectExists(java.lang.String workspacePath, java.lang.Object object, java.lang.Object projectType, boolean force, Monitor monitor)
          Ensures that a project, corresponding to the first segment in the specified workspace path, exists.
protected  boolean exists(URI workspacePath)
          Determines whether a given workspace path URI represents a file that already exists.
protected  java.lang.String formatCode(java.lang.String contents, java.lang.Object codeFormatter)
          If non-null, use the specified code formatter to format the given compilation unit contents.
 Diagnostic generate(java.lang.Object object, java.lang.Object projectType, Monitor monitor)
          If code can be generated for the object, as determined by canGenerate(Object, Object), delegates code generation to doGenerate(Object, Object, Monitor).
protected  void generateGIF(java.lang.String targetPathName, GIFEmitter gifEmitter, java.lang.String parentKey, java.lang.String childKey, boolean overwrite, Monitor monitor)
          Generates an icon using a GIFEmitter to colourize a grey-scale GIF image.
protected  void generateJava(java.lang.String targetPath, java.lang.String packageName, java.lang.String className, JETEmitter jetEmitter, java.lang.Object[] arguments, Monitor monitor)
          Generates a Java source file using JET, with import management and, when running under Eclipse, merging and code formatting capabilities.
protected  void generateProperties(java.lang.String targetPathName, JETEmitter jetEmitter, java.lang.Object[] arguments, Monitor monitor)
          Generates a properties file using JET, with merging capability.
protected  void generateText(java.lang.String targetPathName, JETEmitter jetEmitter, java.lang.Object[] arguments, boolean overwrite, java.lang.String encoding, Monitor monitor)
          Generates an arbitrary text artifact using JET.
 GeneratorAdapterFactory getAdapterFactory()
          Returns the adapter factory that created this adapter.
 java.util.Collection<?> getCanGenerateChildren(java.lang.Object object, java.lang.Object projectType)
          Returns an empty collection, indicating that by default no children are involved in determining whether code can be generated for an object.
 java.lang.Object getCanGenerateParent(java.lang.Object object, java.lang.Object projectType)
          Returns null, indicating that by default no parent is involved in determining whether code can be generated for an object.
protected  java.lang.String getContents(URI workspacePath, java.lang.String encoding)
          Returns the contents of the file identified by the given workspace path URI, as read using the specified encoding.
protected  java.lang.String getEncoding(URI workspacePath)
          When running under Eclipse, queries the workspace to determine the correct encoding for the file identified by the given workspace path URI.
 java.util.Collection<?> getGenerateChildren(java.lang.Object object, java.lang.Object projectType)
          Returns an empty collection, indicating that by default there are no children of an object for which code should be generated.
 java.lang.Object getGenerateParent(java.lang.Object object, java.lang.Object projectType)
          Returns null, indicating that by default there is no parent of an object for which could should be generated.
protected  Generator getGenerator()
          Returns the generator for this adapter's factory.
protected  GIFEmitter getGIFEmitter(java.lang.String[] inputPathNames, int id)
          Returns the GIFEmitter for the input path name at the index specified by id in the given array.
protected  ImportManager getImportManager()
          Returns the ImportManager that is currently in use for generating Java code, or null if there is none.
protected  JETEmitter getJETEmitter(AbstractGeneratorAdapter.JETEmitterDescriptor[] jetEmitterDescriptors, int id)
          Returns the JETEmitter for the JETEmitterDescriptor at the index specified by id in the given array.
protected  java.lang.String getLineDelimiter()
          Returns the current line delimiter used for generating textual results.
 java.lang.String getLineDelimiter(URI workspacePath, java.lang.String encoding)
           
protected  URIConverter getURIConverter()
          Returns an appropriate URIConverter for use during code generation.
protected  java.util.List<java.lang.String> getUserTemplatePath()
          Returns the user-specified portion of the dynamic template path, an ordered list of URIs corresponding to locations under which to find templates.
 boolean isAdapterForType(java.lang.Object type)
          Returns true when the type is this adapter's factory.
protected  boolean isReadOnly(URI workspacePath)
          Determines whether a given workspace path URI represents a read-only file.
 Diagnostic postGenerate(java.lang.Object object, java.lang.Object projectType)
          Caches the object as generatingObject, calls doPostGenerate(Object, Object), and clears it again.
 Diagnostic preGenerate(java.lang.Object object, java.lang.Object projectType)
          Caches the object as generatingObject, calls doPreGenerate(Object, Object), and clears it again.
 void setAdapterFactory(GeneratorAdapterFactory adapterFactory)
          Sets the adapter factory that created this adapter.
protected  void setLineDelimiter(java.lang.String lineDelimiter)
          Sets the current line delimiter used for generating textual results.
protected  void setStaticTemplateClass(JETEmitter jetEmitter, java.lang.String className)
          If dynamic templates are not being used, attempts to set the emitter to use an existing, precompiled template class that has a method with signature generate(Object).
protected  void setStaticTemplateClass(JETEmitter jetEmitter, java.lang.String className, java.lang.String methodName, java.lang.Class<?>[] arguments)
          If dynamic templates are not being used, attempts to set the emitter to use an existing, precompiled template class that has the given method name and argument types.
protected  void setWriteable(URI workspacePath)
          Sets the file represented by a workspace path URI to be writable.
protected  Diagnostic toDiagnostic(java.lang.Exception exception, java.lang.String currentMessage)
          Converts the given exception to a Diagnostic.
protected  URI toPlatformResourceURI(URI uri)
          Converts the given workspace path URI to an absolute, platform resource URI, with encoding to eliminate any invalid characters.
protected  URI toURI(java.lang.String pathName)
          Converts the given workspace path to a URI.
protected  boolean validateEdit(URI workspacePath, Monitor monitor)
          When running under Eclipse, performs an IWorkspace.validateEdit(IFile[], Object) for the file identified by the given workspace path URI.
 
Methods inherited from class org.eclipse.emf.common.notify.impl.SingletonAdapterImpl
dispose, getTarget, notifyChanged, setTarget, unsetTarget
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.emf.codegen.ecore.generator.GeneratorAdapter
dispose
 

Field Detail

MANIFEST_ENCODING

protected static final java.lang.String MANIFEST_ENCODING
See Also:
Constant Field Values

PROPERTIES_ENCODING

protected static final java.lang.String PROPERTIES_ENCODING
See Also:
Constant Field Values

adapterFactory

protected GeneratorAdapterFactory adapterFactory

generatingObject

protected java.lang.Object generatingObject
The object for which this adapter is currently being used to generate code. This will only be set during preGenerate(Object, Object), generate(Object, Object, Monitor), and postGenerate(Object, Object).


message

protected java.lang.String message
The message describing what is being done. This can be set during doGenerate(Object, Object, Monitor) and will be used in the diagnostic message if an exception is caught.


jetEmitters

protected JETEmitter[] jetEmitters
All the JETEmitters used by this adapter. This are cached so that they can be reused at least for different objects with the same adapter. When dynamic templateS are not being used, they can actually be reused for multiple code generation invocations.


gifEmitters

protected GIFEmitter[] gifEmitters
All the GIFEmitters used by this adapter. This are cached so that they can be reused at least for different objects with the same adapter. When dynamic templateS are not being used, they can actually be reused for multiple code generation invocations.


importManager

protected ImportManager importManager
The ImportManager currently being used in generating Java code. This should only be created and cleared via createImportManager(String, String) and clearImportManager(), so that subclasses may respond to such changes.


lineDelimiter

protected java.lang.String lineDelimiter
The line delimiter currently being used in generating textual results. This should only be set via setLineDelimiter(String) so that subclasses may respond to such changes.

Since:
2.3

uriConverter

protected URIConverter uriConverter
An appropriate URIConverter for use during code generation. This is usually applicable to the whole set of objects for which code is being generated, so it can be cached long-term.


OBJECT_ARGUMENT

protected static final java.lang.Class<?>[] OBJECT_ARGUMENT
Constructor Detail

AbstractGeneratorAdapter

public AbstractGeneratorAdapter()
If this default constructor is used, the setAdapterFactory() method must be called immediately to set the generator adapter factory that created this adapter.


AbstractGeneratorAdapter

public AbstractGeneratorAdapter(GeneratorAdapterFactory adapterFactory)
Method Detail

getAdapterFactory

public GeneratorAdapterFactory getAdapterFactory()
Description copied from interface: GeneratorAdapter
Returns the adapter factory that created this adapter.

Specified by:
getAdapterFactory in interface GeneratorAdapter
See Also:
GeneratorAdapter.setAdapterFactory(GeneratorAdapterFactory)

setAdapterFactory

public void setAdapterFactory(GeneratorAdapterFactory adapterFactory)
Description copied from interface: GeneratorAdapter
Sets the adapter factory that created this adapter. If the constructor for the adapter does not set the adapter factory, this method can be called immediately after the adapter is created.

Specified by:
setAdapterFactory in interface GeneratorAdapter
See Also:
GeneratorAdapter.getAdapterFactory()

isAdapterForType

public boolean isAdapterForType(java.lang.Object type)
Returns true when the type is this adapter's factory. This allows generator adapters from different factories to be attached to the same objects.

Specified by:
isAdapterForType in interface Adapter
Overrides:
isAdapterForType in class SingletonAdapterImpl
Parameters:
type - the type.
Returns:
false
See Also:
AdapterFactory.isFactoryForType(java.lang.Object)

getCanGenerateChildren

public java.util.Collection<?> getCanGenerateChildren(java.lang.Object object,
                                                      java.lang.Object projectType)
Returns an empty collection, indicating that by default no children are involved in determining whether code can be generated for an object.

Specified by:
getCanGenerateChildren in interface GeneratorAdapter

getCanGenerateParent

public java.lang.Object getCanGenerateParent(java.lang.Object object,
                                             java.lang.Object projectType)
Returns null, indicating that by default no parent is involved in determining whether code can be generated for an object.

Specified by:
getCanGenerateParent in interface GeneratorAdapter

canGenerate

public abstract boolean canGenerate(java.lang.Object object,
                                    java.lang.Object projectType)
Description copied from interface: GeneratorAdapter
Returns whether code of the given object type can be generated for the specified object.

Specified by:
canGenerate in interface GeneratorAdapter

getGenerateChildren

public java.util.Collection<?> getGenerateChildren(java.lang.Object object,
                                                   java.lang.Object projectType)
Returns an empty collection, indicating that by default there are no children of an object for which code should be generated.

Specified by:
getGenerateChildren in interface GeneratorAdapter

getGenerateParent

public java.lang.Object getGenerateParent(java.lang.Object object,
                                          java.lang.Object projectType)
Returns null, indicating that by default there is no parent of an object for which could should be generated.

Specified by:
getGenerateParent in interface GeneratorAdapter

preGenerate

public final Diagnostic preGenerate(java.lang.Object object,
                                    java.lang.Object projectType)
Caches the object as generatingObject, calls doPreGenerate(Object, Object), and clears it again. If dynamic templates are enabled on the generator, any cached JETEmitters and GIFEmitters are also removed, so that templates will be recompiled during generate(Object, Object, Monitor).

Specified by:
preGenerate in interface GeneratorAdapter

doPreGenerate

protected Diagnostic doPreGenerate(java.lang.Object object,
                                   java.lang.Object projectType)
Does nothing and returns OK. Override this to perform setup for code generation.


generate

public final Diagnostic generate(java.lang.Object object,
                                 java.lang.Object projectType,
                                 Monitor monitor)
If code can be generated for the object, as determined by canGenerate(Object, Object), delegates code generation to doGenerate(Object, Object, Monitor). Otherwise, simply returns OK. The object is cached as generatingObject and the message is cleared before calling doGenerate(Object, Object, Monitor); both are cleared again afterwards.

Specified by:
generate in interface GeneratorAdapter
See Also:
canGenerate(Object, Object), doGenerate(Object, Object, Monitor)

doGenerate

protected abstract Diagnostic doGenerate(java.lang.Object object,
                                         java.lang.Object projectType,
                                         Monitor monitor)
                                  throws java.lang.Exception
Implement this to perform code generation of the given project type for the specified object. Use the monitor to update progress for this long-running operation. Any exceptions thrown will be converted into a diagnostic and returned by generate(). If a message is set, it will be used in this diagnostic.

Throws:
java.lang.Exception

postGenerate

public final Diagnostic postGenerate(java.lang.Object object,
                                     java.lang.Object projectType)
Caches the object as generatingObject, calls doPostGenerate(Object, Object), and clears it again. If dynamic templates are enabled on the generator, any cached JETEmitter and GIFEmitters are also removed, so that templates will be recompiled during the next generate(Object, Object, Monitor).

Specified by:
postGenerate in interface GeneratorAdapter

doPostGenerate

protected Diagnostic doPostGenerate(java.lang.Object object,
                                    java.lang.Object projectType)
Does nothing and returns OK. Override this to perform cleanup from code generation.


toDiagnostic

protected Diagnostic toDiagnostic(java.lang.Exception exception,
                                  java.lang.String currentMessage)
Converts the given exception to a Diagnostic. The currentMessage, if non-null, should describe what was being done when the exception occurred, and will be used in forming the diagnostic's message.


getGenerator

protected Generator getGenerator()
Returns the generator for this adapter's factory.


getJETEmitter

protected JETEmitter getJETEmitter(AbstractGeneratorAdapter.JETEmitterDescriptor[] jetEmitterDescriptors,
                                   int id)
Returns the JETEmitter for the JETEmitterDescriptor at the index specified by id in the given array. If the JETEmitter has not yet been created, it will be created, initialized, and cached at the same index in jetEmitters.

Parameters:
jetEmitterDescriptors - an array of descriptors for all of the JETEmitters used by this generator adapter.
id - the identifier for the desired JETEmitter, also the index of the descriptor in the array.

createJETEmitter

protected JETEmitter createJETEmitter(AbstractGeneratorAdapter.JETEmitterDescriptor jetEmitterDescriptor)
Creates and initializes a JETEmitter according to the given descriptor.


getUserTemplatePath

protected java.util.List<java.lang.String> getUserTemplatePath()
Returns the user-specified portion of the dynamic template path, an ordered list of URIs corresponding to locations under which to find templates. This implementation returns an empty list.

This method is only consulted if the generator's templatePath option is set to null.

Since:
org.eclipse.emf.codegen.ecore 2.2.2
See Also:
Generator.Options.templatePath, JETEmitter.JETEmitter(String[], String), JETCompiler.find(String[], String)

addBaseTemplatePathEntries

protected void addBaseTemplatePathEntries(java.util.List<java.lang.String> templatePath)
Adds template locations to the base portion of the dynamic template path, an ordered list of URIs corresponding to locations under which to find templates. Order matters, so the pattern is to add local entries first, and then invoke the superclass implementation. This implementation does nothing.

This method is only consulted if the generator's templatePath option is set to null.

Since:
org.eclipse.emf.codegen.ecore 2.2.2
See Also:
Generator.Options.templatePath, JETEmitter.JETEmitter(String[], String), JETCompiler.find(String[], String)

setStaticTemplateClass

protected void setStaticTemplateClass(JETEmitter jetEmitter,
                                      java.lang.String className)
If dynamic templates are not being used, attempts to set the emitter to use an existing, precompiled template class that has a method with signature generate(Object).

See Also:
setStaticTemplateClass(JETEmitter, String, String, Class[])

setStaticTemplateClass

protected void setStaticTemplateClass(JETEmitter jetEmitter,
                                      java.lang.String className,
                                      java.lang.String methodName,
                                      java.lang.Class<?>[] arguments)
If dynamic templates are not being used, attempts to set the emitter to use an existing, precompiled template class that has the given method name and argument types.

Since:
2.5

addClasspathEntries

protected void addClasspathEntries(JETEmitter jetEmitter)
                            throws JETException
Override this to add classpath variables to the JETEmitter. These will be used to build and execute dynamic templates.

Throws:
JETException
See Also:
JETEmitter.addVariable(String, String)

getGIFEmitter

protected GIFEmitter getGIFEmitter(java.lang.String[] inputPathNames,
                                   int id)
Returns the GIFEmitter for the input path name at the index specified by id in the given array. If the GIFEmitter has not yet been created, it will be created and cached at the same index in gifEmitters.

Parameters:
inputPathNames - an array of input path names for all the GIFEmitters used by this generator adapter. These are the file names, relative to the template path, of grey-scale images to be colourized.
id - the identifier for the desired GIFEmitter, also the index of the input path name in the array.

createGIFEmitter

protected GIFEmitter createGIFEmitter(java.lang.String inputPathName)
Creates a GIFEmitter based on the image at the give template-path-relative file name.


generateText

protected void generateText(java.lang.String targetPathName,
                            JETEmitter jetEmitter,
                            java.lang.Object[] arguments,
                            boolean overwrite,
                            java.lang.String encoding,
                            Monitor monitor)
Generates an arbitrary text artifact using JET.

Parameters:
targetPathName - the path name of the target file. This should be a workspace path; when running stand-alone, it will be converted to a platform resource URI that should be mapped to a physical file URI by the URIConverter.
jetEmitter - the JETEmitter to use for generating the text.
arguments - the argument array to pass to the JETEmitter's generate(Monitor, Object[]) method. If null, an array will be constructed containing only the object for which code is being generated.
overwrite - whether an existing file should be overwritten.
encoding - an override of the default encoding. If "ISO-8859-1" is specified, Unicode escape encoding is performed to represent non-Latin characters. The default encoding, when running under Eclipse, is determined from the workspace. Failing that, or in stand-alone, the platform default is used.
monitor - the Monitor through which to report progress.

This method also consults the following generator options:


generateProperties

protected void generateProperties(java.lang.String targetPathName,
                                  JETEmitter jetEmitter,
                                  java.lang.Object[] arguments,
                                  Monitor monitor)
Generates a properties file using JET, with merging capability.

The encoding used for the generated file is "ISO-8859-1". Unicode escape encoding is performed to represent non-Latin characters.

Parameters:
targetPathName - the path name of the target file. This should be a workspace path; when running stand-alone, it will be converted to a platform resource URI that should be mapped to a physical file URI by the URIConverter.
jetEmitter - the JETEmitter to use for generating the text.
arguments - the argument array to pass to the JETEmitter's generate(Monitor, Object[]) method. If null, an array will be constructed containing only the object for which code is being generated.
monitor - the Monitor through which to report progress.

This method also consults the following generator options:


generateGIF

protected void generateGIF(java.lang.String targetPathName,
                           GIFEmitter gifEmitter,
                           java.lang.String parentKey,
                           java.lang.String childKey,
                           boolean overwrite,
                           Monitor monitor)
Generates an icon using a GIFEmitter to colourize a grey-scale GIF image. The colours to use are calculated from one or, optionally, two text keys.

Parameters:
targetPathName - the path name of the target file. This should be a workspace path; when running stand-alone, it will be converted to a platform resource URI that should be mapped to a physical file URI by the URIConverter.
gifEmitter - the GIFEmitter to use for generating the icon.
parentKey - the key used to determine the first colour set.
childKey - the key used to determine the second colour set. If null, this key is ignored.
overwrite - whether an existing file should be overwritten.
monitor - the Monitor through which to report progress.

This method also consults the following generator options:


generateJava

protected void generateJava(java.lang.String targetPath,
                            java.lang.String packageName,
                            java.lang.String className,
                            JETEmitter jetEmitter,
                            java.lang.Object[] arguments,
                            Monitor monitor)
Generates a Java source file using JET, with import management and, when running under Eclipse, merging and code formatting capabilities.

When running under Eclipse, the encoding for the file is determined from the workspace. Failing that, or in stand-alone, the platform default is used.

Parameters:
targetPath - the workspace path of the directory in or under which the file will be created, depending on the specified package name. When running stand-alone, this path will be converted to a platform resource URI that should be mapped to a physical file URI by the URIConverter.
packageName - the package name for the generated compilation unit.
className - the name of the public class in the generated compilation unit.
jetEmitter - the JETEmitter to use for generating the code.
arguments - the argument array to pass to the JETEmitter's generate(Monitor, Object[]) method. If null, an array will be constructed containing only the object for which code is being generated.
monitor - the Monitor through which to report progress.

This method also consults the following generator options:


toURI

protected URI toURI(java.lang.String pathName)
Converts the given workspace path to a URI. No encoding is performed, so the URI may contain invalid characters. Such a URI is only used to easily access and manipulate parts of the workspace path. It can then be converted back to a string and an IPath for use in the workspace, or to an encoded platform resource URI for direct use with the EMF persistence framework.


toPlatformResourceURI

protected URI toPlatformResourceURI(URI uri)
Converts the given workspace path URI to an absolute, platform resource URI, with encoding to eliminate any invalid characters.


createMonitor

protected Monitor createMonitor(Monitor monitor,
                                int ticks)
Creates and returns a sub-monitor for the given progress monitor. When running stand-alone, the same monitor is actually returned.

Parameters:
monitor - the parent monitor
ticks - the number of work ticks allocated from the parent monitor

createImportManager

protected void createImportManager(java.lang.String packageName,
                                   java.lang.String className)
Creates and caches an ImportManager for use in generating Java code.


clearImportManager

protected void clearImportManager()
Clears the cached ImportManager.


getImportManager

protected ImportManager getImportManager()
Returns the ImportManager that is currently in use for generating Java code, or null if there is none.


setLineDelimiter

protected void setLineDelimiter(java.lang.String lineDelimiter)
Sets the current line delimiter used for generating textual results.

Parameters:
lineDelimiter -
Since:
2.3

getLineDelimiter

protected java.lang.String getLineDelimiter()
Returns the current line delimiter used for generating textual results.

Since:
2.3

ensureProjectExists

protected void ensureProjectExists(java.lang.String workspacePath,
                                   java.lang.Object object,
                                   java.lang.Object projectType,
                                   boolean force,
                                   Monitor monitor)
Ensures that a project, corresponding to the first segment in the specified workspace path, exists. If the project does not exist, a default project will be created. If it does exist and force is true, it will be reconfigured to match the default configuration. The remainder of the path suggests the folder under which source will be generated.

When running stand-alone, this method does nothing, since simply opening a stream via a URIConverter will automatically create the necessary directories.


ensureContainerExists

protected void ensureContainerExists(URI workspacePath,
                                     Monitor monitor)
Ensures that a container corresponding to the specified relative URI exists. The URI represents a workspace path for which the project must already exist, since this method doesn't have the necessary information to set up a project. This method will create nested folders within the project, if possible.

When running stand-alone, this method does nothing, since simply opening a stream via a URIConverter will automatically create the necessary directories.


getURIConverter

protected URIConverter getURIConverter()
Returns an appropriate URIConverter for use during code generation.


getLineDelimiter

public java.lang.String getLineDelimiter(URI workspacePath,
                                         java.lang.String encoding)
Since:
2.3

exists

protected boolean exists(URI workspacePath)
Determines whether a given workspace path URI represents a file that already exists.


isReadOnly

protected boolean isReadOnly(URI workspacePath)
Determines whether a given workspace path URI represents a read-only file.


setWriteable

protected void setWriteable(URI workspacePath)
                     throws java.lang.Exception
Sets the file represented by a workspace path URI to be writable. When running stand-alone, this actually deletes the file, since there is no Java platform API for making a file writable.

Throws:
java.lang.Exception

validateEdit

protected boolean validateEdit(URI workspacePath,
                               Monitor monitor)
When running under Eclipse, performs an IWorkspace.validateEdit(IFile[], Object) for the file identified by the given workspace path URI. This notifies the workspace that the file will be edited, providing it the opportunity to prepare the files if required. When running stand-alone, does nothing.


createInputStream

protected java.io.InputStream createInputStream(URI workspacePath)
                                         throws java.lang.Exception
Creates an InputStream for the file identified by the given workspace path URI.

Throws:
java.lang.Exception

createOutputStream

protected java.io.OutputStream createOutputStream(URI workspacePath)
                                           throws java.lang.Exception
Creates an OutputStream for the file identified by the given workspace path URI.

Throws:
java.lang.Exception

getContents

protected java.lang.String getContents(URI workspacePath,
                                       java.lang.String encoding)
                                throws java.lang.Exception
Returns the contents of the file identified by the given workspace path URI, as read using the specified encoding.

Throws:
java.lang.Exception

getEncoding

protected java.lang.String getEncoding(URI workspacePath)
When running under Eclipse, queries the workspace to determine the correct encoding for the file identified by the given workspace path URI. When running stand-alone, returns null.


createCodeFormatter

protected java.lang.Object createCodeFormatter(java.util.Map<?,?> options,
                                               URI workspacePath)
When running under Eclipse, returns a code formatter; when stand-alone, returns null. If options is non-null, the code formatting options it specifies are used to create the formatter. Otherwise, the project is obtained from the given workspace path URI, and its default formatting options are used.

Returns:
the created code formatter. If non-null, this will be an instance of CodeFormatter; however, it is not statically typed as such to avoid failure when running stand-alone.

formatCode

protected java.lang.String formatCode(java.lang.String contents,
                                      java.lang.Object codeFormatter)
If non-null, use the specified code formatter to format the given compilation unit contents.

Returns:
the formatted version of the contents. If the code formatter is null or when running stand-alone, the contents are returned unchanged.

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