|
|
Re: generate code out of metamodel(.ecore file ) using xpandfacade [message #1225069 is a reply to message #1223597] |
Sat, 28 December 2013 16:50 |
Adnan AL-SOSWA Messages: 41 Registered: May 2010 |
Member |
|
|
Thanks christian ,
I tried your suggestion but I am not sure if I understood completely
If you please could you explain for me the differenc in the registeration of metamodel
.ecore file and instance of it .xmi file as I want to generate code from the both
here is my code of regiseration ,
URI uri = URI.createURI("file:///D:/xpand/xpand/my.generator.project/src/metamodel/metamodel.ecore", true);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
ResourceSet rs = new ResourceSetImpl();
// enable extended metadata
final ExtendedMetaData extendedMetaData = new BasicExtendedMetaData(rs.getPackageRegistry());
rs.getLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA,extendedMetaData);
EPackage p = null ;
Resource r = rs.getResource(uri, true);
Object eObject = r.getContents().get(0);
if (eObject instanceof EPackage) {
p = (EPackage)eObject;
rs.getPackageRegistry().put(p.getNsURI(), p);
}
MyOutPutImpl out = new MyOutPutImpl();
MyOutlet outlet = new MyOutlet("my-gen");
out.addOutlet( outlet);
ProtectedRegionResolver prs = new ProtectedRegionResolverImpl();
XpandExecutionContext execCtx = new XpandExecutionContextImpl(out, prs);
XpandFacade.create(execCtx).evaluate("template::Template::main", p);
and here my template for generating code from metamodel.ecore
«DEFINE main FOR ecore::EPackage»
«EXPAND javaClass FOREACH eClassifiers.typeSelect(ecore::EClass)»
«ENDDEFINE»
«DEFINE javaClass FOR ecore::EClass»
public class «name» {
}
«ENDDEFINE»
When I run the project I got this exception
Exception in thread "main" EvaluationException : No Definition template::Template::main for Object could be found!
Internal error : element was null
could you please guide me what I am doing wrong ?
thanks in advance .
[Updated on: Mon, 30 December 2013 20:49] Report message to a moderator
|
|
|
Re: generate code out of metamodel(.ecore file ) using xpandfacade [message #1705591 is a reply to message #1225069] |
Mon, 17 August 2015 16:45 |
ngoc tho huynh Messages: 2 Registered: October 2014 |
Junior Member |
|
|
I have the same problem but it has an error:
Exception in thread "main" EvaluationException : Couldn't find extension 'getComponentList()'!
template::Template.xpt[172,18] on line 9 '.getComponentList()'
In the java class, i use
String templatePath = "template::Template::definition";
XpandExecutionContextImpl execCtx = new
XpandExecutionContextImpl(out, null);
execCtx.registerMetaModel(new EmfRegistryMetaModel());
XpandFacade facade = XpandFacade.create(execCtx);
facade.evaluate(templatePath, definition, params);
in Template.xpt, i declare:
«IMPORT fractal»
«EXTENSION template::Extensions»
«DEFINE definition FOR Definition»
//call template
«EXPAND component FOREACH getComponentList()»
«ENDDEFINE»
and in the extension file (Extensions.ext), i declare:
import fractal;
Definition definition1(Component this) :
eContainer;
List[Component] getComponentList(Definition this) :
subComponents.typeSelect(Component);
Could you help me please ?
[Updated on: Mon, 17 August 2015 21:25] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.04243 seconds