summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-04-06 04:15:52 (EDT)
committerpelder2006-04-06 04:15:52 (EDT)
commitbc38c517915485c0098f34d211e8466967ffac2d (patch)
treeaab5ce01e38483db01a6430a4ab8e7ba7e64795d
parent8ea3b729df7d062f3c7e68a8a2c3c7d2f40d80c7 (diff)
downloadorg.eclipse.jet-bc38c517915485c0098f34d211e8466967ffac2d.zip
org.eclipse.jet-bc38c517915485c0098f34d211e8466967ffac2d.tar.gz
org.eclipse.jet-bc38c517915485c0098f34d211e8466967ffac2d.tar.bz2
[131187] Implement overriding of JET templates plus tags to support.
-rw-r--r--plugins/org.eclipse.jet/plugin.xml74
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/JET2TemplateLoaderExtension.java38
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/LoaderGenerationParameters.java66
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2JavaGenerator.java17
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2TransformGenerator.java39
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/IncludeTag.java45
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/InvokeTransformTag.java88
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/LoadTag.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/OverrideTag.java51
-rw-r--r--plugins/org.eclipse.jet/templates/jet2java.javajet17
-rw-r--r--plugins/org.eclipse.jet/templates/jet2transform.javajet23
11 files changed, 404 insertions, 56 deletions
diff --git a/plugins/org.eclipse.jet/plugin.xml b/plugins/org.eclipse.jet/plugin.xml
index d8940e0..a2f719d 100644
--- a/plugins/org.eclipse.jet/plugin.xml
+++ b/plugins/org.eclipse.jet/plugin.xml
@@ -257,7 +257,11 @@ tag are written.
<description>
Process the referenced template, and include its results in the output of the current template.
-The &apos;restoreNames&apos; attribute is useful in recursive transforms. It causes the tag to save the listed variable values prior to executing the template, and then restore them after exectuion.
+The attribute &apos;passVariables&apos; allows explicit declaration of the variables that are passed to the template. By default, all context variables are available to the template. With this parameter, only those variables specified are available. In addition, any changes to passed variables in the template are not reflected in the invoking context.
+
+The deprecated &amp;apos;restoreNames&amp;apos; attribute is useful in recursive transforms. It causes the tag to save the listed variable values prior to executing the template, and then restore them after exectuion.
+
+The &apos;restoreNames&apos; and &apos;passVariables&apos; options are mutually exclusive.
</description>
<attribute
name="template"
@@ -268,11 +272,20 @@ The &apos;restoreNames&apos; attribute is useful in recursive transforms. It cau
</description>
</attribute>
<attribute
+ deprecated="true"
name="restoreNames"
type="string"
use="optional">
<description>
- A comma separated list of variable names (without the $ sign).
+ A comma separated list of variable names (without the $ sign). Mutually exclusive with &apos;passVariables&apos;.
+ </description>
+ </attribute>
+ <attribute
+ name="passVariables"
+ type="string"
+ use="optional">
+ <description>
+ A comma separated list of variable names (without the $ sign). Mutually exclusive with 'restoreNames'.
</description>
</attribute>
</emptyTag>
@@ -596,6 +609,63 @@ If the 'name' attribute refers to an existing attribute on the selected object,
</description>
</attribute>
</containerTag>
+ <emptyTag
+ class="org.eclipse.jet.internal.taglib.control.OverrideTag"
+ deprecated="false"
+ name="override"
+ whenContainingLineIsEmpty="remove">
+ <description>
+ *** Deprecated: Use the 'overrides' attribute on 'transform' extension in plugin.xml instead. *** Declares that this transform overrides templates in the identified transform.
+ </description>
+ <attribute
+ name="transformId"
+ type="string"
+ use="required">
+ <description>
+ The transform id of the transform which is being overriden.
+ </description>
+ </attribute>
+ </emptyTag>
+ <emptyTag
+ class="org.eclipse.jet.internal.taglib.control.InvokeTransformTag"
+ name="invokeTransform"
+ whenContainingLineIsEmpty="remove">
+ <description>
+ Invoke the another transform, passing it the current transform&apos;s source model and context variables. The transform&apos;s actions will be accumulated, and commit when the invoking transform commits.
+
+The attribute &apos;passVariables&apos; allows explicit declaration of the variables that are passed to the transform. By default, all context variables are available. With this parameter, only those variables specified are available. In addition, any changes to passed variables are not reflected in the invoking context.
+
+The deprecated &apos;restoreNames&apos; attribute allows for the restoration of variables set by the invoked transform back to their pre-invocation value.
+
+The &apos;restoreNames&apos; and &apos;passVariables&apos; options are mutually exclusive.
+ </description>
+ <attribute
+ name="transformId"
+ type="string"
+ use="required">
+ <description>
+ The transform id of the transform to invoke.
+ </description>
+ </attribute>
+ <attribute
+ deprecated="true"
+ name="restoreNames"
+ type="string"
+ use="optional">
+ <description>
+ A comma separated list of variable names (without the $ sign). Mutually exclusive with 'passVariables'.
+ </description>
+
+ </attribute>
+ <attribute
+ name="passVariables"
+ type="string"
+ use="optional">
+ <description>
+ A comma separated list of variable names (without the $ sign). Mutually exclusive with 'restoreNames'.
+ </description>
+ </attribute>
+ </emptyTag>
</tagLibrary>
<tagLibrary
id="workspaceTags"
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2TemplateLoaderExtension.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2TemplateLoaderExtension.java
new file mode 100644
index 0000000..de8441f
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2TemplateLoaderExtension.java
@@ -0,0 +1,38 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet;
+
+/**
+ * Extension interface for {@link JET2TemplateLoader} allowing
+ * for delegation of template loading to other loaders
+ */
+public interface JET2TemplateLoaderExtension
+{
+ /**
+ * Add a template loader to which this loader will delegate
+ * when it cannot find a template
+ * @param loader a template loader or <code>null</code> to remove the delegate loader.
+ */
+ public abstract void setDelegateLoader(JET2TemplateLoader loader);
+
+ /**
+ * Return the template loader to which this loader will delegate
+ * when it cannot find a template. The initial delegate loader is <code>null</code>.
+ * @return the delegate loader or <code>null</code>.
+ */
+ public abstract JET2TemplateLoader getDelegateLoader();
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/LoaderGenerationParameters.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/LoaderGenerationParameters.java
new file mode 100644
index 0000000..5430384
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/LoaderGenerationParameters.java
@@ -0,0 +1,66 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.internal.compiler;
+
+import java.util.Map;
+
+/**
+ * Parameter object of legacy JET template.
+ */
+public class LoaderGenerationParameters
+{
+
+ private final String packageName;
+ private final String className;
+ private final Map templateMap;
+
+ /**
+ *
+ */
+ public LoaderGenerationParameters(String packageName, String className, Map templateMap)
+ {
+ super();
+ this.packageName = packageName;
+ this.className = className;
+ this.templateMap = templateMap;
+ }
+
+ /**
+ * @return Returns the className.
+ */
+ public final String getClassName()
+ {
+ return className;
+ }
+
+ /**
+ * @return Returns the packageName.
+ */
+ public final String getPackageName()
+ {
+ return packageName;
+ }
+
+ /**
+ * @return Returns the templateMap.
+ */
+ public final Map getTemplateMap()
+ {
+ return templateMap;
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2JavaGenerator.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2JavaGenerator.java
index 4045c32..8ad76e9 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2JavaGenerator.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2JavaGenerator.java
@@ -2,7 +2,9 @@ package org.eclipse.jet.internal.compiler.templates;
import org.eclipse.jet.internal.compiler.*;
import org.eclipse.jet.compiler.*;
+import org.eclipse.jet.taglib.TagLibraryReference;
import java.util.Iterator;
+import java.util.Map;
public class JET2JavaGenerator
{
@@ -40,19 +42,18 @@ public class JET2JavaGenerator
});
final StringBuffer tagNamespaceVariables = new StringBuffer();
- cu.accept(new DefaultJET2ASTVisitor() {
- public void visit(JET2Directive directive) {
- if("taglib".equals(directive.getName())) {
+ TagLibraryReference[] tlRefs = cu.getTagLibraryReferences();
+ for(int i = 0; i < tlRefs.length; i++ ) {
+ ;
tagNamespaceVariables.append("public static final String _jetns_")
- .append(directive.getAttributes().get("prefix"))
+ .append(tlRefs[i].getPrefix())
.append(" = \"")
- .append(directive.getAttributes().get("id"))
+ .append(tlRefs[i].getTagLibraryId())
.append("\";")
.append("//$NON-NLS-1$")
.append(NL);
- }
- }
- });
+
+ }
final StringBuffer tagDataDeclarations = new StringBuffer();
cu.accept(new DefaultJET2ASTVisitor() {
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2TransformGenerator.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2TransformGenerator.java
index 77dbdbb..698d622 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2TransformGenerator.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2TransformGenerator.java
@@ -2,6 +2,7 @@ package org.eclipse.jet.internal.compiler.templates;
import java.util.Map;
import java.util.Iterator;
+import org.eclipse.jet.internal.compiler.LoaderGenerationParameters;
public class JET2TransformGenerator
{
@@ -15,34 +16,44 @@ public class JET2TransformGenerator
}
protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
- protected final String TEXT_1 = "package org.eclipse.jet.compiled;" + NL + "" + NL + "import java.util.HashMap;" + NL + "import java.util.Map;" + NL + "" + NL + "import org.eclipse.jet.JET2TemplateLoader;" + NL + "import org.eclipse.jet.JET2Template;" + NL + "" + NL + "public class _jet_transformation implements JET2TemplateLoader {" + NL + "" + NL + "\tprivate interface TemplateFactoryMethod {" + NL + "\t\tpublic abstract JET2Template newTemplate();" + NL + "\t}" + NL + "" + NL + "\tprivate Map pathToFactoryMap = null;" + NL + "" + NL + "\tpublic _jet_transformation() {" + NL + "\t\tsuper();" + NL + "\t}" + NL + "" + NL + "\tpublic JET2Template getTemplate(String templatePath) {" + NL + "\t if(pathToFactoryMap == null) {" + NL + "\t pathToFactoryMap = new HashMap(";
- protected final String TEXT_2 = ");";
- protected final String TEXT_3 = NL + "\t\t pathToFactoryMap.put(\"";
- protected final String TEXT_4 = "\"," + NL + "\t\t new TemplateFactoryMethod() {" + NL + "\t\t public JET2Template newTemplate() {" + NL + " return new ";
- protected final String TEXT_5 = "();" + NL + "\t\t }" + NL + "\t\t });";
- protected final String TEXT_6 = NL + " }" + NL + " TemplateFactoryMethod factory = (TemplateFactoryMethod)pathToFactoryMap.get(templatePath);" + NL + "\t\treturn factory == null ? null : factory.newTemplate();" + NL + "\t}" + NL + "" + NL + "}" + NL;
- protected final String TEXT_7 = NL;
+ protected final String TEXT_1 = "package ";
+ protected final String TEXT_2 = ";" + NL + "" + NL + "import java.util.HashMap;" + NL + "import java.util.Map;" + NL + "" + NL + "import org.eclipse.jet.JET2TemplateLoader;" + NL + "import org.eclipse.jet.JET2TemplateLoaderExtension;" + NL + "import org.eclipse.jet.JET2Template;" + NL + "" + NL + "public class ";
+ protected final String TEXT_3 = " implements JET2TemplateLoader, JET2TemplateLoaderExtension {" + NL + "" + NL + "\tprivate interface TemplateFactoryMethod {" + NL + "\t\tpublic abstract JET2Template newTemplate();" + NL + "\t}" + NL + "" + NL + "\tprivate Map pathToFactoryMap = null;" + NL + "\t" + NL + "\tprivate JET2TemplateLoader delegate = null;" + NL + "" + NL + "\tpublic ";
+ protected final String TEXT_4 = "() {" + NL + "\t\tsuper();" + NL + "\t}" + NL + "" + NL + "\tpublic JET2Template getTemplate(String templatePath) {" + NL + "\t if(pathToFactoryMap == null) {" + NL + "\t pathToFactoryMap = new HashMap(";
+ protected final String TEXT_5 = ");";
+ protected final String TEXT_6 = NL + "\t\t pathToFactoryMap.put(\"";
+ protected final String TEXT_7 = "\"," + NL + "\t\t new TemplateFactoryMethod() {" + NL + "\t\t public JET2Template newTemplate() {" + NL + " return new ";
+ protected final String TEXT_8 = "();" + NL + "\t\t }" + NL + "\t\t });";
+ protected final String TEXT_9 = NL + " }" + NL + " TemplateFactoryMethod factory = (TemplateFactoryMethod)pathToFactoryMap.get(templatePath);" + NL + "\t\treturn factory == null ? delegate == null ? null : delegate.getTemplate(templatePath) : factory.newTemplate();" + NL + "\t}" + NL + "" + NL + " public void setDelegateLoader(JET2TemplateLoader loader) {" + NL + " this.delegate = loader;" + NL + " }" + NL + " " + NL + " public JET2TemplateLoader getDelegateLoader() {" + NL + " return delegate;" + NL + " }" + NL + "}" + NL;
+ protected final String TEXT_10 = NL;
public String generate(Object argument)
{
final StringBuffer stringBuffer = new StringBuffer();
-Map templateMap = (Map) argument;
+LoaderGenerationParameters parms = (LoaderGenerationParameters)argument;
+Map templateMap = (Map) parms.getTemplateMap();;
stringBuffer.append(TEXT_1);
- stringBuffer.append( templateMap.size() );
+ stringBuffer.append( parms.getPackageName() );
stringBuffer.append(TEXT_2);
+ stringBuffer.append( parms.getClassName() );
+ stringBuffer.append(TEXT_3);
+ stringBuffer.append( parms.getClassName() );
+ stringBuffer.append(TEXT_4);
+ stringBuffer.append( templateMap.size() );
+ stringBuffer.append(TEXT_5);
for(Iterator i = templateMap.entrySet().iterator(); i.hasNext();){
Map.Entry entry = (Map.Entry)i.next();
- stringBuffer.append(TEXT_3);
+ stringBuffer.append(TEXT_6);
stringBuffer.append( entry.getKey() );
- stringBuffer.append(TEXT_4);
+ stringBuffer.append(TEXT_7);
stringBuffer.append( entry.getValue() );
- stringBuffer.append(TEXT_5);
+ stringBuffer.append(TEXT_8);
}
- stringBuffer.append(TEXT_6);
- stringBuffer.append(TEXT_7);
+ stringBuffer.append(TEXT_9);
+ stringBuffer.append(TEXT_10);
return stringBuffer.toString();
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/IncludeTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/IncludeTag.java
index 40aab4c..8702fa0 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/IncludeTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/IncludeTag.java
@@ -17,13 +17,12 @@
package org.eclipse.jet.internal.taglib.control;
-import java.util.HashMap;
-import java.util.Iterator;
+import java.text.MessageFormat;
import java.util.Map;
-import java.util.StringTokenizer;
import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Writer;
+import org.eclipse.jet.internal.l10n.JET2Messages;
import org.eclipse.jet.taglib.AbstractEmptyTag;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagInfo;
@@ -52,25 +51,39 @@ public class IncludeTag extends AbstractEmptyTag
{
String template = getAttribute("template"); //$NON-NLS-1$
String restoreNames = getAttribute("restoreNames"); //$NON-NLS-1$
+ String passVariables = getAttribute("passVariables"); //$NON-NLS-1$
- Map savedVariableValues = null;
- if (restoreNames != null)
+ if(restoreNames != null && passVariables != null)
{
- savedVariableValues = new HashMap();
- for (StringTokenizer tokenizer = new StringTokenizer(restoreNames, ","); tokenizer.hasMoreTokens();) { //$NON-NLS-1$
- String varName = tokenizer.nextToken();
- savedVariableValues.put(varName, context.getVariable(varName));
- }
+ throw new JET2TagException(MessageFormat.format(JET2Messages.AnyTag_MutuallyExclusiveAttributes,
+ new Object[] {"restoreNames", "passVariables"})); //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ Map savedVariableValues;
+ if(passVariables != null)
+ {
+ savedVariableValues = context.getVariables();
+ context.setVariables(context.extractVariables(passVariables));
+ }
+ else
+ {
+ savedVariableValues = context.extractVariables(restoreNames);
}
- TransformContextExtender tce = new TransformContextExtender(context);
- tce.execute(template, out);
- if (savedVariableValues != null)
+ try
{
- for (Iterator i = savedVariableValues.entrySet().iterator(); i.hasNext();)
+ TransformContextExtender tce = new TransformContextExtender(context);
+ tce.execute(template, out);
+ }
+ finally
+ {
+ if(restoreNames != null)
+ {
+ context.restoreVariables(savedVariableValues);
+ }
+ else if(passVariables != null)
{
- Map.Entry entry = (Map.Entry)i.next();
- context.setVariable((String)entry.getKey(), entry.getValue());
+ context.setVariables(savedVariableValues);
}
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/InvokeTransformTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/InvokeTransformTag.java
new file mode 100644
index 0000000..f2bb9ce
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/InvokeTransformTag.java
@@ -0,0 +1,88 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.internal.taglib.control;
+
+import java.text.MessageFormat;
+import java.util.Map;
+
+import org.eclipse.jet.JET2Context;
+import org.eclipse.jet.JET2Writer;
+import org.eclipse.jet.internal.l10n.JET2Messages;
+import org.eclipse.jet.taglib.AbstractEmptyTag;
+import org.eclipse.jet.taglib.JET2TagException;
+import org.eclipse.jet.taglib.TagInfo;
+import org.eclipse.jet.transform.TransformContextExtender;
+
+/**
+ * Implementation of the Standard JET Control Tag &lt;c:invoke transformId="..." [restoreNames="..."]/&gt;.
+ */
+public class InvokeTransformTag extends AbstractEmptyTag
+{
+
+ /**
+ *
+ */
+ public InvokeTransformTag()
+ {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.taglib.EmptyTag#doAction(org.eclipse.jet.taglib.TagInfo, org.eclipse.jet.JET2Context, org.eclipse.jet.JET2Writer)
+ */
+ public void doAction(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
+ {
+ String transformId = getAttribute("transformId"); //$NON-NLS-1$
+
+ String restoreNames = getAttribute("restoreNames"); //$NON-NLS-1$
+ String passVariables = getAttribute("passVariables"); //$NON-NLS-1$
+
+ if(restoreNames != null && passVariables != null)
+ {
+ throw new JET2TagException(MessageFormat.format(JET2Messages.AnyTag_MutuallyExclusiveAttributes,
+ new Object[] {"restoreNames", "passVariables"})); //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ Map savedVariableValues;
+ if(passVariables != null)
+ {
+ savedVariableValues = context.getVariables();
+ context.setVariables(context.extractVariables(passVariables));
+ }
+ else
+ {
+ savedVariableValues = context.extractVariables(restoreNames);
+ }
+
+ try
+ {
+ TransformContextExtender.getInstance(context).runSubTransform(transformId);
+ }
+ finally
+ {
+ if(restoreNames != null)
+ {
+ context.restoreVariables(savedVariableValues);
+ }
+ else if(passVariables != null)
+ {
+ context.setVariables(savedVariableValues);
+ }
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/LoadTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/LoadTag.java
index 7805bb7..e96b860 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/LoadTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/LoadTag.java
@@ -23,10 +23,10 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.text.MessageFormat;
+import org.eclipse.jet.CoreJETException;
import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.internal.l10n.JET2Messages;
-import org.eclipse.jet.internal.runtime.model.CoreJETException;
import org.eclipse.jet.taglib.AbstractEmptyTag;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagInfo;
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/OverrideTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/OverrideTag.java
new file mode 100644
index 0000000..38fd04e
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/OverrideTag.java
@@ -0,0 +1,51 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.internal.taglib.control;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jet.JET2Context;
+import org.eclipse.jet.JET2Writer;
+import org.eclipse.jet.taglib.AbstractEmptyTag;
+import org.eclipse.jet.taglib.JET2TagException;
+import org.eclipse.jet.taglib.TagInfo;
+import org.eclipse.jet.transform.TransformContextExtender;
+
+/**
+ * Implement the standard JET tag &lt;c:override transformId="..."/&gt;.
+ */
+public class OverrideTag extends AbstractEmptyTag
+{
+
+ /**
+ *
+ */
+ public OverrideTag()
+ {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.taglib.EmptyTag#doAction(org.eclipse.jet.taglib.TagInfo, org.eclipse.jet.JET2Context, org.eclipse.jet.JET2Writer)
+ */
+ public void doAction(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
+ {
+ String transformId = getAttribute("transformId"); //$NON-NLS-1$
+
+ TransformContextExtender.getInstance(context).setOverride(transformId, new NullProgressMonitor());
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/templates/jet2java.javajet b/plugins/org.eclipse.jet/templates/jet2java.javajet
index f13dfc7..c4ba6b0 100644
--- a/plugins/org.eclipse.jet/templates/jet2java.javajet
+++ b/plugins/org.eclipse.jet/templates/jet2java.javajet
@@ -1,6 +1,6 @@
<%@jet package="org.eclipse.jet.internal.compiler.templates"
class="JET2JavaGenerator"
- imports="org.eclipse.jet.internal.compiler.* org.eclipse.jet.compiler.* java.util.Iterator"
+ imports="org.eclipse.jet.internal.compiler.* org.eclipse.jet.compiler.* org.eclipse.jet.taglib.TagLibraryReference java.util.Iterator java.util.Map"
%>
<%
JET2CompilationUnit cu = (JET2CompilationUnit)argument;
@@ -13,19 +13,18 @@
});
final StringBuffer tagNamespaceVariables = new StringBuffer();
- cu.accept(new DefaultJET2ASTVisitor() {
- public void visit(JET2Directive directive) {
- if("taglib".equals(directive.getName())) {
+ TagLibraryReference[] tlRefs = cu.getTagLibraryReferences();
+ for(int i = 0; i < tlRefs.length; i++ ) {
+ ;
tagNamespaceVariables.append("public static final String _jetns_")
- .append(directive.getAttributes().get("prefix"))
+ .append(tlRefs[i].getPrefix())
.append(" = \"")
- .append(directive.getAttributes().get("id"))
+ .append(tlRefs[i].getTagLibraryId())
.append("\";")
.append("//$NON-NLS-1$")
.append(NL);
- }
- }
- });
+
+ }
final StringBuffer tagDataDeclarations = new StringBuffer();
cu.accept(new DefaultJET2ASTVisitor() {
diff --git a/plugins/org.eclipse.jet/templates/jet2transform.javajet b/plugins/org.eclipse.jet/templates/jet2transform.javajet
index c29f539..77bdd59 100644
--- a/plugins/org.eclipse.jet/templates/jet2transform.javajet
+++ b/plugins/org.eclipse.jet/templates/jet2transform.javajet
@@ -1,27 +1,31 @@
<%@jet package="org.eclipse.jet.internal.compiler.templates"
class="JET2TransformGenerator"
- imports="java.util.Map java.util.Iterator"
+ imports="java.util.Map java.util.Iterator org.eclipse.jet.internal.compiler.LoaderGenerationParameters"
%>
<%
-Map templateMap = (Map) argument;
+LoaderGenerationParameters parms = (LoaderGenerationParameters)argument;
+Map templateMap = (Map) parms.getTemplateMap();;
%>
-package org.eclipse.jet.compiled;
+package <%= parms.getPackageName() %>;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jet.JET2TemplateLoader;
+import org.eclipse.jet.JET2TemplateLoaderExtension;
import org.eclipse.jet.JET2Template;
-public class _jet_transformation implements JET2TemplateLoader {
+public class <%= parms.getClassName() %> implements JET2TemplateLoader, JET2TemplateLoaderExtension {
private interface TemplateFactoryMethod {
public abstract JET2Template newTemplate();
}
private Map pathToFactoryMap = null;
+
+ private JET2TemplateLoader delegate = null;
- public _jet_transformation() {
+ public <%= parms.getClassName() %>() {
super();
}
@@ -40,8 +44,15 @@ public class _jet_transformation implements JET2TemplateLoader {
<% } %>
}
TemplateFactoryMethod factory = (TemplateFactoryMethod)pathToFactoryMap.get(templatePath);
- return factory == null ? null : factory.newTemplate();
+ return factory == null ? delegate == null ? null : delegate.getTemplate(templatePath) : factory.newTemplate();
}
+ public void setDelegateLoader(JET2TemplateLoader loader) {
+ this.delegate = loader;
+ }
+
+ public JET2TemplateLoader getDelegateLoader() {
+ return delegate;
+ }
}