[Acceleo] Custom Acceleo metamodel [message #1734268] |
Mon, 06 June 2016 12:12  |
Eclipse User |
|
|
|
Hello, I'm new in Acceleo.
I try to make generator from my custom metamodel. I created it by Obeo Designer - it is ecore metamodel.
So I create new Acceleo Project, choose my metamodel URI (http://org/model/ros) from "Runtime version" and try to run it.
But project can't run and i get exception:
Caused by: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'http://org/model/ros' not found. (file:/C:/Users/Jakub%20Kitaj/Downloads/ObeoDesigner-Community-8.1-win32.win32.x86/ObeoDesigner-Community/workspace/TestAcceleo/model/example.ros, 2, 120)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(XMLHandler.java:2625)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefix(XMLHandler.java:2458)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType(XMLHandler.java:1335)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XMLHandler.java:1504)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1026)
at org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:78)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1008)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:719)
at org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHandler.java:190)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$ContentDriver.scanRootElementHook(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(Unknown Source)
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:175)
at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:261)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1518)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1297)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:259)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
... 6 more
I think i should set my custom metamodel but how can I do this?
|
|
|
|
|
|
Re: [Acceleo] Custom Acceleo metamodel [message #1734648 is a reply to message #1734645] |
Fri, 10 June 2016 03:42   |
Eclipse User |
|
|
|
The generated "registerPackages" method is:
@Override
public void registerPackages(ResourceSet resourceSet) {
super.registerPackages(resourceSet);
/*
* If you want to change the content of this method, do NOT forget to change the "@generated"
* tag in the Javadoc of this method to "@generated NOT". Without this new tag, any compilation
* of the Acceleo module with the main template that has caused the creation of this class will
* revert your modifications.
*/
/*
* If you need additional package registrations, you can register them here. The following line
* (in comment) is an example of the package registration for UML.
*
* You can use the method "isInWorkspace(Class c)" to check if the package that you are about to
* register is in the workspace.
*
* To register a package properly, please follow the following conventions:
*
* If the package is located in another plug-in, already installed in Eclipse. The following content should
* have been generated at the beginning of this method. Do not register the package using this mechanism if
* the metamodel is located in the workspace.
*
* if (!isInWorkspace(UMLPackage.class)) {
* // The normal package registration if your metamodel is in a plugin.
* resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
* }
*
* If the package is located in another project in your workspace, the plugin containing the package has not
* been register by EMF and Acceleo should register it automatically. If you want to use the generator in
* stand alone, the regular registration (seen a couple lines before) is needed.
*
* To learn more about Package Registration, have a look at the Acceleo documentation (Help -> Help Contents).
*/
}
I think, I should write something like:
resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
but from can I get package class for my metamodel (like UMLPackage above) ?
Can you show your "registerPackages" method?
[Updated on: Fri, 10 June 2016 03:48] by Moderator
|
|
|
|
|
|
|
Re: [Acceleo] Custom Acceleo metamodel [message #1736163 is a reply to message #1736094] |
Mon, 27 June 2016 04:21  |
Eclipse User |
|
|
|
Hi Jakub,
Please look at Viktoria's example, as well as those that are pre-generated for you in the java class beside your main template : what you need to "put" in the package registry is the instance of your metamodel's package.
You should have an ecore model you've created with the URI "http://org/model/ros" , and you have generated the code corresponding to that model. In that code, you have a class named "RosPackage" (or "XyzPackage", xyz being the name of your model's EPackage). what you need to pu in the "registerPackages" method is :
resourceSet.getPackageRegistry().put("http://org/model/ros", RosPackage.eINSTANCE);
You will need to have a dependency between the project that contains your acceleo templates and the project that contains your generated model code for this to work.
Laurent Goubet
Obeo
|
|
|
Powered by
FUDForum. Page generated in 0.11287 seconds