[Xpand] EvaluationException, no main found in xpand template [message #632089] |
Mon, 11 October 2010 14:08 |
masija . Messages: 59 Registered: July 2010 |
Member |
|
|
Hi @ all,
i am currently trying to run a mwe workflow , which should invoke a xpand template. This is done programmatically from an action within a gmf editor.
The mwe code looks like this:
<?xml version="1.0"?>
<workflow>
<bean class="org.eclipse.emf.mwe.utils.StandaloneSetup">
<platformUri value="../" />
<RegisterEcoreFile value="platform:/plugin/modeltransTest/templates/modeltrans.ecore"/>
</bean>
<component class="org.eclipse.emf.mwe.utils.Reader">
<uri value="${model}" />
<modelSlot value="model" />
<firstElementOnly value="false" />
</component>
<component class="org.eclipse.xpand2.Generator">
<metaModel id="mm" class="org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel"/>
<expand value="modeltrans2html::main FOR model.typeSelect(modeltrans::Canvas).first()"" />
<outlet path="${out}">
<postprocessor class="org.eclipse.xpand2.output.XmlBeautifier" />
</outlet>
</component>
</workflow>
The .xpt template like this:
«IMPORT 'http://modeltrans/1.0'»
«DEFINE main FOR modeltrans::Canvas»
«FILE self.title + '.html'»
<html>
<head><title>«title»</title></head>
<body>
<h1>«title» Report</h1>
«EXPAND index FOR self-»
<hr/>
«EXPAND nodeA FOREACH hasAs-»
«EXPAND nodeB FOREACH hasBs-»
</body>
</html>
«ENDFILE»
«ENDDEFINE»
«DEFINE index FOR modeltrans::Canvas-»
<h3>NodeAs</h3>
<ul>«EXPAND nodeAIndex FOREACH hasAs-»</ul>
<h3>NodeBs</h3>
<ul>«EXPAND nodeBIndex FOREACH hasBs-»</ul>
«ENDDEFINE»
«DEFINE nodeAIndex FOR modeltrans::NodeA»
<li><a href="#nodeA«title»"></a></li>
«ENDDEFINE»
«DEFINE nodeBIndex FOR modeltrans::NodeB»
<li><a href="#nodeB«title»"></a></li>
«ENDDEFINE»
«DEFINE nodeA FOR modeltrans::NodeA-»
<h3><a name="NodeA«title»"></a></h3>
«ENDDEFINE»
«DEFINE nodeB FOR modeltrans::NodeB-»
<h3><a name="NodeB«title»"></a></h3>
«ENDDEFINE»
Unfortunately, this doesn't works. Instead I get this error message:
11.10.2010 16:06:06 org.eclipse.emf.mwe.core.WorkflowRunner prepare
INFO: ------------------------------------------------------------ --------------------------
11.10.2010 16:06:06 org.eclipse.emf.mwe.core.WorkflowRunner prepare
INFO: EMF Modeling Workflow Engine 0.7.2, Build v200908120417
11.10.2010 16:06:06 org.eclipse.emf.mwe.core.WorkflowRunner prepare
INFO: (c) 2005-2009 openarchitectureware.org and contributors
11.10.2010 16:06:06 org.eclipse.emf.mwe.core.WorkflowRunner prepare
INFO: ------------------------------------------------------------ --------------------------
11.10.2010 16:06:06 org.eclipse.emf.mwe.core.WorkflowRunner prepare
INFO: running workflow: /E:/workspace/modeltransTest/templates/modeltrans2html.mwe
11.10.2010 16:06:06 org.eclipse.emf.mwe.core.WorkflowRunner prepare
INFO:
11.10.2010 16:06:06 org.eclipse.emf.mwe.core.container.CompositeComponent internalInvoke
INFO: Reader: Loading model from platform:/resource/test/default.modeltrans
11.10.2010 16:06:06 org.eclipse.emf.mwe.core.container.CompositeComponent internalInvoke
INFO: Generator: generating 'modeltrans2html::main FOR model.typeSelect(modeltrans::Canvas).first()' => E:\runtime-EclipseApplication(1)/test
11.10.2010 16:06:06 org.eclipse.xtend.expression.AbstractExpressionsUsingWorkflo wComponent invokeInternal
SCHWERWIEGEND: Error in Component of type org.eclipse.xpand2.Generator:
EvaluationException : No Definition 'modeltrans2html::main for modeltrans::Canvas' found!
[23,77] on line 1 'EXPAND modeltrans2html::main FOR model.typeSelect(modeltrans::Canvas).first()'
11.10.2010 16:06:06 org.eclipse.emf.mwe.core.WorkflowRunner executeWorkflow
SCHWERWIEGEND: Workflow interrupted. Reason: No Definition 'modeltrans2html::main for modeltrans::Canvas' found!
11.10.2010 16:06:06 org.eclipse.emf.mwe.core.WorkflowRunner logIssues
SCHWERWIEGEND: [ERROR]: No Definition 'modeltrans2html::main for modeltrans::Canvas' found!(Element: EXPAND modeltrans2html::main FOR model.typeSelect(modeltrans::Canvas).first(); Reported by: Generator: generating 'modeltrans2html::main FOR model.typeSelect(modeltrans::Canvas).first()' => E:\runtime-EclipseApplication(1)/test)
Does anybody know, what I am doing wrong?
I can't immagine why it doesn't find the main method, which is obviously defined in my .xpt Oo
Any help would be appreciated!
Thanks in advance and best regards,
Masija
[Updated on: Mon, 11 October 2010 17:38] Report message to a moderator
|
|
|
|
|
|
|
|
Re: [Xpand] EvaluationException, no main found in xpand template [message #632157 is a reply to message #632089] |
Mon, 11 October 2010 18:53 |
masija . Messages: 59 Registered: July 2010 |
Member |
|
|
Okay, I solved this problem, so thanks alot for your help
I had the template package with the xpt and the mwe file in my original gmf project.
Now I moved these files to the generated .diagram project.
For the mwe workflow file the different project was irrelevant, but obviously for the xpand template.
I attached the relevant code snippets, if someone else will have this problem.
The .xpt template generates just a bunch of crappy lines of html code, but it wasn't my intention to generate usefull code but to understand the concept.
all these files are contained in the .diagram plugin:
in the package templates:
«IMPORT templates::transformtest»
«DEFINE main FOR transformtest::Canvas»
«FILE title + '.html'»
<html>
<head><title>«title»</title></head>
<body>
<h1>«title» Report</h1>
<hr/>
«EXPAND nodeA FOREACH hasNodeAs-»
«EXPAND nodeB FOREACH hasNodeBs-»
</body>
</html>
«ENDFILE»
«ENDDEFINE»
«DEFINE index FOR transformtest::Canvas-»
<h3>NodeAs</h3>
<ul>«EXPAND nodeAIndex FOREACH hasNodeAs-»</ul>
<h3>NodeBs</h3>
<ul>«EXPAND nodeBIndex FOREACH hasNodeBs-»</ul>
«ENDDEFINE»
«DEFINE nodeAIndex FOR transformtest::NodeA»
<li><a href="#nodeA«this.title»"></a></li>
«ENDDEFINE»
«DEFINE nodeBIndex FOR transformtest::NodeB»
<li><a href="#nodeB«this.title»"></a></li>
«ENDDEFINE»
«DEFINE nodeA FOR transformtest::NodeA-»
<h3><a name="NodeA«title»"></a></h3>
«ENDDEFINE»
«DEFINE nodeB FOR transformtest::NodeB-»
<h3><a name="NodeB«title»"></a></h3>
«ENDDEFINE»
the custom action in the .part package:
package transformtest.diagram.part;
import java.net.URL;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.mwe.core.WorkflowRunner;
import org.eclipse.emf.mwe.core.monitor.NullProgressMonitor;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
public class StartTransformation implements IObjectActionDelegate {
private IWorkbenchPart targetPart;
private IFile file;
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
this.targetPart = targetPart;
}
public void selectionChanged(IAction action, ISelection selection) {
action.setEnabled(false);
if (selection instanceof IStructuredSelection == false || selection.isEmpty()) {
return;
}
file = (IFile) ((IStructuredSelection) selection).getFirstElement();
action.setEnabled(true);
}
public void run(IAction action) {
try {
EObject source = getInput();
if (source == null) {
String title = "title";
String message = "message";
MessageDialog.openInformation(getShell(), title, NLS.bind(message, file.getFullPath()));
} else {
URL url = FileLocator.toFileURL(new URL("platform:/plugin/de.transform.test.diagram/templates/transform2html.mwe"));
Map<String, String> properties = new HashMap<String, String>();
properties.put("model", URI.createPlatformResourceURI(file.getFullPath().toString(), true).toString());
properties.put("out", Platform.getLocation().toOSString() + file.getParent().getFullPath());
new WorkflowRunner().run(url.getPath(), new NullProgressMonitor(), properties, null);
file.getParent().refreshLocal(IResource.DEPTH_ONE, new org.eclipse.core.runtime.NullProgressMonitor());
}
} catch (Exception ex) {
handleError(ex);
}
}
private EObject getInput() {
ResourceSetImpl rs = new ResourceSetImpl();
return rs.getEObject(URI.createPlatformResourceURI(file.getFullPath().toString(), true).appendFragment("/"), true);
}
private void handleError(Throwable ex) {
MessageDialog.openError(getShell(), "Transformation failed", MessageFormat.format("{0}: {1}", ex.getClass().getSimpleName(), ex.getMessage() == null ? "no message" : ex.getMessage()));
}
private Shell getShell() {
return targetPart.getSite().getShell();
}
}
the mwe file in the folder /templates
<?xml version="1.0"?>
<workflow>
<bean class="org.eclipse.emf.mwe.utils.StandaloneSetup">
<platformUri value="../" />
<RegisterEcoreFile value="platform:/plugin/de.transform.test/model/transformtest.ecore"/>
</bean>
<component class="org.eclipse.emf.mwe.utils.Reader">
<uri value="${model}" />
<modelSlot value="model" />
<firstElementOnly value="false" />
</component>
<component class="org.eclipse.xpand2.Generator">
<metaModel id="mm" class="org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel"/>
<expand value="templates::transform2html::main FOR model.typeSelect(transformtest::Canvas).first()" />
<outlet path="${out}">
<postprocessor class="org.eclipse.xpand2.output.XmlBeautifier" />
</outlet>
</component>
</workflow>
and finally the object contribution for the custom gmf action which is added to the popupmenu-Extensionpoint
</objectContribution>
<objectContribution
id="de.transform.test.diagram.StartTransformation"
nameFilter="*.transformtest"
objectClass="org.eclipse.core.resources.IFile">
<action
class="transformtest.diagram.part.StartTransformation"
enablesFor="1"
id="de.transform.test.diagram.StartTransformationAction"
label="Transform"
menubarPath="additions">
</action>
</objectContribution>
Thanks alot for your helpm Christian
Best regards,
Masija
|
|
|
Powered by
FUDForum. Page generated in 0.04792 seconds