Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2009-04-22 15:45:47 -0400
committerpelder2009-04-22 15:45:47 -0400
commit98299495d60d03a828ede2ca7b5b4d7e812f0a3a (patch)
tree0576dc19e03669a9f1d41ac3546e69089c83e408
parenta4f1961bfbbff6d8074f1b79a53bede56b75ace0 (diff)
downloadorg.eclipse.jet-98299495d60d03a828ede2ca7b5b4d7e812f0a3a.tar.gz
org.eclipse.jet-98299495d60d03a828ede2ca7b5b4d7e812f0a3a.tar.xz
org.eclipse.jet-98299495d60d03a828ede2ca7b5b4d7e812f0a3a.zip
[273331] Provide an XPath function that gives access to an EObject's EClass
-rw-r--r--doc/org.eclipse.jet.doc/references/xpathFunctions/emf.eClassFunction.html78
-rw-r--r--doc/org.eclipse.jet.doc/references/xpathFunctions/overview.html12
-rw-r--r--doc/org.eclipse.jet.doc/references/xpathFunctions/uml2.stereotypeFunction.html4
-rw-r--r--doc/org.eclipse.jet.doc/toc.xml2
-rw-r--r--plugins/org.eclipse.jet/plugin.xml6
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/CodeGenTemplateLoader.java150
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/functions/extras/EClassFunction.java63
7 files changed, 241 insertions, 74 deletions
diff --git a/doc/org.eclipse.jet.doc/references/xpathFunctions/emf.eClassFunction.html b/doc/org.eclipse.jet.doc/references/xpathFunctions/emf.eClassFunction.html
new file mode 100644
index 0000000..7d50aca
--- /dev/null
+++ b/doc/org.eclipse.jet.doc/references/xpathFunctions/emf.eClassFunction.html
@@ -0,0 +1,78 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<HTML>
+<HEAD>
+<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<META name="GENERATOR" content="IBM Software Development Platform">
+<link rel="STYLESHEET" href="../../book.css" charset="ISO-8859-1" type="text/css"/>
+<TITLE>emf.eClass XPath function</TITLE>
+</HEAD>
+<BODY>
+<TABLE border="0" cellpadding="0" cellspacing="1" width="100%">
+ <TBODY>
+ <TR>
+ <TH align="left"><P>emf.eClass()</P></TH>
+ <TH align="right"><A href="overview.html">Additional XPath Functions</A></TH>
+ </TR>
+ </TBODY>
+</TABLE>
+<HR>
+<H2>emf.eClass</H2>
+<P>Return the EMF EClass of an object. If the object is not an EMF object than an empty result is returned.</P>
+<HR>
+<TABLE border="0" width="100%">
+ <TBODY>
+ <TR>
+ <TH colspan="2" align="left">Function Summary<BR>&nbsp;</TH></TR>
+ <TR>
+ <TD width="20%" valign="top">minimal arguments</TD>
+ <TD><SPAN style="font-family: monospace" valign="top">
+ Object emf.eClass ()<BR>&nbsp;<BR>
+ </SPAN></TD>
+ </TR>
+ <TR>
+ <TD width="20%" valign="top">all arguments</TD>
+ <TD><SPAN style="font-family: monospace" valign="top">
+ Object emf.eClass (Object object)<BR>&nbsp;<BR>
+ </SPAN></TD>
+ </TR>
+ </TBODY>
+</TABLE>
+<HR>
+<TABLE border="0" width="100%">
+ <TBODY>
+ <TR>
+ <TH colspan="2" align="left">There are no required argument<BR>&nbsp;</TH>
+ </TR>
+ </TBODY>
+</TABLE>
+<HR>
+<TABLE border="0" width="100%">
+ <TBODY>
+ <TR>
+ <TH colspan="2" align="left">Optional Arguments<BR>&nbsp;</TH>
+ </TR>
+ <TR>
+ <TD width="20%" valign="top"><B>Object object</B></TD>
+ <TD>An object reference for which the EClass is sought. If omitted, the XPath context object is used.</TD>
+ </TR>
+ </TBODY>
+</TABLE>
+<HR>
+<TABLE border="0" width="100%">
+ <TBODY>
+ <TR>
+ <TH colspan="2" align="left">Example<BR>&nbsp;</TH></TR>
+ <TR>
+ <TD colspan="2"><SPAN style="font-family: monospace">
+<!-- Begin emf.eClass example -->
+ <B>emf.eClass</B>($object)<br>
+ <P>retrn the EClass of $object or an empty result</P>
+<!-- End emf.eClass example -->
+</SPAN></TD>
+ </TR>
+ </TBODY>
+</TABLE>
+<P><BR>
+<FONT color="navy" size="-2">&copy; Copyright IBM Corporation 2000,
+2006. All Rights Reserved.</FONT></P></P></BODY>
+</HTML>
diff --git a/doc/org.eclipse.jet.doc/references/xpathFunctions/overview.html b/doc/org.eclipse.jet.doc/references/xpathFunctions/overview.html
index 27fdc11..f0d4313 100644
--- a/doc/org.eclipse.jet.doc/references/xpathFunctions/overview.html
+++ b/doc/org.eclipse.jet.doc/references/xpathFunctions/overview.html
@@ -39,6 +39,14 @@ The following functions are included in JET, in addition to the XPath functions
<!-- End className description -->
</TD>
</TR>
+ <TR>
+ <TD width="10%"><A href="emf.eClassFunction.html">emf.eClass</A></TD>
+ <TD>
+ <!-- Begin emf.eClass description -->
+ Return the EMF EClass of an object.
+ <!-- End emf.eClass description -->
+ </TD>
+ </TR>
<TR>
<TD width="10%"><A href="escapeJavaWhitespaceFunction.html">escapeJavaWhitespace</A></TD>
<TD>
@@ -122,9 +130,9 @@ The following functions are included in JET, in addition to the XPath functions
<TR>
<TD width="10%"><A href="uml2.stereotypeFunction.html">uml2.stereotype</A></TD>
<TD>
- <!-- Begin upper-case description -->
+ <!-- Begin uml2.stereotype description -->
Access a named UML2 stereotype on a UML2 element
- <!-- End upper-case description -->
+ <!-- End uml2.stereotype description -->
</TD>
</TR>
<TR>
diff --git a/doc/org.eclipse.jet.doc/references/xpathFunctions/uml2.stereotypeFunction.html b/doc/org.eclipse.jet.doc/references/xpathFunctions/uml2.stereotypeFunction.html
index d858093..8049205 100644
--- a/doc/org.eclipse.jet.doc/references/xpathFunctions/uml2.stereotypeFunction.html
+++ b/doc/org.eclipse.jet.doc/references/xpathFunctions/uml2.stereotypeFunction.html
@@ -4,13 +4,13 @@
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM Software Development Platform">
<link rel="STYLESHEET" href="../../book.css" charset="ISO-8859-1" type="text/css"/>
-<TITLE>upper-case XPath function</TITLE>
+<TITLE>uml2.stereotype XPath function</TITLE>
</HEAD>
<BODY>
<TABLE border="0" cellpadding="0" cellspacing="1" width="100%">
<TBODY>
<TR>
- <TH align="left"><P>upper-case()</P></TH>
+ <TH align="left"><P>uml2.stereotype()</P></TH>
<TH align="right"><A href="overview.html">Additional XPath Functions</A></TH>
</TR>
</TBODY>
diff --git a/doc/org.eclipse.jet.doc/toc.xml b/doc/org.eclipse.jet.doc/toc.xml
index 8e0cb49..c774a0f 100644
--- a/doc/org.eclipse.jet.doc/toc.xml
+++ b/doc/org.eclipse.jet.doc/toc.xml
@@ -44,7 +44,9 @@
<topic label="camelCase" href="references/xpathFunctions/camelCaseFunction.html"/>
<topic label="cardinality" href="references/xpathFunctions/cardinalityFunction.html"/>
<topic label="className" href="references/xpathFunctions/classNameFunction.html"/>
+ <topic label="emf.eClass" href="references/xpathFunctions/emf.eClassFunction.html"/>
<topic label="escapeJavaWhitespace" href="references/xpathFunctions/escapeJavaWhitespaceFunction.html"/>
+ <topic label="eval" href="references/xpathFunctions/evalFunction.html"/>
<topic href="references/xpathFunctions/isVariableDefined.html" label="isVariableDefined">
</topic>
<topic label="lower-case" href="references/xpathFunctions/lower_caseFunction.html"/>
diff --git a/plugins/org.eclipse.jet/plugin.xml b/plugins/org.eclipse.jet/plugin.xml
index 85a8bfe..122bee7 100644
--- a/plugins/org.eclipse.jet/plugin.xml
+++ b/plugins/org.eclipse.jet/plugin.xml
@@ -1523,6 +1523,12 @@ See the documentation for the Java class java.util.Locale for details on languag
minArgs="1"
name="eval">
</function>
+ <function
+ implementation="org.eclipse.jet.internal.xpath.functions.extras.EClassFunction"
+ maxArgs="1"
+ minArgs="0"
+ name="emf.eClass">
+ </function>
</extension>
<extension
point="org.eclipse.ant.core.antTasks">
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/CodeGenTemplateLoader.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/CodeGenTemplateLoader.java
index 41cd8b5..2781d45 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/CodeGenTemplateLoader.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/CodeGenTemplateLoader.java
@@ -3,90 +3,100 @@ package org.eclipse.jet.internal.compiler.templates;
import java.util.HashMap;
import java.util.Map;
+import org.eclipse.jet.JET2Template;
import org.eclipse.jet.JET2TemplateLoader;
import org.eclipse.jet.JET2TemplateLoaderExtension;
-import org.eclipse.jet.JET2Template;
-
-public class CodeGenTemplateLoader implements JET2TemplateLoader, JET2TemplateLoaderExtension {
-
- private static final class TemplateFactoryMethod {
-
- private final String templatePath;
- private final String templateClass;
-
- public TemplateFactoryMethod(String templatePath, String templateClass) {
- this.templatePath = templatePath;
- this.templateClass = templateClass;
-
- }
-
- public String getTemplateClass() {
- return this.templateClass;
- }
-
- public String getTemplatePath() {
- return this.templatePath;
- }
- public JET2Template newTemplate() {
- JET2Template template = null;
- try {
- template = (JET2Template) Class.forName(this.templateClass).newInstance();
- } catch (InstantiationException e) {
- // ignore
- } catch (IllegalAccessException e) {
- // ignore
- } catch (ClassNotFoundException e) {
- // ignore
- }
- return template;
- }
-
-
- }
+public class CodeGenTemplateLoader implements JET2TemplateLoader,
+ JET2TemplateLoaderExtension {
- private Map pathToFactoryMap = null;
-
private JET2TemplateLoader delegate = null;
- public CodeGenTemplateLoader() {
- super();
+ private static Map pathToTemplateOrdinalMap = null;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jet.JET2TemplateLoaderExtension#getDelegateLoader()
+ */
+ public JET2TemplateLoader getDelegateLoader() {
+ return delegate;
}
- public JET2Template getTemplate(String templatePath) {
- if(this.pathToFactoryMap == null) {
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jet.JET2TemplateLoader#getTemplate(java.lang.String)
+ */
+ public JET2Template getTemplate(final String templatePath) {
+ if (pathToTemplateOrdinalMap == null) {
initPathToFactoryMap();
}
- TemplateFactoryMethod factory = (TemplateFactoryMethod)this.pathToFactoryMap.get(templatePath);
- return factory == null ? this.delegate == null ? null : this.delegate.getTemplate(templatePath) : factory.newTemplate();
+ final Integer ordinal = (Integer)pathToTemplateOrdinalMap.get(templatePath);
+ switch (ordinal != null ? ordinal.intValue() : -1) {
+ case 0: // templates/jet2java.jet
+ return new org.eclipse.jet.internal.compiler.templates.JET2JavaGenerator();
+ case 1: // templates/jet2transform.jet
+ return new org.eclipse.jet.internal.compiler.templates.JET2TransformGenerator();
+ case 2: // templates/jetTemplateMap.properties.jet
+ return new org.eclipse.jet.internal.compiler.templates.JETTemplateMapGenerator();
+ case 3: // templates/main.jet
+ return new org.eclipse.jet.internal.compiler.templates.DummyMain();
+ case 4: // templates/tagDataDeclarations.jet
+ return new org.eclipse.jet.internal.compiler.templates.TagDataDeclGenerator();
+ case 5: // templates/v1/jet2java.jet
+ return new org.eclipse.jet.internal.compiler.templates.v1.JET1JavaGenerator();
+ case 6: // templates/v2/jet2java.jet
+ return new org.eclipse.jet.internal.compiler.templates.v2.JET2JavaGeneratorNew();
+ case 7: // templates/writeJavaExpression.jet
+ return new org.eclipse.jet.internal.compiler.templates.WriteJavaExpressionTemplate();
+ case 8: // templates/writeTextElement.jet
+ return new org.eclipse.jet.internal.compiler.templates.WriteTextElementTemplate();
+ case 9: // templates/xmlEnd.jet
+ return new org.eclipse.jet.internal.compiler.templates.XMLEndGenerator();
+ case 10: // templates/xmlStart.jet
+ return new org.eclipse.jet.internal.compiler.templates.XMLStartGenerator();
+ default:
+ return delegate != null ? delegate.getTemplate(templatePath) : null;
+ }
}
- private void addTemplate(String templatePath, String templateClass) {
- this.pathToFactoryMap.put(templatePath,
- new TemplateFactoryMethod(templatePath, templateClass));
- }
-
- private void initPathToFactoryMap() {
- this.pathToFactoryMap = new HashMap(11);
- addTemplate("templates/jet2java.jet", "org.eclipse.jet.internal.compiler.templates.JET2JavaGenerator" ); //$NON-NLS-1$ //$NON-NLS-2$
- addTemplate("templates/jet2transform.jet", "org.eclipse.jet.internal.compiler.templates.JET2TransformGenerator" ); //$NON-NLS-1$ //$NON-NLS-2$
- addTemplate("templates/jetTemplateMap.properties.jet", "org.eclipse.jet.internal.compiler.templates.JETTemplateMapGenerator" ); //$NON-NLS-1$ //$NON-NLS-2$
- addTemplate("templates/main.jet", "org.eclipse.jet.internal.compiler.templates.DummyMain" ); //$NON-NLS-1$ //$NON-NLS-2$
- addTemplate("templates/tagDataDeclarations.jet", "org.eclipse.jet.internal.compiler.templates.TagDataDeclGenerator" ); //$NON-NLS-1$ //$NON-NLS-2$
- addTemplate("templates/v1/jet2java.jet", "org.eclipse.jet.internal.compiler.templates.v1.JET1JavaGenerator" ); //$NON-NLS-1$ //$NON-NLS-2$
- addTemplate("templates/v2/jet2java.jet", "org.eclipse.jet.internal.compiler.templates.v2.JET2JavaGeneratorNew" ); //$NON-NLS-1$ //$NON-NLS-2$
- addTemplate("templates/writeJavaExpression.jet", "org.eclipse.jet.internal.compiler.templates.WriteJavaExpressionTemplate" ); //$NON-NLS-1$ //$NON-NLS-2$
- addTemplate("templates/writeTextElement.jet", "org.eclipse.jet.internal.compiler.templates.WriteTextElementTemplate" ); //$NON-NLS-1$ //$NON-NLS-2$
- addTemplate("templates/xmlEnd.jet", "org.eclipse.jet.internal.compiler.templates.XMLEndGenerator" ); //$NON-NLS-1$ //$NON-NLS-2$
- addTemplate("templates/xmlStart.jet", "org.eclipse.jet.internal.compiler.templates.XMLStartGenerator" ); //$NON-NLS-1$ //$NON-NLS-2$
+ private static synchronized void initPathToFactoryMap() {
+ if (pathToTemplateOrdinalMap == null) {
+ pathToTemplateOrdinalMap = new HashMap(11);
+ pathToTemplateOrdinalMap.put("templates/jet2java.jet",
+ new Integer(0));
+ pathToTemplateOrdinalMap.put("templates/jet2transform.jet",
+ new Integer(1));
+ pathToTemplateOrdinalMap.put("templates/jetTemplateMap.properties.jet",
+ new Integer(2));
+ pathToTemplateOrdinalMap.put("templates/main.jet",
+ new Integer(3));
+ pathToTemplateOrdinalMap.put("templates/tagDataDeclarations.jet",
+ new Integer(4));
+ pathToTemplateOrdinalMap.put("templates/v1/jet2java.jet",
+ new Integer(5));
+ pathToTemplateOrdinalMap.put("templates/v2/jet2java.jet",
+ new Integer(6));
+ pathToTemplateOrdinalMap.put("templates/writeJavaExpression.jet",
+ new Integer(7));
+ pathToTemplateOrdinalMap.put("templates/writeTextElement.jet",
+ new Integer(8));
+ pathToTemplateOrdinalMap.put("templates/xmlEnd.jet",
+ new Integer(9));
+ pathToTemplateOrdinalMap.put("templates/xmlStart.jet",
+ new Integer(10));
+ }
}
- public void setDelegateLoader(JET2TemplateLoader loader) {
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jet.JET2TemplateLoaderExtension#setDelegateLoader(org.eclipse
+ * .jet.JET2TemplateLoader)
+ */
+ public void setDelegateLoader(final JET2TemplateLoader loader) {
this.delegate = loader;
}
-
- public JET2TemplateLoader getDelegateLoader() {
- return this.delegate;
- }
}
-
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/functions/extras/EClassFunction.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/functions/extras/EClassFunction.java
new file mode 100644
index 0000000..e00949c
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/functions/extras/EClassFunction.java
@@ -0,0 +1,63 @@
+/**
+ * Copyright (c) 2009 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
+ *
+ */
+package org.eclipse.jet.internal.xpath.functions.extras;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jet.xpath.Context;
+import org.eclipse.jet.xpath.XPathFunction;
+import org.eclipse.jet.xpath.XPathFunctionWithContext;
+
+/**
+ * Implement the XPath function 'emf.eClass( [Object object] )'
+ *
+ */
+public class EClassFunction implements XPathFunction,
+ XPathFunctionWithContext {
+
+ private Context context;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.XPathFunction#evaluate(java.util.List)
+ */
+ public Object evaluate(List args) {
+ Object target = args.size() == 0 ? context.getContextNode() : getFirstObject(args.get(0));
+
+ if(target instanceof EObject) {
+ return Collections.singletonList(((EObject)target).eClass());
+ } else {
+ return Collections.EMPTY_LIST;
+ }
+ }
+
+ private Object getFirstObject(Object object) {
+ if(object instanceof Collection) {
+ final Collection c = (Collection)object;
+ return c.size() > 0 ? c.iterator().next() : null;
+ } else {
+ return object;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.XPathFunctionWithContext#setContext(org.eclipse.jet.xpath.Context)
+ */
+ public void setContext(Context context) {
+ this.context = context;
+ // TODO Auto-generated method stub
+
+ }
+
+}

Back to the top