Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [TENEO] Problem to generate mapping when using multiple ecore models
[TENEO] Problem to generate mapping when using multiple ecore models [message #517769] Mon, 01 March 2010 23:48 Go to next message
Torsten Link is currently offline Torsten LinkFriend
Messages: 51
Registered: July 2009
Member
Hi,

I have two ecore models. Model A defines base classes where model B extends
classes of Model A. Both models are in on Project (for testing).

Now I tried to generate the mapping for theses ecore Models with Using the
Context Menu and with the programmatic way.

Using ContextMenu to create Mapping
Generating Model A works fine.
Generating Model B gives me an Error when the generator tries to genrate
the super type of a class in Model B which is located in Model A.

Using Code to generate the Mapping
I have registered Both packages from the ecore Model to the datastore.
But it gives me the same Error.

Than I have copied the classes of Model B direct in Model A and the
generation works.

#-----------------
# Base Model A
#-----------------
<?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="structure"
nsURI="http:///de/qatools/structure/structure"
nsPrefix="de.qatools.structure.structure">
<eClassifiers xsi:type="ecore:EClass" name="StructureContainer"
abstract="true"
eSuperTypes="#//StructureElement">
<eStructuralFeatures xsi:type="ecore:EReference"
name="structureChildren" upperBound="-1"
eType="#//StructureElement" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Folder"
eSuperTypes="#//StructureContainer"/>
<eClassifiers xsi:type="ecore:EClass" name="StructureElement"
abstract="true" interface="true">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
</ecore:EPackage>


#-----------------
# Base Model B
#-----------------

<?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="config"
nsURI="http:///de/qatools/config/core/config"
nsPrefix="de.qatoorls.config.core.config">
<eClassifiers xsi:type="ecore:EClass" name="AElement"
eSuperTypes="#//ConfigBase">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="someOtherValue"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ConfigBase" abstract="true"
eSuperTypes="structure.ecore#//StructureElement">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="someValue"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
</ecore:EPackage>


#-----------------
# Error Message
#-----------------
DEBUG [Thread-0] (EClassAnnotator.java:89) - Creating mapping for eclass
AElement
DEBUG [Thread-0] (EClassAnnotator.java:89) - Creating mapping for eclass
ConfigBase
Exception in thread "main" java.lang.IllegalArgumentException: No annotated
model element present for: StructureElement for type EClass has its
epackage been registered with Teneo?
org.eclipse.emf.teneo.annotations.pamodel.impl.PAnnotatedMod elImpl.checkAnnotatedPresent(PAnnotatedModelImpl.java:365)
org.eclipse.emf.teneo.annotations.pamodel.impl.PAnnotatedMod elImpl.getPAnnotated(PAnnotatedModelImpl.java:301)
Re: [TENEO] Problem to generate mapping when using multiple ecore models [message #517785 is a reply to message #517769] Tue, 02 March 2010 05:52 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Torsten,
When generating through the menu, what happens when you select both ecore's and then click the menu option?

The programmatic case should work fine. Can you post the code which you use to initialize the datastore?

gr. Martin

Torsten Link wrote:
> Hi,
>
> I have two ecore models. Model A defines base classes where model B extends
> classes of Model A. Both models are in on Project (for testing).
>
> Now I tried to generate the mapping for theses ecore Models with Using the
> Context Menu and with the programmatic way.
>
> Using ContextMenu to create Mapping
> Generating Model A works fine.
> Generating Model B gives me an Error when the generator tries to genrate
> the super type of a class in Model B which is located in Model A.
>
> Using Code to generate the Mapping
> I have registered Both packages from the ecore Model to the datastore.
> But it gives me the same Error.
>
> Than I have copied the classes of Model B direct in Model A and the
> generation works.
>
> #-----------------
> # Base Model A
> #-----------------
> <?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="structure"
> nsURI="http:///de/qatools/structure/structure"
> nsPrefix="de.qatools.structure.structure">
> <eClassifiers xsi:type="ecore:EClass" name="StructureContainer"
> abstract="true"
> eSuperTypes="#//StructureElement">
> <eStructuralFeatures xsi:type="ecore:EReference"
> name="structureChildren" upperBound="-1"
> eType="#//StructureElement" containment="true"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Folder"
> eSuperTypes="#//StructureContainer"/>
> <eClassifiers xsi:type="ecore:EClass" name="StructureElement"
> abstract="true" interface="true">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> </eClassifiers>
> </ecore:EPackage>
>
>
> #-----------------
> # Base Model B
> #-----------------
>
> <?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="config"
> nsURI="http:///de/qatools/config/core/config"
> nsPrefix="de.qatoorls.config.core.config">
> <eClassifiers xsi:type="ecore:EClass" name="AElement"
> eSuperTypes="#//ConfigBase">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="someOtherValue"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="ConfigBase" abstract="true"
> eSuperTypes="structure.ecore#//StructureElement">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="someValue"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> </eClassifiers>
> </ecore:EPackage>
>
>
> #-----------------
> # Error Message
> #-----------------
> DEBUG [Thread-0] (EClassAnnotator.java:89) - Creating mapping for eclass
> AElement
> DEBUG [Thread-0] (EClassAnnotator.java:89) - Creating mapping for eclass
> ConfigBase
> Exception in thread "main" java.lang.IllegalArgumentException: No annotated
> model element present for: StructureElement for type EClass has its
> epackage been registered with Teneo?
> org.eclipse.emf.teneo.annotations.pamodel.impl.PAnnotatedMod elImpl.checkAnnotatedPresent(PAnnotatedModelImpl.java:365)
> org.eclipse.emf.teneo.annotations.pamodel.impl.PAnnotatedMod elImpl.getPAnnotated(PAnnotatedModelImpl.java:301)
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [TENEO] Problem to generate mapping when using multiple ecore models [message #517834 is a reply to message #517769] Tue, 02 March 2010 10:02 Go to previous messageGo to next message
Torsten Link is currently offline Torsten LinkFriend
Messages: 51
Registered: July 2009
Member
Hi Martin,

when I select both ecore Models and then generate it is working. Smile
So the model itself seems to be OK.


Here is my code:


public class TestTeneo {
* @throws IOException
*/
public static void main(String[] args) throws IOException {
TestTeneo tt = new TestTeneo();
tt.run();
}

private void run() throws IOException{

final Properties props = new Properties();
props.setProperty(Environment.DRIVER, "com.mysql.jdbc.Driver");
props.setProperty(Environment.URL, "jdbc:mysql://localhost:3306/Abilit");
props.setProperty(Environment.USER, "root");
props.setProperty(Environment.PASS, "");
props.setProperty(Environment.DIALECT, "org.hibernate.dialect.MySQLInnoDBDialect");
props.setProperty(Environment.SHOW_SQL, "true");
props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "SINGLE_TABLE");

HbDataStore hbds = (HbDataStore)HbHelper.INSTANCE.createRegisterDataStore("Abilit ");
hbds.setProperties(props);

List<String> packageFiles = new ArrayList<String>();
packageFiles.add(" /Users/torstenlink/Documents/workspace_abilit_java/gumbo/mod el/structure.ecore ");
packageFiles.add(" /Users/torstenlink/Documents/workspace_abilit_java/gumbo/mod el/testModel.ecore ");

EPackage[] packages = readFromEcore(packageFiles);

// at this point the array conmtains two packages as I expect
hbds.setEPackages(packages);

hbds.initialize();
}

// this reeds the ecore File and returns all packages in this file
// Is it necessary to get all Packages of the model file or just
// the top level Packages?
private EPackage[] readFromEcore(List<String> ecoreFiles) {
final ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "*", new EcoreResourceFactoryImpl());
final ArrayList<EPackage> epackages = new ArrayList<EPackage>();
for (String ecoreFile : ecoreFiles) {
try {
final Resource res = resourceSet.getResource(URI.createURI(ecoreFile), true);

TreeIterator<EObject> treeIter = res.getAllContents();
while(treeIter.hasNext()){
EObject obj = treeIter.next();
if (obj instanceof EPackage) {
epackages.add((EPackage) obj);
}
}
} catch (Exception e) {
throw new IllegalStateException(e);
}
}

EPackage[] packArray = new EPackage[epackages.size()];
for(int i=0; i<epackages.size();i++){
packArray[i] = epackages.get(i);
}

return packArray;
}
}



Thanks for the fast Help


Torsten Link

Re: [TENEO] Problem to generate mapping when using multiple ecore models [message #517854 is a reply to message #517834] Tue, 02 March 2010 10:40 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Torsten,
Can you check that the read of epackages correctly creates the relations between the epackages. So is the testModel
refering to the structure epackage read first or to a new instance of the structure epackage?

gr. Martin

Torsten Link wrote:
> Hi Martin,
>
> when I select both ecore Models and then generate it is working. :)
> So the model itself seems to be OK.
>
>
> Here is my code:
>
>
> public class TestTeneo {
> * @throws IOException */
> public static void main(String[] args) throws IOException {
> TestTeneo tt = new TestTeneo();
> tt.run();
> }
>
> private void run() throws IOException{
>
> final Properties props = new Properties();
> props.setProperty(Environment.DRIVER, "com.mysql.jdbc.Driver");
> props.setProperty(Environment.URL,
> "jdbc:mysql://localhost:3306/Abilit");
> props.setProperty(Environment.USER, "root");
> props.setProperty(Environment.PASS, "");
> props.setProperty(Environment.DIALECT,
> "org.hibernate.dialect.MySQLInnoDBDialect");
> props.setProperty(Environment.SHOW_SQL, "true");
> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING,
> "SINGLE_TABLE");
>
> HbDataStore hbds =
> (HbDataStore)HbHelper.INSTANCE.createRegisterDataStore("Abilit ");
> hbds.setProperties(props);
>
> List<String> packageFiles = new ArrayList<String>();
> packageFiles.add("
> /Users/torstenlink/Documents/workspace_abilit_java/gumbo/mod
> el/structure.ecore ");
> packageFiles.add("
> /Users/torstenlink/Documents/workspace_abilit_java/gumbo/mod
> el/testModel.ecore ");
>
> EPackage[] packages = readFromEcore(packageFiles);
>
> // at this point the array conmtains two packages as I expect
> hbds.setEPackages(packages);
>
> hbds.initialize();
> }
>
> // this reeds the ecore File and returns all packages in this file
> // Is it necessary to get all Packages of the model file or just
> // the top level Packages?
> private EPackage[] readFromEcore(List<String> ecoreFiles) {
> final ResourceSet resourceSet = new ResourceSetImpl();
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto
> ryMap().put( "*", new EcoreResourceFactoryImpl());
> final ArrayList<EPackage> epackages = new ArrayList<EPackage>();
> for (String ecoreFile : ecoreFiles) {
> try {
> final Resource res =
> resourceSet.getResource(URI.createURI(ecoreFile), true);
>
> TreeIterator<EObject> treeIter = res.getAllContents();
> while(treeIter.hasNext()){
> EObject obj = treeIter.next();
> if (obj instanceof EPackage) {
> epackages.add((EPackage) obj);
> }
> }
> } catch (Exception e) {
> throw new IllegalStateException(e);
> }
> }
>
> EPackage[] packArray = new EPackage[epackages.size()];
> for(int i=0; i<epackages.size();i++){
> packArray[i] = epackages.get(i);
> }
>
> return packArray;
> }
> }
>
>
>
> Thanks for the fast Help
>
>
> Torsten Link
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [TENEO] Problem to generate mapping when using multiple ecore models [message #517896 is a reply to message #517854] Tue, 02 March 2010 13:22 Go to previous messageGo to next message
Torsten Link is currently offline Torsten LinkFriend
Messages: 51
Registered: July 2009
Member
Hi Martin,

I do not understand what I should do to check that
...epackages correctly creates the relations between the epackages....

I have changed my code in that way, that I use now the same ResourseSet for all the files to load. But it did not change the result.

When I open the ecore File in the editor it shows me the referenced File. So the eore itself has this relation.


with kind regards

Torsten
Re: [TENEO] Problem to generate mapping when using multiple ecore models [message #517904 is a reply to message #517896] Tue, 02 March 2010 13:44 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Torsten,
In the logic you showed you first load the structure.ecore and then the TestModel. As you use the same ResourceSet I
expect this to be fine, but to doublecheck the following situation:
Normally EMF should use the structure.ecore which is already read in the same resourceset. But can you doublecheck that
this is indeed the case, that the types in TestModel refer to the types of the structure.ecore already loaded in the
resource set or that the structure.ecore is read again when TestModel is read (which would explain the result reported
by Teneo).

gr. Martin

Torsten Link wrote:
> Hi Martin,
>
> I do not understand what I should do to check that ...epackages
> correctly creates the relations between the epackages....
>
> I have changed my code in that way, that I use now the same ResourseSet
> for all the files to load. But it did not change the result.
>
> When I open the ecore File in the editor it shows me the referenced
> File. So the eore itself has this relation.
>
>
> with kind regards
>
> Torsten
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [TENEO] Problem to generate mapping when using multiple ecore models [message #517960 is a reply to message #517904] Tue, 02 March 2010 15:39 Go to previous messageGo to next message
Torsten Link is currently offline Torsten LinkFriend
Messages: 51
Registered: July 2009
Member
Hi Martin,

I have now changed the setEPackages to:
hdbs.setEPackages(new EPackage[] {StructurePackage.eINSTANCE, ConfigPackage.eINSTANCE});

And is it working. This leads me to the question if it is sufficent to load just the root package in an ecore or do I need to load also the sub packages.


Thanks a lot


Torsten
Re: [TENEO] Problem to generate mapping when using multiple ecore models [message #517971 is a reply to message #517960] Tue, 02 March 2010 15:58 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Torsten,
If the sub package is contained within the root package then supplying the root package is enough.

I am still wondering why this works and the other approach fails....

gr. Martin

Torsten Link wrote:
> Hi Martin,
>
> I have now changed the setEPackages to:
> hdbs.setEPackages(new EPackage[] {StructurePackage.eINSTANCE,
> ConfigPackage.eINSTANCE});
>
> And is it working. This leads me to the question if it is sufficent to
> load just the root package in an ecore or do I need to load also the sub
> packages.
>
>
> Thanks a lot
>
>
> Torsten


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Previous Topic:Propertysheet showing wrong values
Next Topic:TransactionalEditingDomain Lifecycle
Goto Forum:
  


Current Time: Wed Sep 25 06:10:08 GMT 2024

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

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

Back to the top