JET FAQ How do I run a JET transformation from Java?
How do I run a JET transformation from my plug-in?
The class JET2Platform has a number of runTransformOnXXX methods that run a transform programmatically. None of these methods will impact the Eclipse UI. If you want an execution console, see JET FAQ How do I get a console when running JET from Java?
This is intended to be used if you have a workspace file that you want to load as the transformation input. This is the closest thing to running the transform like the UI. (The UI does is slightly differently in order to get the console hooked up, etc.... The runTransformOnXXX methods do not hook into the console).
This method is intended to be used if you have your model already loaded in memory. This would likely be the case if you have a GMF-created editor, and you are adding an action to the editor to transform this model into something else via a JET transform.
This method takes a model (typically an XML document) as a string, and run the transformation against it. As with runTransformOnObject, if you are using the org.eclipse.jet.resource variables in you transform, you will have to set them manually.
There are two 'tricks' to using runTransformOnObject and runTransformOnString.
1) For runTransformOnObject, you must pass an Object that represents the in-memory model. If your EMF model was generated directly from ECore, pass in the EMF Resource object. If you EMF model was generated from an XSD Schema, pass in the instanced of the generated DocumentRoot class.
2) The predefined JET variables for the form org.eclipse.jet.resource.* are not set, because no Eclipse resource was processed during model loading. This will usually cause some grief with at least the default ws:file tag that generates a dump of your input model, as it uses $org.eclipse.jet.resource.project.name. You can pass a Map of variable names to variable values to an overload of runTransformOnXXX.