Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » MoDisco » Problem with Java model to source code transformation(How to use modisco source code generation)
Problem with Java model to source code transformation [message #1804022] Fri, 15 March 2019 22:36 Go to next message
Ali Sardarian is currently offline Ali SardarianFriend
Messages: 12
Registered: March 2019
Junior Member
I have a problem with Java source code generation of Modisco java model.

I used this guide below in Modisco Documentation :
https://help.eclipse.org/2018-12/topic/org.eclipse.modisco.java.doc/mediawiki/java_generation/user.html?cp=67_0_1_1_2

firstly, I imported the plugin org.eclipse.gmt.modisco.java.generation in the workspace
then I added a class in src folder like this :
import java.io.File;
import java.io.IOException;
import java.util.*;

import org.eclipse.emf.common.util.URI;

import org.eclipse.gmt.modisco.java.generation.files.GenerateJavaExtended;

public class Generation {

    public static void main(String[] args) throws IOException {

    GenerateJavaExtended javaGenerator = new GenerateJavaExtended(URI.createFileURI("./mymodel.xmi"),
            new File("./myOutputFolder"), new ArrayList<Object>());

    javaGenerator.doGenerate(null);
    }

}    

But When I run this code as Java Application, I get this error :
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 67, Size: 1
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at org.eclipse.emf.ecore.impl.EPackageImpl.eObjectForURIFragmentNameSegment(EPackageImpl.java:1970)
at org.eclipse.emf.ecore.impl.EModelElementImpl.eObjectForURIFragmentSegment(EModelElementImpl.java:473)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.getEObject(ResourceImpl.java:811)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.getEObject(ResourceImpl.java:787)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.setValueFromId(XMLHandler.java:2868)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.setAttribValue(XMLHandler.java:2773)
at org.eclipse.emf.ecore.xmi.impl.SAXXMIHandler.handleObjectAttribs(SAXXMIHandler.java:79)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromFactory(XMLHandler.java:2247)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromTypeName(XMLHandler.java:2150)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObject(XMLHandler.java:2085)
at org.eclipse.emf.ecore.xmi.impl.XMIHandler.createObject(XMIHandler.java:151)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleFeature(XMLHandler.java:1868)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1048)
at org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:82)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1026)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:720)
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.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.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.acceleo.model.mtl.resource.EMtlResourceImpl.doLoad(EMtlResourceImpl.java:93)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1563)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1342)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:259)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:406)
at org.eclipse.acceleo.common.utils.ModelUtils.load(ModelUtils.java:391)
at org.eclipse.acceleo.common.utils.ModelUtils.load(ModelUtils.java:356)
at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator.initialize(AbstractAcceleoGenerator.java:485)
at org.eclipse.gmt.modisco.java.generation.files.GenerateJava.<init>(GenerateJava.java:92)
at org.eclipse.gmt.modisco.java.generation.files.GenerateJavaExtended.<init>(GenerateJavaExtended.java:39)
at Generation.main(Generation.java:13)


How can I transform my java model back into the original Java source code?

My used tools:

  • Eclipse Modeling tools 2018-12 (4.10.0)
  • MoDisco SDK (1.2.0)
  • JRE 1.8.0_202

