Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Custom Acceleo metamodel
[Acceleo] Custom Acceleo metamodel [message #1734268] Mon, 06 June 2016 16:12 Go to next message
Jakub Kitaj is currently offline Jakub KitajFriend
Messages: 8
Registered: February 2016
Junior Member
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 #1734446 is a reply to message #1734268] Wed, 08 June 2016 12:18 Go to previous messageGo to next message
Viktoria Fink is currently offline Viktoria FinkFriend
Messages: 12
Registered: May 2016
Junior Member
Hi,
don't forget to register your packages inside the generator-java-file.
 * @generated [b]NOT[/b]
     */
    @Override
    public void registerPackages(ResourceSet resourceSet) {
        super.registerPackages(resourceSet);
--> register here your package/model.

I hope that help's you. That's it to my knowledge Wink
Re: [Acceleo] Custom Acceleo metamodel [message #1734541 is a reply to message #1734446] Thu, 09 June 2016 09:40 Go to previous messageGo to next message
Jakub Kitaj is currently offline Jakub KitajFriend
Messages: 8
Registered: February 2016
Junior Member
But I don't create generator-java-file manually. I create Acceleo project by wizard and there I choose my metamodel. So you suggest I should create some file else manually?

Do you know any example?

[Updated on: Thu, 09 June 2016 09:49]

Report message to a moderator

Re: [Acceleo] Custom Acceleo metamodel [message #1734645 is a reply to message #1734541] Fri, 10 June 2016 07:21 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Hi,

As Victoria mentionned, you have a java file generated beside your "mtl" file. Please make sure that your package is properly registered in the "registerPackages" method there.

Laurent Goubet
Obeo
Re: [Acceleo] Custom Acceleo metamodel [message #1734648 is a reply to message #1734645] Fri, 10 June 2016 07:42 Go to previous messageGo to next message
Jakub Kitaj is currently offline Jakub KitajFriend
Messages: 8
Registered: February 2016
Junior Member
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 07:48]

Report message to a moderator

Re: [Acceleo] Custom Acceleo metamodel [message #1734810 is a reply to message #1734648] Mon, 13 June 2016 06:48 Go to previous messageGo to next message
Viktoria Fink is currently offline Viktoria FinkFriend
Messages: 12
Registered: May 2016
Junior Member
Hi,

you have to write down the path to the metamodel. Something like resourceSet.getPackageRegistry().put("/my.custom.model/model/custom.ecore", MyModelPackage.eINSTANCE); MyModelPackage shold be in src of your model.
I hope you already got it as a dependency in your MANIFEST.MF.
Re: [Acceleo] Custom Acceleo metamodel [message #1734869 is a reply to message #1734648] Mon, 13 June 2016 06:48 Go to previous messageGo to next message
Viktoria Fink is currently offline Viktoria FinkFriend
Messages: 12
Registered: May 2016
Junior Member
Hi,

you have to write down the path to the metamodel. Something like resourceSet.getPackageRegistry().put("/my.custom.model/model/custom.ecore", MyModelPackage.eINSTANCE); MyModelPackage shold be in src of your model.
I hope you already got it as a dependency in your MANIFEST.MF.
Re: [Acceleo] Custom Acceleo metamodel [message #1736079 is a reply to message #1734810] Sat, 25 June 2016 00:39 Go to previous messageGo to next message
Jakub Kitaj is currently offline Jakub KitajFriend
Messages: 8
Registered: February 2016
Junior Member
I add metamodel and Package to my MANIFEST.MF.
I try with:
resourceSet.getPackageRegistry().put("/ROS-metamodel/model/ros.ecore", Package.class);


and with:
resourceSet.getPackageRegistry().put("http://org/model/ros", Package.class);


but I get same error
Re: [Acceleo] Custom Acceleo metamodel [message #1736094 is a reply to message #1736079] Sat, 25 June 2016 15:07 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Look at an official Acceleo example or the comments in the generated
code and you will understand why your call to getPackageRegistry().put
is all wrong.

Regards

Ed Willink


On 25/06/2016 01:39, Jakub Kitaj wrote:
> I add metamodel and Package to my MANIFEST.MF.
> I try with:
> resourceSet.getPackageRegistry().put("/ROS-metamodel/model/ros.ecore",
> Package.class);
>
> and with:
> resourceSet.getPackageRegistry().put("http://org/model/ros",
> Package.class);
>
> but I get same error
Re: [Acceleo] Custom Acceleo metamodel [message #1736163 is a reply to message #1736094] Mon, 27 June 2016 08:21 Go to previous message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
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
Previous Topic:Using multiple input files (though one model) to generate
Next Topic:[Acceleo] PackageNotFoundException
Goto Forum:
  


Current Time: Tue Mar 19 05:09:12 GMT 2024

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

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

Back to the top