summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-05-01 11:46:09 (EDT)
committer pelder2006-05-01 11:46:09 (EDT)
commitaf5f21cb3853157ecea1ec27a82c2aee59545a5e (patch)
tree5298d6c06af8bcaf43036043f6c8ca180d2b9c5f
parent76f870a95eed62bcb697aea3bfb813973f9133cb (diff)
downloadorg.eclipse.jet-af5f21cb3853157ecea1ec27a82c2aee59545a5e.zip
org.eclipse.jet-af5f21cb3853157ecea1ec27a82c2aee59545a5e.tar.gz
org.eclipse.jet-af5f21cb3853157ecea1ec27a82c2aee59545a5e.tar.bz2
[139524] Add variants of runTransformOnXXX() to pass a map of variables.
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java85
1 files changed, 77 insertions, 8 deletions
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java
index a8a2749..2089807 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.text.MessageFormat;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.Map;
import java.util.Set;
import org.eclipse.core.filebuffers.FileBuffers;
@@ -172,11 +173,11 @@ public class JET2Platform
}
/**
- * @deprecated Use {@link #runTransformOnResource(String,IResource,IProgressMonitor)} instead
+ * @deprecated Use {@link #runTransformOnResource(String,IResource,Map, IProgressMonitor)} instead
*/
public static IStatus execute(final String id, final IResource resource, final IProgressMonitor monitor)
{
- return runTransformOnResource(id, resource, monitor);
+ return runTransformOnResource(id, resource, null, monitor);
}
/**
@@ -185,11 +186,11 @@ public class JET2Platform
* @param source
* @param monitor
* @return the execution status
- * @deprecated Use {@link #runTransformOnObject(String,Object,IProgressMonitor)} instead
+ * @deprecated Use {@link #runTransformOnObject(String,Object,Map, IProgressMonitor)} instead
*/
public static IStatus execute(final String id, final Object source, final IProgressMonitor monitor)
{
- return runTransformOnObject(id, source, monitor);
+ return runTransformOnObject(id, source, null, monitor);
}
/**
@@ -208,11 +209,11 @@ public class JET2Platform
* @param kind the kind of model (file extension) the string represents.
* @param monitor a progress monitor
* @return the transform's execution status.
- * @deprecated Use {@link #runTransformOnString(String,String,String,IProgressMonitor)} instead
+ * @deprecated Use {@link #runTransformOnString(String,String,String,Map, IProgressMonitor)} instead
*/
public static IStatus execute(final String id, final String source, final String kind, final IProgressMonitor monitor)
{
- return runTransformOnString(id, source, kind, monitor);
+ return runTransformOnString(id, source, kind, null, monitor);
}
/**
@@ -421,8 +422,32 @@ public class JET2Platform
*/
public static IStatus runTransformOnObject(final String id, final Object source, final IProgressMonitor monitor)
{
+ return runTransformOnObject(id, source, null, monitor);
+ }
+
+ /**
+ * Execute a JET transform with the passed object as the root of the source model.
+ * @param id the JET Transform id
+ * @param source the source model root object.
+ * @param variables A Map of variable names and their values. May be <code>null</code>.
+ * @param monitor a progress monitor
+ * @return the transform's execution status
+ */
+ public static IStatus runTransformOnObject(final String id, final Object source, Map variables, final IProgressMonitor monitor)
+ {
final JET2Context context = new JET2Context(source);
- return runTransform(id, context, monitor);
+ try
+ {
+ if(variables != null)
+ {
+ context.setVariables(variables);
+ }
+ return runTransform(id, context, monitor);
+ }
+ catch (JET2TagException e)
+ {
+ return new Status(IStatus.ERROR, id, IStatus.OK, e.getMessage(), e);
+ }
}
/**
@@ -434,11 +459,29 @@ public class JET2Platform
*/
public static IStatus runTransformOnResource(final String id, final IResource resource, final IProgressMonitor monitor)
{
+ return runTransformOnResource(id, resource, null, monitor);
+ }
+
+ /**
+ * Invoke a JET Transform on the pass resource, loading the resource using the transform's model loader.
+ * @param id the JET Transform id
+ * @param resource the Eclipse Resource to load
+ * @param variables A Map of variable names and their values. May be <code>null</code>.
+ * @param monitor a progress monitor
+ * @return the transform's execution status
+ */
+ public static IStatus runTransformOnResource(final String id, final IResource resource, Map variables, final IProgressMonitor monitor)
+ {
try
{
final IJETBundleDescriptor descriptor = getJETBundleManager().getDescriptor(id);
final JET2Context context = new JET2Context(null);
+ if(variables != null)
+ {
+ context.setVariables(variables);
+ }
+
String loaderId = descriptor.getModelLoaderId();
String fileType = descriptor.getModelExtension();
@@ -446,6 +489,10 @@ public class JET2Platform
return runTransform(id, context, monitor);
}
+ catch (JET2TagException e)
+ {
+ return new Status(IStatus.ERROR, id, IStatus.OK, e.getMessage(), e);
+ }
catch (IOException e)
{
// didn't work.
@@ -466,7 +513,7 @@ public class JET2Platform
*/
public static IStatus runTransformOnString(final String id, final String source, final IProgressMonitor monitor)
{
- return runTransformOnString(id, source, "xml", monitor); //$NON-NLS-1$
+ return runTransformOnString(id, source, "xml", null, monitor); //$NON-NLS-1$
}
/**
@@ -479,6 +526,20 @@ public class JET2Platform
*/
public static IStatus runTransformOnString(final String id, final String source, final String kind, final IProgressMonitor monitor)
{
+ return runTransformOnString(id, source, kind, null, monitor);
+ }
+
+ /**
+ * Invoke a JET transform on the passed String representation of an input model.
+ * @param id the transform id
+ * @param source the string respresentation of the input model.
+ * @param kind the kind of model (file extension) the string represents.
+ * @param variables A Map of variable names and their values. May be <code>null</code>.
+ * @param monitor a progress monitor
+ * @return the transform's execution status.
+ */
+ public static IStatus runTransformOnString(final String id, final String source, final String kind, Map variables, final IProgressMonitor monitor)
+ {
IStatus result = Status.OK_STATUS;
JET2Context context = new JET2Context(null);
@@ -488,10 +549,18 @@ public class JET2Platform
try
{
+ if(variables != null)
+ {
+ context.setVariables(variables);
+ }
final Object sourceObject = TransformContextExtender.loadModelFromString(source, modelLoaderID, kind);
context.setSource(sourceObject);
result = runTransform(id, context, monitor);
}
+ catch (JET2TagException e)
+ {
+ return new Status(IStatus.ERROR, id, IStatus.OK, e.getMessage(), e);
+ }
catch (CoreJETException e)
{
result = BasicDiagnostic.toIStatus(e.getDiagnostic());