Re: Problem with Java model to source code transformation [message #1804354 is a reply to message #1804022] Sun, 24 March 2019 05:51 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6934
Registered: July 2009
Senior Member
Hi

The trace clearly shows that "./mymodel.xmi" is not a valid XMI file. You don't provide the file so it's hard to say why it crashed.

Looking at the referenced documentation, you should be using a *.javaxmi file.

Regards

Ed Willink
Re: Problem with Java model to source code transformation [message #1804355 is a reply to message #1804354] Sun, 24 March 2019 06:15 Go to previous messageGo to next message
Ali Sardarian is currently offline Ali SardarianFriend
Messages: 12
Registered: March 2019
Junior Member
Thank you Ed Willink for replying

I provided the model that Modisco java discoverer has created for me.
Do you mean that this code only works with the .javamxi file?

and how I can create a .javaxmi model from my sample project?
is there any difference between .xmi java model and .javaxmi ?

Best Regards
Re: Problem with Java model to source code transformation [message #1804386 is a reply to message #1804355] Mon, 25 March 2019 09:36 Go to previous messageGo to next message
Fabien Giquel is currently offline Fabien GiquelFriend
Messages: 147
Registered: July 2009
Senior Member
Hi,

the default extension for java model file is .xmi (more precisely it should end with "_java.xmi"), the documentation page has not been correctly updated about that.
So there something wrong with your .xmi file created by Modisco java discoverer.
Please check simple opening with a model editor : from your "Project Explorer" view, select your .xmi file, do "Open With>" and choose "Sample reflective Ecore model editor" (OR "Modisco Model Browser") => do you get the same error message ?
If confirmed, as Ed mentioned, we will need the file to understand the cause. Could you fill a bugzilla about the problem and attach the file : https://bugs.eclipse.org/bugs/enter_bug.cgi?product=MDT.MoDisco

Regards,
Fabien GIQUEL


----------------------------------------------------
Fabien GIQUEL
R&D Engineer
Mia-Software
rue Nina Simone
44000 NANTES
----------------------------------------------------
Re: Problem with Java model to source code transformation [message #1804398 is a reply to message #1804386] Mon, 25 March 2019 13:46 Go to previous messageGo to next message
Ali Sardarian is currently offline Ali SardarianFriend
Messages: 12
Registered: March 2019
Junior Member
Thanks Fabien for Replying.

my sample java model can be opened with the Modisco Model Browser successfully.

I created a Bugzilla with this link :
https://bugs.eclipse.org/bugs/show_bug.cgi?id=545748
and also I uploaded my model in Attachments.
Re: Problem with Java model to source code transformation [message #1804408 is a reply to message #1804398] Mon, 25 March 2019 16:46 Go to previous messageGo to next message
Fabien Giquel is currently offline Fabien GiquelFriend
Messages: 147
Registered: July 2009
Senior Member
Hi,

the underlying cause of the problem was in EMF release embedded within eclipse 2018-12 : see https://bugs.eclipse.org/bugs/show_bug.cgi?id=543103. It has been fixed in EMF 2.17.0.

So for instance you may download and use the "eclipse 2019-03" which includes the fix. I give it a try on my side.

Note : in 2019-03, Modisco SDK is not directly available in update sites, you will have to indicate the two update sites in "Help>install new software.." before installing "Modisco SDK" feature :

http://download.eclipse.org/facet/updates/release/1.3.0/
http://download.eclipse.org/modeling/mdt/modisco/updates/release/1.2.0/
Re: Problem with Java model to source code transformation [message #1804410 is a reply to message #1804408] Mon, 25 March 2019 17:03 Go to previous messageGo to next message
Fabien Giquel is currently offline Fabien GiquelFriend
Messages: 147
Registered: July 2009
Senior Member
Following my note : "So for instance you may download and use the "eclipse 2019-03" which includes the fix. I give it a try on my side."
--> it does not work with 2019-03 for another reason (.emtl file not supported)
It works with "eclipse 2018-09".

Regards
Fabien
Re: Problem with Java model to source code transformation [message #1804423 is a reply to message #1804410] Mon, 25 March 2019 22:00 Go to previous messageGo to next message
Ali Sardarian is currently offline Ali SardarianFriend
Messages: 12
Registered: March 2019
Junior Member
Thank you very much, Fabien.

It works with eclipse 2018-09 properly, but only through Eclipse Application run configuration.

When I try the same with Java Application, I get this error :
Exception in thread "main" org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'http://www.eclipse.org/MoDisco/Java/0.2.incubation/java' not found. (models/sample_for_modisco_java.xmi, 2, 215)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:319)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:278)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:406)
	at org.eclipse.acceleo.common.utils.ModelUtils.load(ModelUtils.java:391)
	at org.eclipse.acceleo.common.utils.ModelUtils.load(ModelUtils.java:356)
	at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator.initialize(AbstractAcceleoGenerator.java:488)
	at org.eclipse.gmt.modisco.java.generation.files.GenerateJava.<init>(GenerateJava.java:92)
	at org.eclipse.gmt.modisco.java.generation.files.GenerateJavaExtended.<init>(GenerateJavaExtended.java:39)
	at Generate.main(Generate.java:13)
Caused by: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'http://www.eclipse.org/MoDisco/Java/0.2.incubation/java' not found. (models/sample_for_modisco_java.xmi, 2, 215)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(XMLHandler.java:2643)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefix(XMLHandler.java:2476)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType(XMLHandler.java:1353)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XMLHandler.java:1522)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1044)
	at org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:78)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1026)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:720)
	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:1563)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1342)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:259)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
	... 7 more


Is there any way to do this through the Java Application?

Best Regards
Ali Sardarian
Re: Problem with Java model to source code transformation [message #1804471 is a reply to message #1804423] Tue, 26 March 2019 13:21 Go to previous message
Ali Sardarian is currently offline Ali SardarianFriend
Messages: 12
Registered: March 2019
Junior Member
the problem has been solved.

according to this page :
https://wiki.eclipse.org/Acceleo/FAQ#My_generation_fails_with_a_.27package_not_found.27_exception

we just need to add this to our code :
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.gmt.modisco.java.emf.JavaPackage;

EPackage.Registry.INSTANCE.put(JavaPackage.eNS_URI, JavaPackage.eINSTANCE); 
Previous Topic:Generate Java code from a Java model
Next Topic:EMF Refactor & Modisco Java model
Goto Forum:
  


Current Time: Mon Nov 30 02:44:14 GMT 2020

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

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

Back to the top