Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Problem with "external" GenModel when programmatically triggering the generator
Problem with "external" GenModel when programmatically triggering the generator [message #419738] Wed, 04 June 2008 16:04 Go to next message
JG is currently offline JGFriend
Messages: 51
Registered: July 2009
Member
Hi everyone,

in my project, I am dynamically building Ecore models. Building the
models works fine so far, but I cannot successfully create code
programmatically. One important note in advance: I am trying to use the
Generator in standalone mode, which probably makes things more
difficult, but I found an early hint in this group by Ed Merks pointing
me to the Apache Tuscany project, which do the same thing, apparently
successfully. I looked at their code to help me figure out the basics.

So I build a GenModel for my set of dynamic EPackages via

GenModel genModel = GenModelFactory.eINSTANCE.createGenModel();
genModel.initialize(myDynamicEPackages);

I also do

genModel.reconcile();
genModel.setCanGenerate(true);
genModel.setValidateModel(true);


which I found in GenModelEditor.validate().


Using the GenModel.diagnose() method, I found that the problem seemed to
be that my dynamic models are depending on some parts of my static
models... this is probably the part where the "Reload..." wizard allows
one to browse for these external GenModels.

I figured that I would have to somehow obtain GenPackages for each
EPackage in my static model and add them to the basic GenModel I created
"around" my set of dynamic EPackages via the usedGenPackages feature.
(Well, probably I would only need those that are actually used by my
dynamic models, but I just added them all for now...)

After some browsing of this newsgroup, I found pointers to samples
indicating how to obtain references to my static packages to hand to the
dynamic GenModel.
I iterate over all values() in the EPackage.Registry.INSTANCE, create a
GenModel around all packages I find that way (using the same code as for
my dynamic packages), and add them to the dynamic GenModel like this:

genModel.getUsedGenPackages().addAll(externalGenModel.getGen Packages());

Now the complaints about missing GenModels have gone away, but instead I
got some really weired error messages from genModel.diagnose() which I
can make no sense of:

Diagnostic 0: Diagnostic WARNING source=org.eclipse.emf.ecore.model
code=4 The generic type associated with the 'EJavaClass' classifier
should have 1 type argument(s) to match the number of type parameter(s)
of the classifier
data=[org.eclipse.emf.ecore.impl.EGenericTypeImpl@a22671 (expression:
EJavaClass)]
Diagnostic 1: Diagnostic WARNING source=org.eclipse.emf.ecore.model
code=4 The generic type associated with the 'EJavaClass' classifier
should have 1 type argument(s) to match the number of type parameter(s)
of the classifier
data=[org.eclipse.emf.ecore.impl.EGenericTypeImpl@189f854 (expression:
EJavaClass)]
Diagnostic 2: Diagnostic WARNING source=org.eclipse.emf.ecore.model
code=4 The generic type associated with the 'EJavaClass' classifier
should have 1 type argument(s) to match the number of type parameter(s)
of the classifier
data=[org.eclipse.emf.ecore.impl.EGenericTypeImpl@10e7c9e (expression:
EJavaClass)]
Diagnostic 3: Diagnostic ERROR source=org.eclipse.emf.ecore.model code=2
The generic type associated with the 'PCollection' classifier must not
have 1 argument(s) when the classifier has 0 type parameter(s)
data=[org.eclipse.emf.ecore.impl.EGenericTypeImpl@178655 (expression:
PCollection<EString>)]
Diagnostic 4: Diagnostic ERROR source=org.eclipse.emf.ecore.model code=2
The generic type associated with the 'PCollection' classifier must not
have 1 argument(s) when the classifier has 0 type parameter(s)
data=[org.eclipse.emf.ecore.impl.EGenericTypeImpl@746ad0 (expression:
PCollection<EString>)]
Diagnostic 5: Diagnostic WARNING source=org.eclipse.emf.ecore.model
code=4 The generic type associated with the 'EJavaClass' classifier
should have 1 type argument(s) to match the number of type parameter(s)
of the classifier
data=[org.eclipse.emf.ecore.impl.EGenericTypeImpl@1108727 (expression:
EJavaClass)]


About the warnings: in my example model I actually created 4 EDataTypes,
whose instanceClass is either java.lang.String, java.lang.Integer, or
java.util.Date, neither of which has a Type parameter (but they do all
implement Comparable and fix the type parameter there...).

About the errors: PCollection is an "external" EDataType I defined in
one of my static models. Its instanceClass is java.util.Collection, and
I set a type parameter there. In Rose this datatype's definition looks
like this:

<<datatype>> PCollection
------------------------
<<parameter>> T
<<javaclass>> java.util.Collection

So what could be wrong here?
I do not use PCollection in my dynamic models, and I defined another
external type with a type parameter in the very same way, without any
complaints (actually for java.util.List).

Any suggestions welcome.

Regards

JG
Re: Problem with "external" GenModel when programmatically triggering the generator [message #419743 is a reply to message #419738] Wed, 04 June 2008 16:54 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
JG,

Comments below.

JG wrote:
> Hi everyone,
>
> in my project, I am dynamically building Ecore models. Building the
> models works fine so far, but I cannot successfully create code
> programmatically. One important note in advance: I am trying to use
> the Generator in standalone mode, which probably makes things more
> difficult, but I found an early hint in this group by Ed Merks
> pointing me to the Apache Tuscany project, which do the same thing,
> apparently successfully. I looked at their code to help me figure out
> the basics.
>
> So I build a GenModel for my set of dynamic EPackages via
>
> GenModel genModel = GenModelFactory.eINSTANCE.createGenModel();
> genModel.initialize(myDynamicEPackages);
>
> I also do
>
> genModel.reconcile();
> genModel.setCanGenerate(true);
> genModel.setValidateModel(true);
>
>
> which I found in GenModelEditor.validate().
>
>
> Using the GenModel.diagnose() method, I found that the problem seemed
> to be that my dynamic models are depending on some parts of my static
> models... this is probably the part where the "Reload..." wizard
> allows one to browse for these external GenModels.
>
> I figured that I would have to somehow obtain GenPackages for each
> EPackage in my static model and add them to the basic GenModel I
> created "around" my set of dynamic EPackages via the usedGenPackages
> feature. (Well, probably I would only need those that are actually
> used by my dynamic models, but I just added them all for now...)
>
> After some browsing of this newsgroup, I found pointers to samples
> indicating how to obtain references to my static packages to hand to
> the dynamic GenModel.
> I iterate over all values() in the EPackage.Registry.INSTANCE, create
> a GenModel around all packages I find that way (using the same code as
> for my dynamic packages), and add them to the dynamic GenModel like this:
>
> genModel.getUsedGenPackages().addAll(externalGenModel.getGen Packages());
That's quite brute force.
>
> Now the complaints about missing GenModels have gone away, but instead
> I got some really weired error messages from genModel.diagnose() which
> I can make no sense of:
>
> Diagnostic 0: Diagnostic WARNING source=org.eclipse.emf.ecore.model
> code=4 The generic type associated with the 'EJavaClass' classifier
> should have 1 type argument(s) to match the number of type
> parameter(s) of the classifier
> data=[org.eclipse.emf.ecore.impl.EGenericTypeImpl@a22671 (expression:
> EJavaClass)]
> Diagnostic 1: Diagnostic WARNING source=org.eclipse.emf.ecore.model
> code=4 The generic type associated with the 'EJavaClass' classifier
> should have 1 type argument(s) to match the number of type
> parameter(s) of the classifier
> data=[org.eclipse.emf.ecore.impl.EGenericTypeImpl@189f854 (expression:
> EJavaClass)]
> Diagnostic 2: Diagnostic WARNING source=org.eclipse.emf.ecore.model
> code=4 The generic type associated with the 'EJavaClass' classifier
> should have 1 type argument(s) to match the number of type
> parameter(s) of the classifier
> data=[org.eclipse.emf.ecore.impl.EGenericTypeImpl@10e7c9e (expression:
> EJavaClass)]
> Diagnostic 3: Diagnostic ERROR source=org.eclipse.emf.ecore.model
> code=2 The generic type associated with the 'PCollection' classifier
> must not have 1 argument(s) when the classifier has 0 type
> parameter(s) data=[org.eclipse.emf.ecore.impl.EGenericTypeImpl@178655
> (expression: PCollection<EString>)]
> Diagnostic 4: Diagnostic ERROR source=org.eclipse.emf.ecore.model
> code=2 The generic type associated with the 'PCollection' classifier
> must not have 1 argument(s) when the classifier has 0 type
> parameter(s) data=[org.eclipse.emf.ecore.impl.EGenericTypeImpl@746ad0
> (expression: PCollection<EString>)]
> Diagnostic 5: Diagnostic WARNING source=org.eclipse.emf.ecore.model
> code=4 The generic type associated with the 'EJavaClass' classifier
> should have 1 type argument(s) to match the number of type
> parameter(s) of the classifier
> data=[org.eclipse.emf.ecore.impl.EGenericTypeImpl@1108727 (expression:
> EJavaClass)]
>
>
> About the warnings: in my example model I actually created 4
> EDataTypes, whose instanceClass is either java.lang.String,
> java.lang.Integer, or java.util.Date, neither of which has a Type
> parameter (but they do all implement Comparable and fix the type
> parameter there...).
The warnings all sound like cases of just EJavaClass without any type
arguments; the same ones you'd get in Java in you uses java.lang.Class
instead of java.lang.Class<?> or java.lang.Class<Integer>...
>
> About the errors: PCollection is an "external" EDataType I defined in
> one of my static models. Its instanceClass is java.util.Collection,
> and I set a type parameter there. In Rose this datatype's definition
> looks like this:
>
> <<datatype>> PCollection
> ------------------------
> <<parameter>> T
> <<javaclass>> java.util.Collection
This looks pretty much like how we define EEList... But it sounds like
the Ecore result doesn't end up with an ETypeParameter for T.
>
> So what could be wrong here?
> I do not use PCollection in my dynamic models, and I defined another
> external type with a type parameter in the very same way, without any
> complaints (actually for java.util.List).
I guess the best I can suggest is look closely at the Ecore result for
the PCollection... I assume you also generated the project for the
package that contains PCollection to use Java 5.0 syntax (otherwise it
will erase that information as it generates).
>
> Any suggestions welcome.
>
> Regards
>
> JG


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Problem with "external" GenModel when programmatically triggering the generator [message #419751 is a reply to message #419743] Thu, 05 June 2008 15:15 Go to previous messageGo to next message
JG is currently offline JGFriend
Messages: 51
Registered: July 2009
Member
Ed,

thanks again for your help.

>> I iterate over all values() in the EPackage.Registry.INSTANCE, create
>> a GenModel around all packages I find that way (using the same code as
>> for my dynamic packages), and add them to the dynamic GenModel like this:
>>
>> genModel.getUsedGenPackages().addAll(externalGenModel.getGen Packages());
> That's quite brute force.

Well, I guessed so... but that's what Tuscany (apparently...) does, and
I had decided to figure out a way to only add the needed packages later.
Any pointers in the right direction would be welcome.


>>
>> About the warnings: in my example model I actually created 4
>> EDataTypes, whose instanceClass is either java.lang.String,
>> java.lang.Integer, or java.util.Date, neither of which has a Type
>> parameter (but they do all implement Comparable and fix the type
>> parameter there...).
> The warnings all sound like cases of just EJavaClass without any type
> arguments; the same ones you'd get in Java in you uses java.lang.Class
> instead of java.lang.Class<?> or java.lang.Class<Integer>...

I figured that out in the meantime, I indeed did not add a type
parameter. So in my code I now do:

ETypeParameter etp = EcoreFactory.eINSTANCE.createETypeParameter();
etp.setName("J");
newEDataType.getETypeParameters().add(etp);


Resulting in

<eClassifiers xsi:type="ecore:EDataType" name="integer"
instanceClassName="java.lang.Integer" serializable="true">
<eTypeParameters name="J"/>
</eClassifiers>

Which looks exactly like Ecore's EEList:

<eClassifiers xsi:type="ecore:EDataType" name="EEList"
instanceClassName="org.eclipse.emf.common.util.EList"
serializable="false">
<eTypeParameters name="E"/>
</eClassifiers>

So I guessed that this should be sufficient, however, the warnings remain.

>> About the errors: PCollection is an "external" EDataType I defined in
>> one of my static models. Its instanceClass is java.util.Collection,
>> and I set a type parameter there. In Rose this datatype's definition
>> looks like this:
>>
>> <<datatype>> PCollection
>> ------------------------
>> <<parameter>> T
>> <<javaclass>> java.util.Collection
> This looks pretty much like how we define EEList...

Well, I sure hope it does, since I used Ecore's external type
definitions as a template when I defined these data types some time ago.

> But it sounds like
> the Ecore result doesn't end up with an ETypeParameter for T.

I copied the EDataType's definition from my "static" .ecore model file:

<eClassifiers xsi:type="ecore:EDataType" name="PCollection"
instanceClassName="java.util.Collection">
<eTypeParameters name="T"/>
</eClassifiers>

So there _is_ a type parameter in my .ecore file, well, at least this
looks exactly like Ecore's EEList.

In some moderate state of desparation I looked at all the various meta
classes in the debugger. And was quite surprised to find that while
EcorePackageImpl's eeListDataType does indeed have a value in its
eTypeParameter EList, my JavaTypes package does NOT have one.

How can that be? How can the Ecore model/file be different from the
actual code? I have yet to find the place in the code where all the
properties of the meta classes are actually set.


>> So what could be wrong here?
>> I do not use PCollection in my dynamic models, and I defined another
>> external type with a type parameter in the very same way, without any
>> complaints (actually for java.util.List).
> I guess the best I can suggest is look closely at the Ecore result for
> the PCollection... I assume you also generated the project for the
> package that contains PCollection to use Java 5.0 syntax (otherwise it
> will erase that information as it generates).

Yes, its all Java 5. I originally started with the model (built in Rose)
in EMF 2.1 times, but I since have "migrated" to 2.3. Well, I actually
replaced the imported org.eclipse.emf.Ecore.cat with the new one and
started using generics in my external data type definitions. Are there
any other things I should have done?

A different, but related problem:

Just to see what would happen, I also tried to generate my model from
the Ecore file via Eclipse and the GenModel editor. The result was quite
different: I got a load of error messages stating that the ecore model
contains an unresolved proxy, to an EClass of my static model which I
reference (actually: subclass) from the dynamic model. So apparently,
when validating the ecore model, the generator can not find my static
model. I expected that the importer would ask me for the referenced
packages, just as the Rose importer does. So how do I specify the
location of my external static model in the GenModel I create for my
dynamic model? There are a numbe rof properties which come into question
(addImport, setForeignModel, ...) but none is documented anywhere. Any
pointers to documentation or use welcome.


Regards

JG
Re: Problem with "external" GenModel when programmatically triggering the generator [message #419755 is a reply to message #419751] Thu, 05 June 2008 17:19 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------040203000707080802010409
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

JG,

Comments below.


JG wrote:
> Ed,
>
> thanks again for your help.
>
>>> I iterate over all values() in the EPackage.Registry.INSTANCE,
>>> create a GenModel around all packages I find that way (using the
>>> same code as for my dynamic packages), and add them to the dynamic
>>> GenModel like this:
>>>
>>> genModel.getUsedGenPackages().addAll(externalGenModel.getGen Packages());
>>>
>> That's quite brute force.
>
> Well, I guessed so... but that's what Tuscany (apparently...) does,
> and I had decided to figure out a way to only add the needed packages
> later.
> Any pointers in the right direction would be welcome.
GenModel.getMissingPackages should help.
>
>
>>>
>>> About the warnings: in my example model I actually created 4
>>> EDataTypes, whose instanceClass is either java.lang.String,
>>> java.lang.Integer, or java.util.Date, neither of which has a Type
>>> parameter (but they do all implement Comparable and fix the type
>>> parameter there...).
>> The warnings all sound like cases of just EJavaClass without any type
>> arguments; the same ones you'd get in Java in you uses
>> java.lang.Class instead of java.lang.Class<?> or
>> java.lang.Class<Integer>...
>
> I figured that out in the meantime, I indeed did not add a type
> parameter. So in my code I now do:
>
> ETypeParameter etp = EcoreFactory.eINSTANCE.createETypeParameter();
> etp.setName("J");
> newEDataType.getETypeParameters().add(etp);
>
>
> Resulting in
>
> <eClassifiers xsi:type="ecore:EDataType" name="integer"
> instanceClassName="java.lang.Integer" serializable="true">
> <eTypeParameters name="J"/>
> </eClassifiers>
This can't be good. Integer isn't a generic type.
>
> Which looks exactly like Ecore's EEList:
>
> <eClassifiers xsi:type="ecore:EDataType" name="EEList"
> instanceClassName="org.eclipse.emf.common.util.EList"
> serializable="false">
> <eTypeParameters name="E"/>
> </eClassifiers>
>
> So I guessed that this should be sufficient, however, the warnings
> remain.
>
>>> About the errors: PCollection is an "external" EDataType I defined
>>> in one of my static models. Its instanceClass is
>>> java.util.Collection, and I set a type parameter there. In Rose this
>>> datatype's definition looks like this:
>>>
>>> <<datatype>> PCollection
>>> ------------------------
>>> <<parameter>> T
>>> <<javaclass>> java.util.Collection
>> This looks pretty much like how we define EEList...
>
> Well, I sure hope it does, since I used Ecore's external type
> definitions as a template when I defined these data types some time ago.
>
>> But it sounds like the Ecore result doesn't end up with an
>> ETypeParameter for T.
>
> I copied the EDataType's definition from my "static" .ecore model file:
>
> <eClassifiers xsi:type="ecore:EDataType" name="PCollection"
> instanceClassName="java.util.Collection">
> <eTypeParameters name="T"/>
> </eClassifiers>
>
> So there _is_ a type parameter in my .ecore file, well, at least this
> looks exactly like Ecore's EEList.
>
> In some moderate state of desparation I looked at all the various meta
> classes in the debugger. And was quite surprised to find that while
> EcorePackageImpl's eeListDataType does indeed have a value in its
> eTypeParameter EList, my JavaTypes package does NOT have one.
>
> How can that be? How can the Ecore model/file be different from the
> actual code? I have yet to find the place in the code where all the
> properties of the meta classes are actually set.
Do you have code like this in the generated package. Is your GenModel's
compliance level set to 5.0?

public void initializePackageContents()
{
if (isInitialized) return;
isInitialized = true;

// Initialize package
setName(eNAME);
setNsPrefix(eNS_PREFIX);
setNsURI(eNS_URI);

// Create type parameters
addETypeParameter(eeListEDataType, "E");


>
>
>>> So what could be wrong here?
>>> I do not use PCollection in my dynamic models, and I defined another
>>> external type with a type parameter in the very same way, without
>>> any complaints (actually for java.util.List).
>> I guess the best I can suggest is look closely at the Ecore result
>> for the PCollection... I assume you also generated the project for
>> the package that contains PCollection to use Java 5.0 syntax
>> (otherwise it will erase that information as it generates).
>
> Yes, its all Java 5. I originally started with the model (built in Rose)
> in EMF 2.1 times, but I since have "migrated" to 2.3. Well, I actually
> replaced the imported org.eclipse.emf.Ecore.cat with the new one and
> started using generics in my external data type definitions. Are there
> any other things I should have done?
Set the GenModel's compliance level to 5.0 maybe?
> A different, but related problem:
>
> Just to see what would happen, I also tried to generate my model from
> the Ecore file via Eclipse and the GenModel editor. The result was
> quite different: I got a load of error messages stating that the ecore
> model contains an unresolved proxy, to an EClass of my static model
> which I reference (actually: subclass) from the dynamic model. So
> apparently, when validating the ecore model, the generator can not
> find my static model.
What did the proxy URIs look like?
> I expected that the importer would ask me for the referenced packages,
> just as the Rose importer does. So how do I specify the location of my
> external static model in the GenModel I create for my dynamic model?
> There are a numbe rof properties which come into question (addImport,
> setForeignModel, ...) but none is documented anywhere. Any pointers to
> documentation or use welcome.
Is the *.genmodel for your new model in the workspace somewhere? I
needs to be...
>
>
> Regards
>
> JG
>


--------------040203000707080802010409
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
JG,<br>
<br>
Comments below.<br>
<br>
<br>
JG wrote:
<blockquote cite="mid:g28vv9$48v$1@build.eclipse.org" type="cite">Ed,
<br>
<br>
thanks again for your help.
<br>
<br>
<blockquote type="cite">
<blockquote type="cite">I iterate over all values() in the
EPackage.Registry.INSTANCE, create a GenModel around all packages I
find that way (using the same code as for my dynamic packages), and add
them to the dynamic GenModel like this:
<br>
<br>
genModel.getUsedGenPackages().addAll(externalGenModel.getGen Packages());
<br>
</blockquote>
That's quite brute force.
<br>
</blockquote>
<br>
Well, I guessed so... but that's what Tuscany (apparently...) does, and
I had decided to figure out a way to only add the needed packages
later.
<br>
Any pointers in the right direction would be welcome.
<br>
</blockquote>
GenModel.getMissingPackages should help.<br>
<blockquote cite="mid:g28vv9$48v$1@build.eclipse.org" type="cite"><br>
<br>
<blockquote type="cite">
<blockquote type="cite"><br>
About the warnings: in my example model I actually created 4
EDataTypes, whose instanceClass is either java.lang.String,
java.lang.Integer, or java.util.Date, neither of which has a Type
parameter (but they do all implement Comparable and fix the type
parameter there...).
<br>
</blockquote>
The warnings all sound like cases of just EJavaClass without any type
arguments; the same ones you'd get in Java in you uses java.lang.Class
instead of java.lang.Class&lt;?&gt; or
java.lang.Class&lt;Integer&gt;...
<br>
</blockquote>
<br>
I figured that out in the meantime, I indeed did not add a type
parameter. So in my code I now do:
<br>
<br>
ETypeParameter etp = EcoreFactory.eINSTANCE.createETypeParameter();
<br>
etp.setName("J");
<br>
newEDataType.getETypeParameters().add(etp);
<br>
<br>
<br>
Resulting in
<br>
<br>
&lt;eClassifiers xsi:type="ecore:EDataType" name="integer"
<br>
&nbsp;&nbsp;&nbsp;&nbsp;instanceClassName="java.lang.Integer " serializable="true"&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&lt;eTypeParamet ers name="J"/&gt;
<br>
&lt;/eClassifiers&gt;
<br>
</blockquote>
This can't be good.&nbsp; Integer isn't a generic type.<br>
<blockquote cite="mid:g28vv9$48v$1@build.eclipse.org" type="cite"><br>
Which looks exactly like Ecore's EEList:
<br>
<br>
&lt;eClassifiers xsi:type="ecore:EDataType" name="EEList"
<br>
&nbsp;&nbsp;&nbsp;&nbsp;instanceClassName="org.eclipse.emf.common.util.EList "
<br>
&nbsp;&nbsp;&nbsp;&nbsp;serializable="false "&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&lt;eTypeParamet ers name="E"/&gt;
<br>
&lt;/eClassifiers&gt;
<br>
<br>
So I guessed that this should be sufficient, however, the warnings
remain.
<br>
<br>
<blockquote type="cite">
<blockquote type="cite">About the errors: PCollection is an
"external" EDataType I defined in one of my static models. Its
instanceClass is java.util.Collection, and I set a type parameter
there. In Rose this datatype's definition looks like this:
<br>
<br>
&lt;&lt;datatype&gt;&gt; PCollection
<br>
------------------------
<br>
&lt;&lt;parameter&gt;&gt; T
<br>
&lt;&lt;javaclass&gt;&gt; java.util.Collection
<br>
</blockquote>
This looks pretty much like how we define EEList... </blockquote>
<br>
Well, I sure hope it does, since I used Ecore's external type
definitions as a template when I defined these data types some time
ago.
<br>
<br>
<blockquote type="cite">But it sounds like the Ecore result doesn't
end up with an ETypeParameter for T.
<br>
</blockquote>
<br>
I copied the EDataType's definition from my "static" .ecore model file:
<br>
<br>
&lt;eClassifiers xsi:type="ecore:EDataType" name="PCollection"
<br>
&nbsp;&nbsp;&nbsp;&nbsp;instanceClassName="java.util.Collection "&gt;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;eTypeParameters name="T"/&gt;
<br>
&lt;/eClassifiers&gt;
<br>
<br>
So there _is_ a type parameter in my .ecore file, well, at least this
looks exactly like Ecore's EEList.
<br>
<br>
In some moderate state of desparation I looked at all the various meta
classes in the debugger. And was quite surprised to find that while
EcorePackageImpl's eeListDataType does indeed have a value in its
eTypeParameter EList, my JavaTypes package does NOT have one.
<br>
<br>
How can that be? How can the Ecore model/file be different from the
actual code? I have yet to find the place in the code where all the
properties of the meta classes are actually set.
<br>
</blockquote>
Do you have code like this in the generated package.&nbsp; Is your
GenModel's compliance level set to 5.0?<br>
<blockquote><small>&nbsp; public void initializePackageContents()</small><br>
<small>&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp; if (isInitialized) return;</small><br>
<small>&nbsp;&nbsp;&nbsp; isInitialized = true;</small><br>
<br>
<small>&nbsp;&nbsp;&nbsp; // Initialize package</small><br>
<small>&nbsp;&nbsp;&nbsp; setName(eNAME);</small><br>
<small>&nbsp;&nbsp;&nbsp; setNsPrefix(eNS_PREFIX);</small><br>
<small>&nbsp;&nbsp;&nbsp; setNsURI(eNS_URI);</small><br>
<br>
<small>&nbsp;&nbsp;&nbsp; // Create type parameters</small><br>
<small>&nbsp;&nbsp;&nbsp; addETypeParameter(eeListEDataType, "E");</small><br>
</blockquote>
<br>
<blockquote cite="mid:g28vv9$48v$1@build.eclipse.org" type="cite"><br>
<br>
<blockquote type="cite">
<blockquote type="cite">So what could be wrong here?
<br>
I do not use PCollection in my dynamic models, and I defined another
external type with a type parameter in the very same way, without any
complaints (actually for java.util.List).
<br>
</blockquote>
I guess the best I can suggest is look closely at the Ecore result for
the PCollection...&nbsp; I assume you also generated the project for the
package that contains PCollection to use Java 5.0 syntax (otherwise it
will erase that information as it generates).
<br>
</blockquote>
<br>
Yes, its all Java 5. I originally started with the model (built in
Rose)
<br>
in EMF 2.1 times, but I since have "migrated" to 2.3. Well, I actually
<br>
replaced the imported org.eclipse.emf.Ecore.cat with the new one and
<br>
started using generics in my external data type definitions. Are there
any other things I should have done?
<br>
</blockquote>
Set the GenModel's compliance level to 5.0 maybe?<br>
<blockquote cite="mid:g28vv9$48v$1@build.eclipse.org" type="cite">A
different, but related problem:
<br>
<br>
Just to see what would happen, I also tried to generate my model from
the Ecore file via Eclipse and the GenModel editor. The result was
quite different: I got a load of error messages stating that the ecore
model contains an unresolved proxy, to an EClass of my static model
which I reference (actually: subclass) from the dynamic model. So
apparently, when validating the ecore model, the generator can not find
my static model. </blockquote>
What did the proxy URIs look like?<br>
<blockquote cite="mid:g28vv9$48v$1@build.eclipse.org" type="cite">I
expected that the importer would ask me for the referenced packages,
just as the Rose importer does. So how do I specify the location of my
external static model in the GenModel I create for my dynamic model?
There are a numbe rof properties which come into question (addImport,
setForeignModel, ...) but none is documented anywhere. Any pointers to
documentation or use welcome.
<br>
</blockquote>
Is the *.genmodel for your new model in the workspace somewhere?&nbsp; I
needs to be...<br>
<blockquote cite="mid:g28vv9$48v$1@build.eclipse.org" type="cite"><br>
<br>
Regards
<br>
<br>
JG
<br>
<br>
</blockquote>
<br>
</body>
</html>

--------------040203000707080802010409--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Problem with "external" GenModel when programmatically triggering the generator [message #419834 is a reply to message #419755] Mon, 09 June 2008 05:22 Go to previous messageGo to next message
JG is currently offline JGFriend
Messages: 51
Registered: July 2009
Member
Ed,

>> How can that be? How can the Ecore model/file be different from the
>> actual code? I have yet to find the place in the code where all the
>> properties of the meta classes are actually set.
> Do you have code like this in the generated package. Is your GenModel's
> compliance level set to 5.0?

Its set to 6.0, so I expect Generics to be available.

>
> public void initializePackageContents()
> {
> if (isInitialized) return;
> isInitialized = true;
>
> // Initialize package
> setName(eNAME);
> setNsPrefix(eNS_PREFIX);
> setNsURI(eNS_URI);
>
> // Create type parameters
> addETypeParameter(eeListEDataType, "E");


In my JavatypesPackageImpl, I have


public void initializePackageContents() {
if (isInitialized) return;
isInitialized = true;

// Initialize package
setName(eNAME);
setNsPrefix(eNS_PREFIX);
setNsURI(eNS_URI);

// Initialize data types

[lots of datatypes here, among them...]

initEDataType(pCollectionEDataType, Collection.class, "PCollection",
IS_SERIALIZABLE, !IS_GENERATED_INSTANCE_CLASS);

// Create resource
createResource(eNS_URI);
}


No addETypeParameter(...) in the entire class.

>> Just to see what would happen, I also tried to generate my model from
>> the Ecore file via Eclipse and the GenModel editor. The result was
>> quite different: I got a load of error messages stating that the ecore
>> model contains an unresolved proxy, to an EClass of my static model
>> which I reference (actually: subclass) from the dynamic model. So
>> apparently, when validating the ecore model, the generator can not
>> find my static model.
> What did the proxy URIs look like?

<nsURIOfMyStaticPackage>#//<NameOfMyStaticClass>

Actually, I expected that my static classes/genmodel would not be found
at first and that I would need a way to tell the generator where to
them. But how?


> Is the *.genmodel for your new model in the workspace somewhere? I
> needs to be...

You mean the *.genmodel for the dynamically created model? Well, I am
trying to use the generator standalone. It is supposed to be a component
in a larger framework which is not meant to be executed as an Eclipse
application.

The genmodel is in memory, and I can successfully write it to a file, by
putting it and my dynamic Ecore model together into a ResourceSet.
However, the Diagnostic shows the dangling HREFs to my static model.
How could I tell the generator where to find it outside the Eclipse
platform?

I could successfully load the static genmodel (via a file URI), and
added the Genpackage for the missing EPackage to usedGenPackage



Regards

JG
Re: Problem with "external" GenModel when programmatically triggering the generator [message #419838 is a reply to message #419834] Mon, 09 June 2008 12:41 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050108050201010103080307
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

JG wrote:
> Ed,
>
>>> How can that be? How can the Ecore model/file be different from the
>>> actual code? I have yet to find the place in the code where all the
>>> properties of the meta classes are actually set.
>> Do you have code like this in the generated package. Is your
>> GenModel's compliance level set to 5.0?
>
> Its set to 6.0, so I expect Generics to be available.
>
>>
>> public void initializePackageContents()
>> {
>> if (isInitialized) return;
>> isInitialized = true;
>>
>> // Initialize package
>> setName(eNAME);
>> setNsPrefix(eNS_PREFIX);
>> setNsURI(eNS_URI);
>>
>> // Create type parameters
>> addETypeParameter(eeListEDataType, "E");
>
>
> In my JavatypesPackageImpl, I have
>
>
> public void initializePackageContents() {
> if (isInitialized) return;
> isInitialized = true;
>
> // Initialize package
> setName(eNAME);
> setNsPrefix(eNS_PREFIX);
> setNsURI(eNS_URI);
>
> // Initialize data types
>
> [lots of datatypes here, among them...]
>
> initEDataType(pCollectionEDataType, Collection.class,
> "PCollection", IS_SERIALIZABLE, !IS_GENERATED_INSTANCE_CLASS);
>
> // Create resource
> createResource(eNS_URI);
> }
>
>
> No addETypeParameter(...) in the entire class.
So that explains why you don't see it in the generated model. But I
can't reproduce this. If I add EClass "X" with ETypeParameter "T" to
the library model, set it to 6.0 compliance, I end up with

// Create type parameters
addETypeParameter(xEClass, "T");
>
>>> Just to see what would happen, I also tried to generate my model
>>> from the Ecore file via Eclipse and the GenModel editor. The result
>>> was quite different: I got a load of error messages stating that the
>>> ecore model contains an unresolved proxy, to an EClass of my static
>>> model which I reference (actually: subclass) from the dynamic model.
>>> So apparently, when validating the ecore model, the generator can
>>> not find my static model.
>> What did the proxy URIs look like?
>
> <nsURIOfMyStaticPackage>#//<NameOfMyStaticClass>
>
> Actually, I expected that my static classes/genmodel would not be
> found at first and that I would need a way to tell the generator where
> to them. But how?
I'm expecting this to be of the form
platform:/<plugin-or-resource>/<plugin-id-project-name>/model/Xyz.ecore#// <...>.
I.e., the development time version of the model is registered in the
plugin.xml and should be available in the binary plugin. E.g.,

<extension point="org.eclipse.emf.ecore.generated_package">
<package
uri="http://www.example.com/Library"
class="com.example.library.LibraryPackage"
*genModel="model/Library.genmodel"*/>
</extension>
>
>
>> Is the *.genmodel for your new model in the workspace somewhere? I
>> needs to be...
>
> You mean the *.genmodel for the dynamically created model? Well, I am
> trying to use the generator standalone. It is supposed to be a
> component in a larger framework which is not meant to be executed as
> an Eclipse application.
No, I mean for the base model being used by your dynamic model. You
need the GenModel for it as well.
>
> The genmodel is in memory, and I can successfully write it to a file,
> by putting it and my dynamic Ecore model together into a ResourceSet.
> However, the Diagnostic shows the dangling HREFs to my static model.
> How could I tell the generator where to find it outside the Eclipse
> platform?
All things can be accomplished with URI mappings in the ResourceSet's
URI converter.
>
> I could successfully load the static genmodel (via a file URI), and
> added the Genpackage for the missing EPackage to usedGenPackage
You're dynamic model needs to refer to the EPackages loaded from this
other GenModel. It's even possible to redirect the nsURI (as you're
using it already) to the physical location of the EPackage instance you
load for the static model's GenModel. Note also that static EPackages
are contained by a resource who's URI is set to be the nsURI, so I
wouldn't expect there'd be dangling references when referring to them...
>
>
>
> Regards
>
> JG


--------------050108050201010103080307
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
JG wrote:
<blockquote cite="mid:g2ienm$v4g$2@build.eclipse.org" type="cite">Ed,
<br>
<br>
<blockquote type="cite">
<blockquote type="cite">How can that be? How can the Ecore
model/file be different from the actual code? I have yet to find the
place in the code where all the properties of the meta classes are
actually set.
<br>
</blockquote>
Do you have code like this in the generated package.&nbsp; Is your
GenModel's compliance level set to 5.0?
<br>
</blockquote>
<br>
Its set to 6.0, so I expect Generics to be available.
<br>
<br>
<blockquote type="cite"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void initializePackageContents()
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; if (isInitialized) return;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; isInitialized = true;
<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; // Initialize package
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; setName(eNAME);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; setNsPrefix(eNS_PREFIX);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; setNsURI(eNS_URI);
<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; // Create type parameters
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; addETypeParameter(eeListEDataType, "E");
<br>
</blockquote>
<br>
<br>
In my JavatypesPackageImpl, I have
<br>
<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;public void initializePackageContents() {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; if (isInitialized) return;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; isInitialized = true;
<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; // Initialize package
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; setName(eNAME);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; setNsPrefix(eNS_PREFIX);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; setNsURI(eNS_URI);
<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; // Initialize data types
<br>
<br>
[lots of datatypes here, among them...]
<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; initEDataType(pCollectionEDataType, Collection.class,
"PCollection", IS_SERIALIZABLE, !IS_GENERATED_INSTANCE_CLASS);
<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; // Create resource
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; createResource(eNS_URI);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;}
<br>
<br>
<br>
No addETypeParameter(...) in the entire class.
<br>
</blockquote>
So that explains why you don't see it in the generated model.&nbsp; But I
can't reproduce this.&nbsp; If I add EClass "X" with ETypeParameter "T" to
the library model, set it to 6.0 compliance, I end up with<br>
<br>
&nbsp;&nbsp;&nbsp; // Create type parameters<br>
&nbsp;&nbsp;&nbsp; addETypeParameter(xEClass, "T");<br>
<blockquote cite="mid:g2ienm$v4g$2@build.eclipse.org" type="cite"><br>
<blockquote type="cite">
<blockquote type="cite">Just to see what would happen, I also tried
to generate my model from the Ecore file via Eclipse and the GenModel
editor. The result was quite different: I got a load of error messages
stating that the ecore model contains an unresolved proxy, to an EClass
of my static model which I reference (actually: subclass) from the
dynamic model. So apparently, when validating the ecore model, the
generator can not find my static model. </blockquote>
What did the proxy URIs look like?
<br>
</blockquote>
<br>
&lt;nsURIOfMyStaticPackage&gt;#//&lt;NameOfMySta ticClass&gt;
<br>
<br>
Actually, I expected that my static classes/genmodel would not be found
at first and that I would need a way to tell the generator where to
them. But how?
<br>
</blockquote>
I'm expecting this to be of the form
platform:/&lt;plugin-or-resource&gt;/&lt;plugin- id-project-name&gt;/model/Xyz.ecore#//&lt;...&gt ;.&nbsp;&nbsp;&nbsp;
I.e., the development time version of the model is registered in the
plugin.xml and should be available in the binary plugin.&nbsp; E.g.,<br>
<br>
&nbsp;&nbsp; &lt;extension point="org.eclipse.emf.ecore.generated_package"&gt;<br >
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;package<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; uri=<a class="moz-txt-link-rfc2396E" href="http://www.example.com/Library">"http://www.example.com/Library"</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; class="com.example.library.LibraryPackage"<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>genModel="model/Library.genmodel"</b>/&gt;<br>
&nbsp;&nbsp; &lt;/extension&gt;<br>
<blockquote cite="mid:g2ienm$v4g$2@build.eclipse.org" type="cite"><br>
<br>
<blockquote type="cite">Is the *.genmodel for your new model in the
workspace somewhere?&nbsp; I needs to be...
<br>
</blockquote>
<br>
You mean the *.genmodel for the dynamically created model? Well, I am
trying to use the generator standalone. It is supposed to be a
component in a larger framework which is not meant to be executed as an
Eclipse application.
<br>
</blockquote>
No, I mean for the base model being used by your dynamic model.&nbsp; You
need the GenModel for it as well.<br>
<blockquote cite="mid:g2ienm$v4g$2@build.eclipse.org" type="cite"><br>
The genmodel is in memory, and I can successfully write it to a file,
by putting it and my dynamic Ecore model together into a ResourceSet.
However, the Diagnostic shows the dangling HREFs to my static model.
<br>
How could I tell the generator where to find it outside the Eclipse
platform?
<br>
</blockquote>
All things can be accomplished with URI mappings in the ResourceSet's
URI converter. <br>
<blockquote cite="mid:g2ienm$v4g$2@build.eclipse.org" type="cite"><br>
I could successfully load the static genmodel (via a file URI), and
added the Genpackage for the missing EPackage to usedGenPackage
<br>
</blockquote>
You're dynamic model needs to refer to the EPackages loaded from this
other GenModel.&nbsp; It's even possible to redirect the nsURI (as you're
using it already) to the physical location of the EPackage instance you
load for the static model's GenModel.&nbsp; Note also that static EPackages
are contained by a resource who's URI is set to be the nsURI, so I
wouldn't expect there'd be dangling references when referring to them...<br>
<blockquote cite="mid:g2ienm$v4g$2@build.eclipse.org" type="cite"><br>
<br>
<br>
Regards
<br>
<br>
JG
<br>
</blockquote>
<br>
</body>
</html>

--------------050108050201010103080307--


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Copying EObjects with readonly properties
Next Topic:Qualified elements in XML
Goto Forum:
  


Current Time: Thu Apr 25 08:10:26 GMT 2024

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

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

Back to the top