openArchitectureWare.org

oAW has moved to Eclipse.

At this site you will find information about the outdated version openArchitectureWare 4, only.
Please read our letter of intent for further information.

 

 Forum Index > openArchitectureWare > General Discussions New Topic Post Reply
 How to invoke Xpand template into Java code????
 |  Printable Version
IdaEss
 Monday, November 08 2010 @ 11:40 AM CET (Read 1503 times)  


Status: offline

Registered: 11/08/10
Posts: 1

I have created a plug-in (I work with the Yakindu Workbench).
This Plug-in should generate Java code for state machine diagram (statemachine-File).
So i have a custom action (ActionGenerateJavaCode.java) that should invoke the Xpand template.
When I run the action, then I get the following error message:

EvaluationException : No Definition templates::Statechart::Root for statemachine::Statechart could be found!
Internal error: element was null



the custom action looks like this:

import org.eclipse.core.resources.IFile;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.xpand2.XpandExecutionContextImpl;
import org.eclipse.xpand2.XpandFacade;
import org.eclipse.xpand2.output.Outlet;
import org.eclipse.xpand2.output.Output;
import org.eclipse.xpand2.output.OutputImpl;
import org.eclipse.xtend.typesystem.emf.EmfMetaModel;
import statemachine.impl.StatechartImpl;


public class ActionGenerateJavaCode implements IObjectActionDelegate{

private ISelection selection;


@Override
public void run(IAction action) {

try{
IFile file = getFile();
URI fileURI = null;
java.net.URI uri = file.getLocationURI();
fileURI = URI.createURI(uri.toString(), true);
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getPackageRegistry().put(
statemachine.StatemachinePackage.eINSTANCE.getNsURI(),
statemachine.StatemachinePackage.eINSTANCE);
Resource resource = resourceSet.createResource(fileURI);

try {
resource.load(null);
}

catch (Exception e) {
e.printStackTrace();
}

resourceSet.getResources().add(resource);
StatechartImpl statechart = (StatechartImpl) resource.getContents().get(0);

//Xpand
Output out = new OutputImpl();
out.addOutlet(new Outlet("src-gen"));
XpandExecutionContextImpl executionContext = new XpandExecutionContextImpl(out, null);

//Configure the metamodels
EmfMetaModel emfMetaModel = new EmfMetaModel();
emfMetaModel.setMetaModelPackage(statemachine.StatemachinePackage.class.getName());
emfMetaModel.setMetaModelPackage(statechartexpressions.StatechartexpressionsPackage.class.getName());
executionContext.registerMetaModel(emfMetaModel);
XpandFacade xpandFacade = XpandFacade.create(executionContext);
Object [] params =null;
xpandFacade.evaluate("templates::Statechart::Root", statechart, params);
System.out.println("End generate code");

}

catch (Exception e) {
e.printStackTrace();
}
}

@Override
public void selectionChanged(IAction action, ISelection selection) {
this.selection = selection;
}

@Override
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
}

public IFile getFile(){
return (IFile)((IStructuredSelection)selection).getFirstElement();
}

}







     
    Profile Email
    Quote
    Karsten Thoms
     Tuesday, November 09 2010 @ 08:20 AM CET  
    Forum

    Status: offline

    Registered: 07/20/05
    Posts: 1859

    The basic problem will be that the ResourceLoader cannot locate the templates. The default ResourceLoader is classpath based, i.e. templates must be found on the classpath. Are they on the classpath?

    ~Karsten


     
    Profile Email Website
    Quote
    Content generated in: 0.05 seconds
    New Topic Post Reply



     All times are CEST. The time is now 02:18 PM.
    Normal Topic Normal Topic
    Locked Topic Locked Topic
    Sticky Topic Sticky Topic
    New Post New Post
    Sticky Topic W/ New Post Sticky Topic W/ New Post
    Locked Topic W/ New Post Locked Topic W/ New Post
    View Anonymous Posts 
    Anonymous users can post 
    Filtered HTML Allowed 
    Censored Content