Java to Ecore using annotation [message #1752623] |
Wed, 25 January 2017 15:53 |
Sam Ra Messages: 9 Registered: January 2017 |
Junior Member |
|
|
I'm trying to transform Java code into ecore model but failed untill now with error:
"Errors were detected while resolving names or processing @model annotation" Details -> "No model elements were found in Java source: check for '@model' on interfaces and classes"
This is how code looks like for instance:
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ClassARequest")
/**
* @model
*/
public class ClassA implements java.io.Serializable {
/**
* @model
*/
private String myAttribute;
public ClassA() {
}
/**
* @model
*/
public String getMyAttribute() {
return apotekId;
}
/**
* @model
*/
public void setMyAttribute(String attribute) {
this.myAttribute = attribute;
}
}
I have lots of classes so I'm looking for automating this someway later.
Note that I'm having big difficulties in finding good EMF documentation/tutorials that helps understand what to do covering more the details of EMF. Even the @model annotation, I did'nt find examples on using it except one so I knew I have to surround it with /** as I did in code. You recommended me looking into code and debug when I have questions but is that really the only way to get information on how to use EMF? Or just hoping someone posted similar question here or at stackoverflow and someone had an answer?
Please help, thanks!
[Updated on: Wed, 25 January 2017 15:57] Report message to a moderator
|
|
|
|
Re: Java to Ecore using annotation [message #1752706 is a reply to message #1752642] |
Thu, 26 January 2017 12:02 |
Sam Ra Messages: 9 Registered: January 2017 |
Junior Member |
|
|
I managed to get the .ecore and .modelgernerator generated using the @model annotation. I have a problem though that all attributes generated seems to get one type in ecore regardless what type its defined with in the class. All attributes are turned to be numbers. I tried to add few attributes as shown in the book to enforce type conversion but failed. below a snippet of code example and what ecore I get. Note that I tried combination of Strings,Estrings,etc and played around with attributes but nothing changed in output. Also the second problem was the default value I get for these attributes which are set to 0, then 1, then 2 and 3. I tried also with other attributes as in the book "default-value" but it didn't help.
/**
* @model
*/
public class Person {
/**
* @model data-type="String"
*/
String id;
/**
* @model
*/
String name;
/**
* @model
*/
int age;
/**
* @model data-type="String" containment="true"
*/
List books;
/**
* @model
*/
public String getId() {
return id;
}
/**
* @model
*/
public String getName() {
return name;
}
/**
* @model
*/
public int getAge() {
return age;
}
/**
* @model
*/
public List getBooks() {
return books;
}
}
And here is the Ecore
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="converter" nsURI="http:///converter.ecore"
nsPrefix="converter">
<eClassifiers xsi:type="ecore:EEnum" name="Person">
<eLiterals name="id"/>
<eLiterals name="name" value="1"/>
<eLiterals name="age" value="2"/>
<eLiterals name="books" value="3"/>
</eClassifiers>
</ecore:EPackage>
[Updated on: Thu, 26 January 2017 12:06] Report message to a moderator
|
|
|
Re: Java to Ecore using annotation [message #1752889 is a reply to message #1752706] |
Mon, 30 January 2017 11:19 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
The Java to Ecore converter expects annotations on things that look like the things EMF would generate. EMF generates interfaces and implementation classes. The only class with variables it generates is for enumerations so that why you see an EEnum as the result.
I'd suggest you look at what's generated for some sample *.ecore models and looking at the generated @model annotations in the interfaces for those samples.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03942 seconds