Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2007-11-29 18:20:24 -0500
committerpelder2007-11-29 18:20:24 -0500
commitdcff51d99754130c296a22e206133fed1801af64 (patch)
tree0ec18f5096d8e3a5bcd6708a2c8ba0001ac116d5
parentdf520d24a484d885343bdb0279c826187b6a2eae (diff)
downloadorg.eclipse.jet-dcff51d99754130c296a22e206133fed1801af64.tar.gz
org.eclipse.jet-dcff51d99754130c296a22e206133fed1801af64.tar.xz
org.eclipse.jet-dcff51d99754130c296a22e206133fed1801af64.zip
[211516] Performance: Create a factory class for tag libraries
-rw-r--r--plugins/org.eclipse.jet/Generate Tag Factories (org.eclipse.jet).launch9
-rw-r--r--transforms/org.eclipse.jet.transforms.tagfactory/.classpath7
-rw-r--r--transforms/org.eclipse.jet.transforms.tagfactory/.project29
-rw-r--r--transforms/org.eclipse.jet.transforms.tagfactory/.settings/org.eclipse.core.resources.prefs4
-rw-r--r--transforms/org.eclipse.jet.transforms.tagfactory/META-INF/MANIFEST.MF9
-rw-r--r--transforms/org.eclipse.jet.transforms.tagfactory/build.properties9
-rw-r--r--transforms/org.eclipse.jet.transforms.tagfactory/plugin.xml20
-rw-r--r--transforms/org.eclipse.jet.transforms.tagfactory/sample.xml3
-rw-r--r--transforms/org.eclipse.jet.transforms.tagfactory/templates/dump.jet2
-rw-r--r--transforms/org.eclipse.jet.transforms.tagfactory/templates/main.jet45
-rw-r--r--transforms/org.eclipse.jet.transforms.tagfactory/templates/tagLibrary/tagFactory.java.jet60
11 files changed, 197 insertions, 0 deletions
diff --git a/plugins/org.eclipse.jet/Generate Tag Factories (org.eclipse.jet).launch b/plugins/org.eclipse.jet/Generate Tag Factories (org.eclipse.jet).launch
new file mode 100644
index 0000000..2e31be6
--- /dev/null
+++ b/plugins/org.eclipse.jet/Generate Tag Factories (org.eclipse.jet).launch
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<launchConfiguration type="org.eclipse.jet.jet2Transformation">
+<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
+<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
+</listAttribute>
+<stringAttribute key="org.eclipse.jet.id" value="org.eclipse.jet.transforms.tagfactory"/>
+<intAttribute key="org.eclipse.jet.logFilterLevel" value="3"/>
+<stringAttribute key="org.eclipse.jet.source" value="org.eclipse.jet/plugin.xml"/>
+</launchConfiguration>
diff --git a/transforms/org.eclipse.jet.transforms.tagfactory/.classpath b/transforms/org.eclipse.jet.transforms.tagfactory/.classpath
new file mode 100644
index 0000000..d4a97a3
--- /dev/null
+++ b/transforms/org.eclipse.jet.transforms.tagfactory/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="jet2java"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/transforms/org.eclipse.jet.transforms.tagfactory/.project b/transforms/org.eclipse.jet.transforms.tagfactory/.project
new file mode 100644
index 0000000..0c2ade2
--- /dev/null
+++ b/transforms/org.eclipse.jet.transforms.tagfactory/.project
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.jet.transforms.tagfactory</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jet.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.jet.jet2Nature</nature>
+ </natures>
+</projectDescription>
diff --git a/transforms/org.eclipse.jet.transforms.tagfactory/.settings/org.eclipse.core.resources.prefs b/transforms/org.eclipse.jet.transforms.tagfactory/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..fca210c
--- /dev/null
+++ b/transforms/org.eclipse.jet.transforms.tagfactory/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,4 @@
+#Wed Nov 21 09:17:01 EST 2007
+eclipse.preferences.version=1
+encoding//jet2java/org/eclipse/jet/compiled/_jet_tagFactoryjava.java=UTF-8
+encoding//templates/tagLibrary/tagFactory.java.jet=UTF-8
diff --git a/transforms/org.eclipse.jet.transforms.tagfactory/META-INF/MANIFEST.MF b/transforms/org.eclipse.jet.transforms.tagfactory/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..f14b82f
--- /dev/null
+++ b/transforms/org.eclipse.jet.transforms.tagfactory/META-INF/MANIFEST.MF
@@ -0,0 +1,9 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: org.eclipse.jet.transforms.tagfactory
+Bundle-SymbolicName: org.eclipse.jet.transforms.tagfactory;singleton:=true
+Bundle-Version: 1.0.0
+Bundle-Localization: plugin
+Bundle-Vendor:
+Require-Bundle: org.eclipse.jet
+Bundle-ClassPath: .,bin/
diff --git a/transforms/org.eclipse.jet.transforms.tagfactory/build.properties b/transforms/org.eclipse.jet.transforms.tagfactory/build.properties
new file mode 100644
index 0000000..cb23e8a
--- /dev/null
+++ b/transforms/org.eclipse.jet.transforms.tagfactory/build.properties
@@ -0,0 +1,9 @@
+source.. = jet2java/
+output.. = bin/
+bin.includes = .,\
+ plugin.xml,\
+ META-INF/,\
+ templates/
+src.includes = .project,\
+ build.properties,\
+ .classpath
diff --git a/transforms/org.eclipse.jet.transforms.tagfactory/plugin.xml b/transforms/org.eclipse.jet.transforms.tagfactory/plugin.xml
new file mode 100644
index 0000000..f3f2a17
--- /dev/null
+++ b/transforms/org.eclipse.jet.transforms.tagfactory/plugin.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.0"?>
+<plugin>
+ <extension
+ id=""
+ name=""
+ point="org.eclipse.jet.transform">
+ <transform
+ startTemplate="templates/main.jet"
+ templateLoaderClass="org.eclipse.jet.compiled._jet_transformation" >
+ <description></description>
+ <tagLibraries>
+ <importLibrary id="org.eclipse.jet.controlTags" usePrefix="c" autoImport="true"/>
+ <importLibrary id="org.eclipse.jet.javaTags" usePrefix="java" autoImport="true"/>
+ <importLibrary id="org.eclipse.jet.formatTags" usePrefix="f" autoImport="true"/>
+ <importLibrary id="org.eclipse.jet.workspaceTags" usePrefix="ws" autoImport="false"/>
+ </tagLibraries>
+ </transform>
+ </extension>
+</plugin> \ No newline at end of file
diff --git a/transforms/org.eclipse.jet.transforms.tagfactory/sample.xml b/transforms/org.eclipse.jet.transforms.tagfactory/sample.xml
new file mode 100644
index 0000000..84ff56b
--- /dev/null
+++ b/transforms/org.eclipse.jet.transforms.tagfactory/sample.xml
@@ -0,0 +1,3 @@
+<root>
+
+</root> \ No newline at end of file
diff --git a/transforms/org.eclipse.jet.transforms.tagfactory/templates/dump.jet b/transforms/org.eclipse.jet.transforms.tagfactory/templates/dump.jet
new file mode 100644
index 0000000..5ced365
--- /dev/null
+++ b/transforms/org.eclipse.jet.transforms.tagfactory/templates/dump.jet
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8"?>
+<c:dump select="/*" format="true" entities="true"/>
diff --git a/transforms/org.eclipse.jet.transforms.tagfactory/templates/main.jet b/transforms/org.eclipse.jet.transforms.tagfactory/templates/main.jet
new file mode 100644
index 0000000..70a2c8c
--- /dev/null
+++ b/transforms/org.eclipse.jet.transforms.tagfactory/templates/main.jet
@@ -0,0 +1,45 @@
+<%@taglib prefix="ws" id="org.eclipse.jet.workspaceTags" %>
+<%-- Main entry point for org.eclipse.jet.transforms.tagfactory --%>
+
+<c:setVariable var="plugin" select="/plugin"/>
+<%--
+TODO: traverse input model, performing calculations and storing
+the results as model annotations via c:set tag
+--%>
+<c:iterate select="$plugin/extension[@point='org.eclipse.jet.tagLibraries']" var="extension">
+ <c:iterate select="$extension/tagLibrary[@tagFactory]" var="tagLibrary">
+ <c:setVariable var="ordinal" select="1"/>
+ <c:set select="$tagLibrary" name="numTags"><c:get select="count($tagLibrary/*['Tag' = substring(local-name(), string-length(local-name()) - 2, 3)])"/></c:set>
+ <c:set select="$tagLibrary" name="pkgFactory"><c:get select="packageName($tagLibrary/@tagFactory)"/></c:set>
+ <c:set select="$tagLibrary" name="clsFactory"><c:get select="className($tagLibrary/@tagFactory)"/></c:set>
+ <c:iterate select="$tagLibrary/*['Tag' = substring(local-name(), string-length(local-name()) - 2, 3)]" var="tag">
+ <c:set select="$tag" name="ordinal"><c:get select="$ordinal"/></c:set>
+ <c:setVariable var="ordinal" select="$ordinal + 1"/>
+ </c:iterate>
+ </c:iterate>
+</c:iterate>
+
+
+<%--
+TODO: traverse annotated model, performing text generation actions
+such as ws:file, ws:folder and ws:project
+--%>
+<c:iterate select="$plugin/extension[@point='org.eclipse.jet.tagLibraries']" var="extension">
+ <c:iterate select="$extension/tagLibrary[@tagFactory]" var="tagLibrary">
+ <java:class srcFolder="{$org.eclipse.jet.resource.project.name}/src"
+ package="{$tagLibrary/@pkgFactory}"
+ name="{$tagLibrary/@clsFactory}"
+ template="templates/tagLibrary/tagFactory.java.jet"/>
+ </c:iterate>
+</c:iterate>
+
+
+<%-- For debug purposes, dump the annotated input model in
+ the root of the project containing the original input model.
+
+ Note that model formatting may not be identical, and that in
+ the case of non-XML input models, the dump may look quite different.
+
+<ws:file template="templates/dump.jet" path="{$org.eclipse.jet.resource.project.name}/dump.xml"/>
+--%>
+
diff --git a/transforms/org.eclipse.jet.transforms.tagfactory/templates/tagLibrary/tagFactory.java.jet b/transforms/org.eclipse.jet.transforms.tagfactory/templates/tagLibrary/tagFactory.java.jet
new file mode 100644
index 0000000..b9b7f6f
--- /dev/null
+++ b/transforms/org.eclipse.jet.transforms.tagfactory/templates/tagLibrary/tagFactory.java.jet
@@ -0,0 +1,60 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: tagFactory.java.jet,v 1.1 2007/11/29 23:20:24 pelder Exp $
+ */
+package <c:get select="$tagLibrary/@pkgFactory"/>;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jet.taglib.CustomTag;
+import org.eclipse.jet.taglib.JET2TagException;
+import org.eclipse.jet.taglib.TagInstanceFactory;
+
+/**
+ * Tag Factory for <c:get select="$tagLibrary/@id"/>
+ */
+public class <c:get select="$tagLibrary/@clsFactory"/> implements TagInstanceFactory
+{
+
+ private final Map tagOrdinalByName;
+
+ /**
+ *
+ */
+ public <c:get select="$tagLibrary/@clsFactory"/>()
+ {
+ tagOrdinalByName = new HashMap(<c:get select="$tagLibrary/@numTags"/>);
+
+<c:iterate select="$tagLibrary/*['Tag' = substring(local-name(), string-length(local-name()) - 2, 3)]" var="tag">
+ tagOrdinalByName.put("<c:get select="$tag/@name"/>",new Integer(<c:get select="$tag/@ordinal"/>)); //$NON-NLS-1$
+</c:iterate>
+ }
+
+ public CustomTag createCustomTag(String name)
+ {
+ Integer ordinal = (Integer)tagOrdinalByName.get(name);
+
+ switch(ordinal == null ? 0 : ordinal.intValue()) {
+<c:iterate select="$tagLibrary/*['Tag' = substring(local-name(), string-length(local-name()) - 2, 3)]" var="tag">
+ case <c:get select="$tag/@ordinal"/>: // <c:get select="$tag/@name"/>
+ return new <c:get select="$tag/@class"/>();
+</c:iterate>
+ default:
+ throw new JET2TagException("Unknown Tag: " + name); //$NON-NLS-1$
+ }
+ }
+
+}

Back to the top