Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Xpand] EvaluationException, no main found in xpand template
[Xpand] EvaluationException, no main found in xpand template [message #632089] Mon, 11 October 2010 14:08 Go to next message
masija . is currently offline masija .Friend
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 #632092 is a reply to message #632089] Mon, 11 October 2010 14:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14722
Registered: July 2009
Senior Member
Hi,

what is the name of your .xpt file and where is it located?
btw - it seems you are using gmf xpand (fork) - so this might be a question for the gmf newsgroup

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com

[Updated on: Mon, 11 October 2010 14:54]

Report message to a moderator

Re: [Xpand] EvaluationException, no main found in xpand template [message #632109 is a reply to message #632092] Mon, 11 October 2010 15:25 Go to previous messageGo to next message
masija . is currently offline masija .Friend
Messages: 59
Registered: July 2010
Member
hi,
my .xpt file has the name and path
E:/workspace/modeltransTest/templates/modeltrans2html.xpt

Thanks for your fast reply, i think i will post also on the gmf forum..
Best regars,
Masija
Re: [Xpand] EvaluationException, no main found in xpand template [message #632112 is a reply to message #632109] Mon, 11 October 2010 15:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14722
Registered: July 2009
Senior Member
hello

you should put your templates to a source folder.

and then should call templates::modeltrans2html::main

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com

[Updated on: Mon, 11 October 2010 15:32]

Report message to a moderator

Re: [Xpand] EvaluationException, no main found in xpand template [message #632140 is a reply to message #632112] Mon, 11 October 2010 17:37 Go to previous messageGo to next message
masija . is currently offline masija .Friend
Messages: 59
Registered: July 2010
Member
okay, now I moved the .xpt to a package templates in my src folder...
but nothing changed:
I get still the same error :/
Re: [Xpand] EvaluationException, no main found in xpand template [message #632143 is a reply to message #632140] Mon, 11 October 2010 18:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14722
Registered: July 2009
Senior Member
Hi,

Did you change the workflow too? How to you call the workflow? You did Not post the snippet with the workflowrunner. Does it work when you are calling the workflow using the Run mwe Workflow Action?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com

[Updated on: Mon, 11 October 2010 18:09]

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 Go to previous message
masija . is currently offline masija .Friend
Messages: 59
Registered: July 2010
Member
Okay, I solved this problem, so thanks alot for your help Wink
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 Wink
Best regards,
Masija



Previous Topic:[Acceleo] Use of template result in Sequence of String
Next Topic:[Acceleo] In search of a clean solution for namespace/block generation
Goto Forum:
  


Current Time: Tue Oct 08 09:19:43 GMT 2024

Powered by FUDForum. Page generated in 0.04792 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top