Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to use external classes in an ecore model
How to use external classes in an ecore model [message #409382] Fri, 18 May 2007 10:27 Go to next message
Eclipse UserFriend
Originally posted by: psentosa.yahoo.com

Hi,

In my ecore model, a class should have references to classes that are not
(and shouldn't be) part of this model (or any other model) .These classes
are actually kept in another plug-in project.
How can I reference them in my model? Until now I've only seen an .ecore
file that refers to other .ecore-s, but not to classes.

I tried to create classes which are named based on those external classes,
and in their field "Instance Class Name" I put the qualified class name of
the referred classes.
But then I see in the generated code, that those classes are IMPLEMENTed.
(which is not correct, because they're classes). In case it was an external
interface, it will be OK because a new interface, that extends the external
interface is generated, and this will be implemented by the corresponding
class. But what about classes?

The same problem is also for any java libraries that are not yet implemented
as .ecore data type (e.g ArrayList?). Will it be a good approach to create a
data type that has its filed "Instance Class Name" referring to the java
libraries? But than I would have the same problematic result in the
generated code.

Thanks for any idea and suggestions.

Regards
Paul
Re: How to use external classes in an ecore model [message #409383 is a reply to message #409382] Fri, 18 May 2007 11:20 Go to previous messageGo to next message
Jacek Pospychala is currently offline Jacek PospychalaFriend
Messages: 159
Registered: July 2009
Senior Member
Paul,

EDataType's are designed for this purpose. When you create EDataType and
set it Instance Class name to e.g. ArrayList, only appropriate feature
id will be defined in package. If you mark it also serializable, then
generated factory implementation will additionally have convertToString
and createFromString methods.

EMF actually has already a versatile set of etypes implementing
java.util Collections interfaces, starting from BasicEList, that you may
want to use.
To use them in your ecore, set lower and upper bounds, so EMF will
automatically select apropriate list for you.

Hope this helps

Paul Sentosa wrote:
> Hi,
>
> In my ecore model, a class should have references to classes that are not
> (and shouldn't be) part of this model (or any other model) .These classes
> are actually kept in another plug-in project.
> How can I reference them in my model? Until now I've only seen an .ecore
> file that refers to other .ecore-s, but not to classes.
>
> I tried to create classes which are named based on those external classes,
> and in their field "Instance Class Name" I put the qualified class name of
> the referred classes.
> But then I see in the generated code, that those classes are IMPLEMENTed.
> (which is not correct, because they're classes). In case it was an external
> interface, it will be OK because a new interface, that extends the external
> interface is generated, and this will be implemented by the corresponding
> class. But what about classes?
>
> The same problem is also for any java libraries that are not yet implemented
> as .ecore data type (e.g ArrayList?). Will it be a good approach to create a
> data type that has its filed "Instance Class Name" referring to the java
> libraries? But than I would have the same problematic result in the
> generated code.
>
> Thanks for any idea and suggestions.
>
> Regards
> Paul
>
>
Re: How to use external classes in an ecore model [message #409384 is a reply to message #409383] Fri, 18 May 2007 12:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: psentosa.yahoo.com

Jacek,

thanks for your answer.


I tried to follow your suggestion: create a datatype called ArrayList, set
its Instance Class Name to java.util.ArrayList.
But then when I tried to get the .genmodel file, I got the following error
report:
java.lang.ClassCastException: org.eclipse.emf.ecore.impl.EDataTypeImpl
at
org.eclipse.emf.ecore.impl.EReferenceImpl.getEReferenceType( EReferenceImpl.j
ava:268)
at org.eclipse.emf.ecore.impl.EReferenceImpl.eGet(EReferenceImp l.java:358)
at
org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:967)
at
org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:959)
.....
......
how can I get this correct?

And should this approach also work for external class -case I mentioned
before?
I created a DataType called OwnClass representing the class
own.package.OwnClass, a class kept in a certain external package..
Doing this, I could get the .genmodel file, but not the generated code, due
to this error:
java.lang.NullPointerException
at
org.eclipse.emf.codegen.ecore.genmodel.impl.GenTypedElementI mpl.getTypeGenPa
ckage(GenTypedElementImpl.java:80)
at
org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl$D ependencyHelper.
<init>(GenPackageImpl.java:2050)
at
org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl.p repareCache(GenP
ackageImpl.java:2777)
...........
...........

and also, one further question: in case I could make this work, how should I
make a DataType as a reference in my class?

Thanks for further explanation

Regards
Paul

"Jacek Pospychala" <jacek.pospychala@pl.ibm.com> schrieb im Newsbeitrag
news:f2k25q$vtp$1@build.eclipse.org...
> Paul,
>
> EDataType's are designed for this purpose. When you create EDataType and
> set it Instance Class name to e.g. ArrayList, only appropriate feature
> id will be defined in package. If you mark it also serializable, then
> generated factory implementation will additionally have convertToString
> and createFromString methods.
>
> EMF actually has already a versatile set of etypes implementing
> java.util Collections interfaces, starting from BasicEList, that you may
> want to use.
> To use them in your ecore, set lower and upper bounds, so EMF will
> automatically select apropriate list for you.
>
> Hope this helps
>
> Paul Sentosa wrote:
> > Hi,
> >
> > In my ecore model, a class should have references to classes that are
not
> > (and shouldn't be) part of this model (or any other model) .These
classes
> > are actually kept in another plug-in project.
> > How can I reference them in my model? Until now I've only seen an .ecore
> > file that refers to other .ecore-s, but not to classes.
> >
> > I tried to create classes which are named based on those external
classes,
> > and in their field "Instance Class Name" I put the qualified class name
of
> > the referred classes.
> > But then I see in the generated code, that those classes are
IMPLEMENTed.
> > (which is not correct, because they're classes). In case it was an
external
> > interface, it will be OK because a new interface, that extends the
external
> > interface is generated, and this will be implemented by the
corresponding
> > class. But what about classes?
> >
> > The same problem is also for any java libraries that are not yet
implemented
> > as .ecore data type (e.g ArrayList?). Will it be a good approach to
create a
> > data type that has its filed "Instance Class Name" referring to the java
> > libraries? But than I would have the same problematic result in the
> > generated code.
> >
> > Thanks for any idea and suggestions.
> >
> > Regards
> > Paul
> >
> >
Re: How to use external classes in an ecore model [message #409387 is a reply to message #409384] Fri, 18 May 2007 14:03 Go to previous messageGo to next message
Marcelo Paternostro is currently offline Marcelo PaternostroFriend
Messages: 602
Registered: July 2009
Senior Member
Hi Paul,

DataTypes, like primitive types, can only be used as the type of
attributes. I believe the first error is happening because you've
defined the feature as a reference.

Regarding the NPE... Are you using EMF 2.3.0? In this version we are
providing a very complete EcoreValidation that would spot problems in
your Ecore model as soon as you open the GenModel editor. Even if you
are currently tied to an earlier version, I would recommend you to have
a separate Eclipse with 2.3.0 installed just to double check your
models. Believe me... It can save you lots of debugging/newsgroup time ;-)

Cheers,
Marcelo

Paul Sentosa wrote:
> Jacek,
>
> thanks for your answer.
>
>
> I tried to follow your suggestion: create a datatype called ArrayList, set
> its Instance Class Name to java.util.ArrayList.
> But then when I tried to get the .genmodel file, I got the following error
> report:
> java.lang.ClassCastException: org.eclipse.emf.ecore.impl.EDataTypeImpl
> at
> org.eclipse.emf.ecore.impl.EReferenceImpl.getEReferenceType( EReferenceImpl.j
> ava:268)
> at org.eclipse.emf.ecore.impl.EReferenceImpl.eGet(EReferenceImp l.java:358)
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:967)
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:959)
> ....
> .....
> how can I get this correct?
>
> And should this approach also work for external class -case I mentioned
> before?
> I created a DataType called OwnClass representing the class
> own.package.OwnClass, a class kept in a certain external package..
> Doing this, I could get the .genmodel file, but not the generated code, due
> to this error:
> java.lang.NullPointerException
> at
> org.eclipse.emf.codegen.ecore.genmodel.impl.GenTypedElementI mpl.getTypeGenPa
> ckage(GenTypedElementImpl.java:80)
> at
> org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl$D ependencyHelper.
> <init>(GenPackageImpl.java:2050)
> at
> org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl.p repareCache(GenP
> ackageImpl.java:2777)
> ..........
> ..........
>
> and also, one further question: in case I could make this work, how should I
> make a DataType as a reference in my class?
>
> Thanks for further explanation
>
> Regards
> Paul
>
> "Jacek Pospychala" <jacek.pospychala@pl.ibm.com> schrieb im Newsbeitrag
> news:f2k25q$vtp$1@build.eclipse.org...
>> Paul,
>>
>> EDataType's are designed for this purpose. When you create EDataType and
>> set it Instance Class name to e.g. ArrayList, only appropriate feature
>> id will be defined in package. If you mark it also serializable, then
>> generated factory implementation will additionally have convertToString
>> and createFromString methods.
>>
>> EMF actually has already a versatile set of etypes implementing
>> java.util Collections interfaces, starting from BasicEList, that you may
>> want to use.
>> To use them in your ecore, set lower and upper bounds, so EMF will
>> automatically select apropriate list for you.
>>
>> Hope this helps
>>
>> Paul Sentosa wrote:
>>> Hi,
>>>
>>> In my ecore model, a class should have references to classes that are
> not
>>> (and shouldn't be) part of this model (or any other model) .These
> classes
>>> are actually kept in another plug-in project.
>>> How can I reference them in my model? Until now I've only seen an .ecore
>>> file that refers to other .ecore-s, but not to classes.
>>>
>>> I tried to create classes which are named based on those external
> classes,
>>> and in their field "Instance Class Name" I put the qualified class name
> of
>>> the referred classes.
>>> But then I see in the generated code, that those classes are
> IMPLEMENTed.
>>> (which is not correct, because they're classes). In case it was an
> external
>>> interface, it will be OK because a new interface, that extends the
> external
>>> interface is generated, and this will be implemented by the
> corresponding
>>> class. But what about classes?
>>>
>>> The same problem is also for any java libraries that are not yet
> implemented
>>> as .ecore data type (e.g ArrayList?). Will it be a good approach to
> create a
>>> data type that has its filed "Instance Class Name" referring to the java
>>> libraries? But than I would have the same problematic result in the
>>> generated code.
>>>
>>> Thanks for any idea and suggestions.
>>>
>>> Regards
>>> Paul
>>>
>>>
>
>
Re: How to use external classes in an ecore model [message #409391 is a reply to message #409387] Fri, 18 May 2007 14:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: psentosa.yahoo.com

Hi Marcelo,
thanks for your answer.
No, I haven't even used the ArrayList; I just defined it first to find out
how the generated code of it looks like, but I got those error report.
And here is also the problem:
In my generated code later, I'd like to have following line generated:

ArrayList children = new ArrayList();
RefererredClass rc;

So as you can see, both are references and not part of the model I defined.

Regarding NPE, yes, I used Eclipse 3.3M4 and its corresponding EMF version.

Any other idea?
Many thanks in advance!

Regards
Paul



"Marcelo Paternostro" <marcelop@ca.ibm.com> schrieb im Newsbeitrag
news:f2kbnt$an2$1@build.eclipse.org...
> Hi Paul,
>
> DataTypes, like primitive types, can only be used as the type of
> attributes. I believe the first error is happening because you've
> defined the feature as a reference.
>
> Regarding the NPE... Are you using EMF 2.3.0? In this version we are
> providing a very complete EcoreValidation that would spot problems in
> your Ecore model as soon as you open the GenModel editor. Even if you
> are currently tied to an earlier version, I would recommend you to have
> a separate Eclipse with 2.3.0 installed just to double check your
> models. Believe me... It can save you lots of debugging/newsgroup time
;-)
>
> Cheers,
> Marcelo
>
> Paul Sentosa wrote:
> > Jacek,
> >
> > thanks for your answer.
> >
> >
> > I tried to follow your suggestion: create a datatype called ArrayList,
set
> > its Instance Class Name to java.util.ArrayList.
> > But then when I tried to get the .genmodel file, I got the following
error
> > report:
> > java.lang.ClassCastException: org.eclipse.emf.ecore.impl.EDataTypeImpl
> > at
> >
org.eclipse.emf.ecore.impl.EReferenceImpl.getEReferenceType( EReferenceImpl.j
> > ava:268)
> > at
org.eclipse.emf.ecore.impl.EReferenceImpl.eGet(EReferenceImp l.java:358)
> > at
> >
org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:967)
> > at
> >
org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:959)
> > ....
> > .....
> > how can I get this correct?
> >
> > And should this approach also work for external class -case I mentioned
> > before?
> > I created a DataType called OwnClass representing the class
> > own.package.OwnClass, a class kept in a certain external package..
> > Doing this, I could get the .genmodel file, but not the generated code,
due
> > to this error:
> > java.lang.NullPointerException
> > at
> >
org.eclipse.emf.codegen.ecore.genmodel.impl.GenTypedElementI mpl.getTypeGenPa
> > ckage(GenTypedElementImpl.java:80)
> > at
> >
org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl$D ependencyHelper.
> > <init>(GenPackageImpl.java:2050)
> > at
> >
org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl.p repareCache(GenP
> > ackageImpl.java:2777)
> > ..........
> > ..........
> >
> > and also, one further question: in case I could make this work, how
should I
> > make a DataType as a reference in my class?
> >
> > Thanks for further explanation
> >
> > Regards
> > Paul
> >
> > "Jacek Pospychala" <jacek.pospychala@pl.ibm.com> schrieb im Newsbeitrag
> > news:f2k25q$vtp$1@build.eclipse.org...
> >> Paul,
> >>
> >> EDataType's are designed for this purpose. When you create EDataType
and
> >> set it Instance Class name to e.g. ArrayList, only appropriate feature
> >> id will be defined in package. If you mark it also serializable, then
> >> generated factory implementation will additionally have convertToString
> >> and createFromString methods.
> >>
> >> EMF actually has already a versatile set of etypes implementing
> >> java.util Collections interfaces, starting from BasicEList, that you
may
> >> want to use.
> >> To use them in your ecore, set lower and upper bounds, so EMF will
> >> automatically select apropriate list for you.
> >>
> >> Hope this helps
> >>
> >> Paul Sentosa wrote:
> >>> Hi,
> >>>
> >>> In my ecore model, a class should have references to classes that are
> > not
> >>> (and shouldn't be) part of this model (or any other model) .These
> > classes
> >>> are actually kept in another plug-in project.
> >>> How can I reference them in my model? Until now I've only seen an
..ecore
> >>> file that refers to other .ecore-s, but not to classes.
> >>>
> >>> I tried to create classes which are named based on those external
> > classes,
> >>> and in their field "Instance Class Name" I put the qualified class
name
> > of
> >>> the referred classes.
> >>> But then I see in the generated code, that those classes are
> > IMPLEMENTed.
> >>> (which is not correct, because they're classes). In case it was an
> > external
> >>> interface, it will be OK because a new interface, that extends the
> > external
> >>> interface is generated, and this will be implemented by the
> > corresponding
> >>> class. But what about classes?
> >>>
> >>> The same problem is also for any java libraries that are not yet
> > implemented
> >>> as .ecore data type (e.g ArrayList?). Will it be a good approach to
> > create a
> >>> data type that has its filed "Instance Class Name" referring to the
java
> >>> libraries? But than I would have the same problematic result in the
> >>> generated code.
> >>>
> >>> Thanks for any idea and suggestions.
> >>>
> >>> Regards
> >>> Paul
> >>>
> >>>
> >
> >
Re: How to use external classes in an ecore model [message #409392 is a reply to message #409391] Fri, 18 May 2007 15:24 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29655
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050300010109020109030205
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Paul,

It's very clear that you have an EReference with an eType that's an
EDataType and the validation support should spot that (when, for
example, you right click and invoke "Validate" from the root package)
but I'm not sure it was complete in M4. I'd suggest using M7. Your
second problem sounds like a feature with no type at all. Again,
validation should report that. I can't imagine that it would be a good
idea to use ArrayList in your APIs. You're sure that a multi-valued
feature (upperBound set to -1) would not be more appropriate?


Paul Sentosa wrote:
> Hi Marcelo,
> thanks for your answer.
> No, I haven't even used the ArrayList; I just defined it first to find out
> how the generated code of it looks like, but I got those error report.
> And here is also the problem:
> In my generated code later, I'd like to have following line generated:
>
> ArrayList children = new ArrayList();
> RefererredClass rc;
>
> So as you can see, both are references and not part of the model I defined.
>
> Regarding NPE, yes, I used Eclipse 3.3M4 and its corresponding EMF version.
>
> Any other idea?
> Many thanks in advance!
>
> Regards
> Paul
>
>
>
> "Marcelo Paternostro" <marcelop@ca.ibm.com> schrieb im Newsbeitrag
> news:f2kbnt$an2$1@build.eclipse.org...
>
>> Hi Paul,
>>
>> DataTypes, like primitive types, can only be used as the type of
>> attributes. I believe the first error is happening because you've
>> defined the feature as a reference.
>>
>> Regarding the NPE... Are you using EMF 2.3.0? In this version we are
>> providing a very complete EcoreValidation that would spot problems in
>> your Ecore model as soon as you open the GenModel editor. Even if you
>> are currently tied to an earlier version, I would recommend you to have
>> a separate Eclipse with 2.3.0 installed just to double check your
>> models. Believe me... It can save you lots of debugging/newsgroup time
>>
> ;-)
>
>> Cheers,
>> Marcelo
>>
>> Paul Sentosa wrote:
>>
>>> Jacek,
>>>
>>> thanks for your answer.
>>>
>>>
>>> I tried to follow your suggestion: create a datatype called ArrayList,
>>>
> set
>
>>> its Instance Class Name to java.util.ArrayList.
>>> But then when I tried to get the .genmodel file, I got the following
>>>
> error
>
>>> report:
>>> java.lang.ClassCastException: org.eclipse.emf.ecore.impl.EDataTypeImpl
>>> at
>>>
>>>
> org.eclipse.emf.ecore.impl.EReferenceImpl.getEReferenceType( EReferenceImpl.j
>
>>> ava:268)
>>> at
>>>
> org.eclipse.emf.ecore.impl.EReferenceImpl.eGet(EReferenceImp l.java:358)
>
>>> at
>>>
>>>
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:967)
>
>>> at
>>>
>>>
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:959)
>
>>> ....
>>> .....
>>> how can I get this correct?
>>>
>>> And should this approach also work for external class -case I mentioned
>>> before?
>>> I created a DataType called OwnClass representing the class
>>> own.package.OwnClass, a class kept in a certain external package..
>>> Doing this, I could get the .genmodel file, but not the generated code,
>>>
> due
>
>>> to this error:
>>> java.lang.NullPointerException
>>> at
>>>
>>>
> org.eclipse.emf.codegen.ecore.genmodel.impl.GenTypedElementI mpl.getTypeGenPa
>
>>> ckage(GenTypedElementImpl.java:80)
>>> at
>>>
>>>
> org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl$D ependencyHelper.
>
>>> <init>(GenPackageImpl.java:2050)
>>> at
>>>
>>>
> org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl.p repareCache(GenP
>
>>> ackageImpl.java:2777)
>>> ..........
>>> ..........
>>>
>>> and also, one further question: in case I could make this work, how
>>>
> should I
>
>>> make a DataType as a reference in my class?
>>>
>>> Thanks for further explanation
>>>
>>> Regards
>>> Paul
>>>
>>> "Jacek Pospychala" <jacek.pospychala@pl.ibm.com> schrieb im Newsbeitrag
>>> news:f2k25q$vtp$1@build.eclipse.org...
>>>
>>>> Paul,
>>>>
>>>> EDataType's are designed for this purpose. When you create EDataType
>>>>
> and
>
>>>> set it Instance Class name to e.g. ArrayList, only appropriate feature
>>>> id will be defined in package. If you mark it also serializable, then
>>>> generated factory implementation will additionally have convertToString
>>>> and createFromString methods.
>>>>
>>>> EMF actually has already a versatile set of etypes implementing
>>>> java.util Collections interfaces, starting from BasicEList, that you
>>>>
> may
>
>>>> want to use.
>>>> To use them in your ecore, set lower and upper bounds, so EMF will
>>>> automatically select apropriate list for you.
>>>>
>>>> Hope this helps
>>>>
>>>> Paul Sentosa wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> In my ecore model, a class should have references to classes that are
>>>>>
>>> not
>>>
>>>>> (and shouldn't be) part of this model (or any other model) .These
>>>>>
>>> classes
>>>
>>>>> are actually kept in another plug-in project.
>>>>> How can I reference them in my model? Until now I've only seen an
>>>>>
> .ecore
>
>>>>> file that refers to other .ecore-s, but not to classes.
>>>>>
>>>>> I tried to create classes which are named based on those external
>>>>>
>>> classes,
>>>
>>>>> and in their field "Instance Class Name" I put the qualified class
>>>>>
> name
>
>>> of
>>>
>>>>> the referred classes.
>>>>> But then I see in the generated code, that those classes are
>>>>>
>>> IMPLEMENTed.
>>>
>>>>> (which is not correct, because they're classes). In case it was an
>>>>>
>>> external
>>>
>>>>> interface, it will be OK because a new interface, that extends the
>>>>>
>>> external
>>>
>>>>> interface is generated, and this will be implemented by the
>>>>>
>>> corresponding
>>>
>>>>> class. But what about classes?
>>>>>
>>>>> The same problem is also for any java libraries that are not yet
>>>>>
>>> implemented
>>>
>>>>> as .ecore data type (e.g ArrayList?). Will it be a good approach to
>>>>>
>>> create a
>>>
>>>>> data type that has its filed "Instance Class Name" referring to the
>>>>>
> java
>
>>>>> libraries? But than I would have the same problematic result in the
>>>>> generated code.
>>>>>
>>>>> Thanks for any idea and suggestions.
>>>>>
>>>>> Regards
>>>>> Paul
>>>>>
>>>>>
>>>>>
>>>
>
>
>


--------------050300010109020109030205
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">
Paul,<br>
<br>
It's very clear that you have an EReference with an eType that's an
EDataType and the validation support should spot that (when, for
example, you right click and invoke "Validate" from the root package)
but I'm not sure it was complete in M4.&nbsp; I'd suggest using M7.&nbsp; Your
second problem sounds like a feature with no type at all.&nbsp; Again,
validation should report that.&nbsp;&nbsp; I can't imagine that it would be a
good idea to use ArrayList in your APIs.&nbsp; You're sure that a
multi-valued feature (upperBound set to -1) would not be more
appropriate?<br>
<br>
<br>
Paul Sentosa wrote:
<blockquote cite="midf2kenh$6e1$1@build.eclipse.org" type="cite">
<pre wrap="">Hi Marcelo,
thanks for your answer.
No, I haven't even used the ArrayList; I just defined it first to find out
how the generated code of it looks like, but I got those error report.
And here is also the problem:
In my generated code later, I'd like to have following line generated:

ArrayList children = new ArrayList();
RefererredClass rc;

So as you can see, both are references and not part of the model I defined.

Regarding NPE, yes, I used Eclipse 3.3M4 and its corresponding EMF version.

Any other idea?
Many thanks in advance!

Regards
Paul



"Marcelo Paternostro" <a class="moz-txt-link-rfc2396E" href="mailto:marcelop@ca.ibm.com">&lt;marcelop@ca.ibm.com&gt;</a> schrieb im Newsbeitrag
<a class="moz-txt-link-freetext" href="news:f2kbnt$an2$1@build.eclipse.org">news:f2kbnt$an2$1@build.eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Hi Paul,

DataTypes, like primitive types, can only be used as the type of
attributes. I believe the first error is happening because you've
defined the feature as a reference.

Regarding the NPE... Are you using EMF 2.3.0? In this version we are
providing a very complete EcoreValidation that would spot problems in
your Ecore model as soon as you open the GenModel editor. Even if you
are currently tied to an earlier version, I would recommend you to have
a separate Eclipse with 2.3.0 installed just to double check your
models. Believe me... It can save you lots of debugging/newsgroup time
</pre>
</blockquote>
<pre wrap=""><!---->;-)
</pre>
<blockquote type="cite">
<pre wrap="">Cheers,
Marcelo

Paul Sentosa wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Jacek,

thanks for your answer.


I tried to follow your suggestion: create a datatype called ArrayList,
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->set
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">its Instance Class Name to java.util.ArrayList.
But then when I tried to get the .genmodel file, I got the following
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->error
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">report:
java.lang.ClassCastException: org.eclipse.emf.ecore.impl.EDataTypeImpl
at

</pre>
</blockquote>
</blockquote>
<pre wrap=""><!----> org.eclipse.emf.ecore.impl.EReferenceImpl.getEReferenceType( EReferenceImpl.j
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">ava:268)
at
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!----> org.eclipse.emf.ecore.impl.EReferenceImpl.eGet(EReferenceImp l.java:358)
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap=""> at

</pre>
</blockquote>
</blockquote>
<pre wrap=""><!----> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:967)
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap=""> at

</pre>
</blockquote>
</blockquote>
<pre wrap=""><!----> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:959)
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">....
......
how can I get this correct?

And should this approach also work for external class -case I mentioned
before?
I created a DataType called OwnClass representing the class
own.package.OwnClass, a class kept in a certain external package..
Doing this, I could get the .genmodel file, but not the generated code,
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->due
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">to this error:
java.lang.NullPointerException
at

</pre>
</blockquote>
</blockquote>
<pre wrap=""><!----> org.eclipse.emf.codegen.ecore.genmodel.impl.GenTypedElementI mpl.getTypeGenPa
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">ckage(GenTypedElementImpl.java:80)
at

</pre>
</blockquote>
</blockquote>
<pre wrap=""><!----> org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl$D ependencyHelper.
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">&lt;init&gt;(GenPackageImpl.java:2050)
at

</pre>
</blockquote>
</blockquote>
<pre wrap=""><!----> org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl.p repareCache(GenP
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">ackageImpl.java:2777)
...........
...........

and also, one further question: in case I could make this work, how
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->should I
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">make a DataType as a reference in my class?

Thanks for further explanation

Regards
Paul

"Jacek Pospychala" <a class="moz-txt-link-rfc2396E" href="mailto:jacek.pospychala@pl.ibm.com">&lt;jacek.pospychala@pl.ibm.com&gt;</a> schrieb im Newsbeitrag
<a class="moz-txt-link-freetext" href="news:f2k25q$vtp$1@build.eclipse.org">news:f2k25q$vtp$1@build.eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Paul,

EDataType's are designed for this purpose. When you create EDataType
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->and
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">set it Instance Class name to e.g. ArrayList, only appropriate feature
id will be defined in package. If you mark it also serializable, then
generated factory implementation will additionally have convertToString
and createFromString methods.

EMF actually has already a versatile set of etypes implementing
java.util Collections interfaces, starting from BasicEList, that you
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->may
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">want to use.
To use them in your ecore, set lower and upper bounds, so EMF will
automatically select apropriate list for you.

Hope this helps

Paul Sentosa wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hi,

In my ecore model, a class should have references to classes that are
</pre>
</blockquote>
</blockquote>
<pre wrap="">not
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">(and shouldn't be) part of this model (or any other model) .These
</pre>
</blockquote>
</blockquote>
<pre wrap="">classes
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">are actually kept in another plug-in project.
How can I reference them in my model? Until now I've only seen an
</pre>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->.ecore
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">file that refers to other .ecore-s, but not to classes.

I tried to create classes which are named based on those external
</pre>
</blockquote>
</blockquote>
<pre wrap="">classes,
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">and in their field "Instance Class Name" I put the qualified class
</pre>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->name
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">of
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">the referred classes.
But then I see in the generated code, that those classes are
</pre>
</blockquote>
</blockquote>
<pre wrap="">IMPLEMENTed.
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">(which is not correct, because they're classes). In case it was an
</pre>
</blockquote>
</blockquote>
<pre wrap="">external
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">interface, it will be OK because a new interface, that extends the
</pre>
</blockquote>
</blockquote>
<pre wrap="">external
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">interface is generated, and this will be implemented by the
</pre>
</blockquote>
</blockquote>
<pre wrap="">corresponding
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">class. But what about classes?

The same problem is also for any java libraries that are not yet
</pre>
</blockquote>
</blockquote>
<pre wrap="">implemented
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">as .ecore data type (e.g ArrayList?). Will it be a good approach to
</pre>
</blockquote>
</blockquote>
<pre wrap="">create a
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">data type that has its filed "Instance Class Name" referring to the
</pre>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->java
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">libraries? But than I would have the same problematic result in the
generated code.

Thanks for any idea and suggestions.

Regards
Paul


</pre>
</blockquote>
</blockquote>
<pre wrap="">
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
<br>
</body>
</html>

--------------050300010109020109030205--
Re: How to use external classes in an ecore model [message #409417 is a reply to message #409392] Mon, 21 May 2007 16:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: psentosa.yahoo.com

This is a multi-part message in MIME format.

------=_NextPart_000_000A_01C79BD8.1AC3CFB0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi,

thanks everyone for the answers and sorry for this late reply.
Yes, I was editing the model arbitrarily and didn't notice one reference =
I made before. Sorry about this.

Another question, and hope the last one, regarding referring an external =
class. So far I used those classes only as return type or parameter, so =
it wasn't problem at all defining them as a datatype. Now, I just =
realize that one of the classes in the model should EXTEND an external =
class, which means, I can't define this referred external class using a =
new data type. Instead, this class must somehow be recognized as an =
EClass object (but it shouldn't part of any ecore model). Hope I've =
described this clearly.
Any suggestions how I can solve this kind of problem?

Many thanks in advance
Regards
Paul
"Ed Merks" <merks@ca.ibm.com> schrieb im Newsbeitrag =
news:f2kgep$lk4$1@build.eclipse.org...
Paul,

It's very clear that you have an EReference with an eType that's an =
EDataType and the validation support should spot that (when, for =
example, you right click and invoke "Validate" from the root package) =
but I'm not sure it was complete in M4. I'd suggest using M7. Your =
second problem sounds like a feature with no type at all. Again, =
validation should report that. I can't imagine that it would be a good =
idea to use ArrayList in your APIs. You're sure that a multi-valued =
feature (upperBound set to -1) would not be more appropriate?


Paul Sentosa wrote:=20
Hi Marcelo,
thanks for your answer.
No, I haven't even used the ArrayList; I just defined it first to find =
out
how the generated code of it looks like, but I got those error report.
And here is also the problem:
In my generated code later, I'd like to have following line generated:

ArrayList children =3D new ArrayList();
RefererredClass rc;

So as you can see, both are references and not part of the model I =
defined.

Regarding NPE, yes, I used Eclipse 3.3M4 and its corresponding EMF =
version.

Any other idea?
Many thanks in advance!

Regards
Paul



"Marcelo Paternostro" <marcelop@ca.ibm.com> schrieb im Newsbeitrag
news:f2kbnt$an2$1@build.eclipse.org...
Hi Paul,

DataTypes, like primitive types, can only be used as the type of
attributes. I believe the first error is happening because you've
defined the feature as a reference.

Regarding the NPE... Are you using EMF 2.3.0? In this version we are
providing a very complete EcoreValidation that would spot problems in
your Ecore model as soon as you open the GenModel editor. Even if you
are currently tied to an earlier version, I would recommend you to have
a separate Eclipse with 2.3.0 installed just to double check your
models. Believe me... It can save you lots of debugging/newsgroup time
;-)
Cheers,
Marcelo

Paul Sentosa wrote:
Jacek,

thanks for your answer.


I tried to follow your suggestion: create a datatype called ArrayList,
set
its Instance Class Name to java.util.ArrayList.
But then when I tried to get the .genmodel file, I got the following
error
report:
java.lang.ClassCastException: org.eclipse.emf.ecore.impl.EDataTypeImpl
at

=
org.eclipse.emf.ecore.impl.EReferenceImpl.getEReferenceType( EReferenceImp=
l.j
ava:268)
at
=
org.eclipse.emf.ecore.impl.EReferenceImpl.eGet(EReferenceImp l.java:358)
at

=
org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:96=
7)
at

=
org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:95=
9)
....
......
how can I get this correct?

And should this approach also work for external class -case I mentioned
before?
I created a DataType called OwnClass representing the class
own.package.OwnClass, a class kept in a certain external package..
Doing this, I could get the .genmodel file, but not the generated code,
due
to this error:
java.lang.NullPointerException
at

=
org.eclipse.emf.codegen.ecore.genmodel.impl.GenTypedElementI mpl.getTypeGe=
nPa
ckage(GenTypedElementImpl.java:80)
at

=
org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl$D ependencyHelp=
er.
<init>(GenPackageImpl.java:2050)
at

=
org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl.p repareCache(G=
enP
ackageImpl.java:2777)
...........
...........

and also, one further question: in case I could make this work, how
should I
make a DataType as a reference in my class?

Thanks for further explanation

Regards
Paul

"Jacek Pospychala" <jacek.pospychala@pl.ibm.com> schrieb im Newsbeitrag
news:f2k25q$vtp$1@build.eclipse.org...
Paul,

EDataType's are designed for this purpose. When you create EDataType
and
set it Instance Class name to e.g. ArrayList, only appropriate feature
id will be defined in package. If you mark it also serializable, then
generated factory implementation will additionally have convertToString
and createFromString methods.

EMF actually has already a versatile set of etypes implementing
java.util Collections interfaces, starting from BasicEList, that you
may
want to use.
To use them in your ecore, set lower and upper bounds, so EMF will
automatically select apropriate list for you.

Hope this helps

Paul Sentosa wrote:
Hi,

In my ecore model, a class should have references to classes that are
not
(and shouldn't be) part of this model (or any other model) .These
classes
are actually kept in another plug-in project.
How can I reference them in my model? Until now I've only seen an
.ecore
file that refers to other .ecore-s, but not to classes.

I tried to create classes which are named based on those external
classes,
and in their field "Instance Class Name" I put the qualified class
name
of
the referred classes.
But then I see in the generated code, that those classes are
IMPLEMENTed.
(which is not correct, because they're classes). In case it was an
external
interface, it will be OK because a new interface, that extends the
external
interface is generated, and this will be implemented by the
corresponding
class. But what about classes?

The same problem is also for any java libraries that are not yet
implemented
as .ecore data type (e.g ArrayList?). Will it be a good approach =
to
create a
data type that has its filed "Instance Class Name" referring to =
the
java
libraries? But than I would have the same problematic result in the
generated code.

Thanks for any idea and suggestions.

Regards
Paul


=20

=20

------=_NextPart_000_000A_01C79BD8.1AC3CFB0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type =
content=3Dtext/html;charset=3DISO-8859-1>
<META content=3D"MSHTML 6.00.2800.1561" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY text=3D#000000 bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>thanks everyone for the answers and =
sorry for this=20
late reply.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Yes, I was editing the model =
arbitrarily and didn't=20
notice one reference I made before. Sorry about this.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Another question, and hope the last =
one, regarding=20
referring an external class. So far I used those classes only as return =
type or=20
parameter, so it wasn't problem at all defining them as a datatype. Now, =
I just=20
realize that </FONT><FONT face=3DArial size=3D2>one of the classes in =
the model=20
should EXTEND an external class, which means, I can't define this =
referred=20
external class&nbsp;using a new&nbsp;data type. Instead, this =
class&nbsp;must=20
somehow be recognized as an EClass object (but it shouldn't part of any =
ecore=20
model). Hope I've described this clearly.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Any suggestions how I can solve this =
kind of=20
problem?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Many thanks in advance</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Regards</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Paul</FONT></DIV>
<BLOCKQUOTE=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Ed Merks" &lt;<A =
href=3D"mailto:merks@ca.ibm.com">merks@ca.ibm.com</A>&gt;=20
schrieb im Newsbeitrag <A=20
=
href=3D"news:f2kgep$lk4$1@build.eclipse.org">news:f2kgep$lk4$1@build.ecli=
pse.org</A>...</DIV>Paul,<BR><BR>It's=20
very clear that you have an EReference with an eType that's an =
EDataType and=20
the validation support should spot that (when, for example, you right =
click=20
and invoke "Validate" from the root package) but I'm not sure it was =
complete=20
in M4.&nbsp; I'd suggest using M7.&nbsp; Your second problem sounds =
like a=20
feature with no type at all.&nbsp; Again, validation should report=20
that.&nbsp;&nbsp; I can't imagine that it would be a good idea to use=20
ArrayList in your APIs.&nbsp; You're sure that a multi-valued feature=20
(upperBound set to -1) would not be more appropriate?<BR><BR><BR>Paul =
Sentosa=20
wrote:=20
<BLOCKQUOTE cite=3Dmidf2kenh$6e1$1@build.eclipse.org =
type=3D"cite"><PRE wrap=3D"">Hi Marcelo,
thanks for your answer.
No, I haven't even used the ArrayList; I just defined it first to find =
out
how the generated code of it looks like, but I got those error report.
And here is also the problem:
In my generated code later, I'd like to have following line generated:

ArrayList children =3D new ArrayList();
RefererredClass rc;

So as you can see, both are references and not part of the model I =
defined.

Regarding NPE, yes, I used Eclipse 3.3M4 and its corresponding EMF =
version.

Any other idea?
Many thanks in advance!

Regards
Paul



"Marcelo Paternostro" <A class=3Dmoz-txt-link-rfc2396E =
href=3D"mailto:marcelop@ca.ibm.com">&lt;marcelop@ca.ibm.com&gt;</A> =
schrieb im Newsbeitrag
<A class=3Dmoz-txt-link-freetext =
href=3D"news:f2kbnt$an2$1@build.eclipse.org">news:f2kbnt$an2$1@build.ecli=
pse.org</A>...
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">Hi Paul,

DataTypes, like primitive types, can only be used as the type of
attributes. I believe the first error is happening because you've
defined the feature as a reference.

Regarding the NPE... Are you using EMF 2.3.0? In this version we are
providing a very complete EcoreValidation that would spot problems in
your Ecore model as soon as you open the GenModel editor. Even if you
are currently tied to an earlier version, I would recommend you to have
a separate Eclipse with 2.3.0 installed just to double check your
models. Believe me... It can save you lots of debugging/newsgroup time
</PRE></BLOCKQUOTE><PRE wrap=3D""><!---->;-)
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">Cheers,
Marcelo

Paul Sentosa wrote:
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">Jacek,

thanks for your answer.


I tried to follow your suggestion: create a datatype called ArrayList,
</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap=3D""><!---->set
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">its Instance Class Name =
to java.util.ArrayList.
But then when I tried to get the .genmodel file, I got the following
</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap=3D""><!---->error
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">report:
java.lang.ClassCastException: org.eclipse.emf.ecore.impl.EDataTypeImpl
at

</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE =
wrap=3D""><!---->org.eclipse.emf.ecore.impl.EReferenceImpl.getEReferenceT=
ype(EReferenceImpl.j
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">ava:268)
at
</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE =
wrap=3D""><!---->org.eclipse.emf.ecore.impl.EReferenceImpl.eGet(EReferenc=
eImpl.java:358)
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D""> at

</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE =
wrap=3D""><!---->org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEO=
bjectImpl.java:967)
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D""> at

</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE =
wrap=3D""><!---->org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEO=
bjectImpl.java:959)
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">....
......
how can I get this correct?

And should this approach also work for external class -case I mentioned
before?
I created a DataType called OwnClass representing the class
own.package.OwnClass, a class kept in a certain external package..
Doing this, I could get the .genmodel file, but not the generated code,
</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap=3D""><!---->due
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">to this error:
java.lang.NullPointerException
at

</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE =
wrap=3D""><!---->org.eclipse.emf.codegen.ecore.genmodel.impl.GenTypedElem=
entImpl.getTypeGenPa
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE =
wrap=3D"">ckage(GenTypedElementImpl.java:80)
at

</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE =
wrap=3D""><!---->org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageIm=
pl$DependencyHelper.
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE =
wrap=3D"">&lt;init&gt;(GenPackageImpl.java:2050)
at

</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE =
wrap=3D""><!---->org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageIm=
pl.prepareCache(GenP
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">ackageImpl.java:2777)
...........
...........

and also, one further question: in case I could make this work, how
</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap=3D""><!---->should I
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">make a DataType as a =
reference in my class?

Thanks for further explanation

Regards
Paul

"Jacek Pospychala" <A class=3Dmoz-txt-link-rfc2396E =
href=3D"mailto:jacek.pospychala@pl.ibm.com">&lt;jacek.pospychala@pl.ibm.c=
om&gt;</A> schrieb im Newsbeitrag
<A class=3Dmoz-txt-link-freetext =
href=3D"news:f2k25q$vtp$1@build.eclipse.org">news:f2k25q$vtp$1@build.ecli=
pse.org</A>...
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">Paul,

EDataType's are designed for this purpose. When you create EDataType
</PRE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE><PRE =
wrap=3D""><!---->and
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">set it Instance Class =
name to e.g. ArrayList, only appropriate feature
id will be defined in package. If you mark it also serializable, then
generated factory implementation will additionally have convertToString
and createFromString methods.

EMF actually has already a versatile set of etypes implementing
java.util Collections interfaces, starting from BasicEList, that you
</PRE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE><PRE =
wrap=3D""><!---->may
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">want to use.
To use them in your ecore, set lower and upper bounds, so EMF will
automatically select apropriate list for you.

Hope this helps

Paul Sentosa wrote:
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">Hi,

In my ecore model, a class should have references to classes that are
</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap=3D"">not
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">(and shouldn't be) =
part of this model (or any other model) .These
</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap=3D"">classes
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">are actually kept in =
another plug-in project.
How can I reference them in my model? Until now I've only seen an
</PRE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE ><PRE =
wrap=3D""><!---->.ecore
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">file that refers to =
other .ecore-s, but not to classes.

I tried to create classes which are named based on those external
</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap=3D"">classes,
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">and in their field =
"Instance Class Name" I put the qualified class
</PRE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE ><PRE =
wrap=3D""><!---->name
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">of
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">the referred classes.
But then I see in the generated code, that those classes are
</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap=3D"">IMPLEMENTed.
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">(which is not =
correct, because they're classes). In case it was an
</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap=3D"">external
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">interface, it will be =
OK because a new interface, that extends the
</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap=3D"">external
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">interface is =
generated, and this will be implemented by the
</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap=3D"">corresponding
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">class. But what about =
classes?

The same problem is also for any java libraries that are not yet
</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap=3D"">implemented
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">as .ecore data type =
(e.g ArrayList?). Will it be a good approach to
</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap=3D"">create a
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">data type that has =
its filed "Instance Class Name" referring to the
</PRE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE ><PRE =
wrap=3D""><!---->java
</PRE>
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite">
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">libraries? But than I =
would have the same problematic result in the
generated code.

Thanks for any idea and suggestions.

Regards
Paul


</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap=3D""> =
</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap=3D""><!---->

</PRE></BLOCKQUOTE><BR></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_000A_01C79BD8.1AC3CFB0--
Re: How to use external classes in an ecore model [message #409420 is a reply to message #409417] Mon, 21 May 2007 22:14 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29655
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------040201060805070605020509
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Paul,

It it's an interface, you can define an EClass with that external
interface name set as the instanceClassName as well as isInterface and
isAbstract set to true. If it's literally a class and not an interface,
then you are out of luck unless you do some hand coding since instances
of EClasses must implement EObject/InternalEObject and that' normally
done by extending EObjectImpl or minimally by extending
BasicEObjectImpl. Since you can extend only one class, extending some
other class will force you to copy all of the logic in
BasicEObjectImpl/EObjectImpl into your derived class.


Paul Sentosa wrote:
> Hi,
>
> thanks everyone for the answers and sorry for this late reply.
> Yes, I was editing the model arbitrarily and didn't notice one
> reference I made before. Sorry about this.
>
> Another question, and hope the last one, regarding referring an
> external class. So far I used those classes only as return type or
> parameter, so it wasn't problem at all defining them as a datatype.
> Now, I just realize that one of the classes in the model should EXTEND
> an external class, which means, I can't define this referred external
> class using a new data type. Instead, this class must somehow be
> recognized as an EClass object (but it shouldn't part of any ecore
> model). Hope I've described this clearly.
> Any suggestions how I can solve this kind of problem?
>
> Many thanks in advance
> Regards
> Paul
>
> "Ed Merks" <merks@ca.ibm.com <mailto:merks@ca.ibm.com>> schrieb im
> Newsbeitrag news:f2kgep$lk4$1@build.eclipse.org...
> Paul,
>
> It's very clear that you have an EReference with an eType that's
> an EDataType and the validation support should spot that (when,
> for example, you right click and invoke "Validate" from the root
> package) but I'm not sure it was complete in M4. I'd suggest
> using M7. Your second problem sounds like a feature with no type
> at all. Again, validation should report that. I can't imagine
> that it would be a good idea to use ArrayList in your APIs.
> You're sure that a multi-valued feature (upperBound set to -1)
> would not be more appropriate?
>
>
> Paul Sentosa wrote:
>> Hi Marcelo,
>> thanks for your answer.
>> No, I haven't even used the ArrayList; I just defined it first to find out
>> how the generated code of it looks like, but I got those error report.
>> And here is also the problem:
>> In my generated code later, I'd like to have following line generated:
>>
>> ArrayList children = new ArrayList();
>> RefererredClass rc;
>>
>> So as you can see, both are references and not part of the model I defined.
>>
>> Regarding NPE, yes, I used Eclipse 3.3M4 and its corresponding EMF version.
>>
>> Any other idea?
>> Many thanks in advance!
>>
>> Regards
>> Paul
>>
>>
>>
>> "Marcelo Paternostro" <marcelop@ca.ibm.com> schrieb im Newsbeitrag
>> news:f2kbnt$an2$1@build.eclipse.org...
>>
>>> Hi Paul,
>>>
>>> DataTypes, like primitive types, can only be used as the type of
>>> attributes. I believe the first error is happening because you've
>>> defined the feature as a reference.
>>>
>>> Regarding the NPE... Are you using EMF 2.3.0? In this version we are
>>> providing a very complete EcoreValidation that would spot problems in
>>> your Ecore model as soon as you open the GenModel editor. Even if you
>>> are currently tied to an earlier version, I would recommend you to have
>>> a separate Eclipse with 2.3.0 installed just to double check your
>>> models. Believe me... It can save you lots of debugging/newsgroup time
>>>
>> ;-)
>>
>>> Cheers,
>>> Marcelo
>>>
>>> Paul Sentosa wrote:
>>>
>>>> Jacek,
>>>>
>>>> thanks for your answer.
>>>>
>>>>
>>>> I tried to follow your suggestion: create a datatype called ArrayList,
>>>>
>> set
>>
>>>> its Instance Class Name to java.util.ArrayList.
>>>> But then when I tried to get the .genmodel file, I got the following
>>>>
>> error
>>
>>>> report:
>>>> java.lang.ClassCastException: org.eclipse.emf.ecore.impl.EDataTypeImpl
>>>> at
>>>>
>>>>
>> org.eclipse.emf.ecore.impl.EReferenceImpl.getEReferenceType( EReferenceImpl.j
>>
>>>> ava:268)
>>>> at
>>>>
>> org.eclipse.emf.ecore.impl.EReferenceImpl.eGet(EReferenceImp l.java:358)
>>
>>>> at
>>>>
>>>>
>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:967)
>>
>>>> at
>>>>
>>>>
>> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:959)
>>
>>>> ....
>>>> .....
>>>> how can I get this correct?
>>>>
>>>> And should this approach also work for external class -case I mentioned
>>>> before?
>>>> I created a DataType called OwnClass representing the class
>>>> own.package.OwnClass, a class kept in a certain external package..
>>>> Doing this, I could get the .genmodel file, but not the generated code,
>>>>
>> due
>>
>>>> to this error:
>>>> java.lang.NullPointerException
>>>> at
>>>>
>>>>
>> org.eclipse.emf.codegen.ecore.genmodel.impl.GenTypedElementI mpl.getTypeGenPa
>>
>>>> ckage(GenTypedElementImpl.java:80)
>>>> at
>>>>
>>>>
>> org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl$D ependencyHelper.
>>
>>>> <init>(GenPackageImpl.java:2050)
>>>> at
>>>>
>>>>
>> org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl.p repareCache(GenP
>>
>>>> ackageImpl.java:2777)
>>>> ..........
>>>> ..........
>>>>
>>>> and also, one further question: in case I could make this work, how
>>>>
>> should I
>>
>>>> make a DataType as a reference in my class?
>>>>
>>>> Thanks for further explanation
>>>>
>>>> Regards
>>>> Paul
>>>>
>>>> "Jacek Pospychala" <jacek.pospychala@pl.ibm.com> schrieb im Newsbeitrag
>>>> news:f2k25q$vtp$1@build.eclipse.org...
>>>>
>>>>> Paul,
>>>>>
>>>>> EDataType's are designed for this purpose. When you create EDataType
>>>>>
>> and
>>
>>>>> set it Instance Class name to e.g. ArrayList, only appropriate feature
>>>>> id will be defined in package. If you mark it also serializable, then
>>>>> generated factory implementation will additionally have convertToString
>>>>> and createFromString methods.
>>>>>
>>>>> EMF actually has already a versatile set of etypes implementing
>>>>> java.util Collections interfaces, starting from BasicEList, that you
>>>>>
>> may
>>
>>>>> want to use.
>>>>> To use them in your ecore, set lower and upper bounds, so EMF will
>>>>> automatically select apropriate list for you.
>>>>>
>>>>> Hope this helps
>>>>>
>>>>> Paul Sentosa wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> In my ecore model, a class should have references to classes that are
>>>>>>
>>>> not
>>>>
>>>>>> (and shouldn't be) part of this model (or any other model) .These
>>>>>>
>>>> classes
>>>>
>>>>>> are actually kept in another plug-in project.
>>>>>> How can I reference them in my model? Until now I've only seen an
>>>>>>
>> .ecore
>>
>>>>>> file that refers to other .ecore-s, but not to classes.
>>>>>>
>>>>>> I tried to create classes which are named based on those external
>>>>>>
>>>> classes,
>>>>
>>>>>> and in their field "Instance Class Name" I put the qualified class
>>>>>>
>> name
>>
>>>> of
>>>>
>>>>>> the referred classes.
>>>>>> But then I see in the generated code, that those classes are
>>>>>>
>>>> IMPLEMENTed.
>>>>
>>>>>> (which is not correct, because they're classes). In case it was an
>>>>>>
>>>> external
>>>>
>>>>>> interface, it will be OK because a new interface, that extends the
>>>>>>
>>>> external
>>>>
>>>>>> interface is generated, and this will be implemented by the
>>>>>>
>>>> corresponding
>>>>
>>>>>> class. But what about classes?
>>>>>>
>>>>>> The same problem is also for any java libraries that are not yet
>>>>>>
>>>> implemented
>>>>
>>>>>> as .ecore data type (e.g ArrayList?). Will it be a good approach to
>>>>>>
>>>> create a
>>>>
>>>>>> data type that has its filed "Instance Class Name" referring to the
>>>>>>
>> java
>>
>>>>>> libraries? But than I would have the same problematic result in the
>>>>>> generated code.
>>>>>>
>>>>>> Thanks for any idea and suggestions.
>>>>>>
>>>>>> Regards
>>>>>> Paul
>>>>>>
>>>>>>
>>>>>>
>>>>
>>
>>
>>
>


--------------040201060805070605020509
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">
Paul,<br>
<br>
It it's an interface, you can define an EClass with that external
interface name set as the&nbsp; instanceClassName as well as isInterface and
isAbstract set to true.&nbsp; If it's literally a class and not an
interface, then you are out of luck unless you do some hand coding
since instances of EClasses must implement EObject/InternalEObject and
that' normally done by extending EObjectImpl or minimally by extending
BasicEObjectImpl.&nbsp; Since you can extend only one class, extending some
other class will force you to copy all of the logic in
BasicEObjectImpl/EObjectImpl into your derived class.<br>
<br>
<br>
Paul Sentosa wrote:
<blockquote cite="midf2sia1$5m4$1@build.eclipse.org" type="cite">
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<meta content="MSHTML 6.00.2800.1561" name="GENERATOR">
<style></style>
<div><font face="Arial" size="2">Hi,</font></div>
<div>&nbsp;</div>
<div><font face="Arial" size="2">thanks everyone for the answers and
sorry for this late reply.</font></div>
<div><font face="Arial" size="2">Yes, I was editing the model
arbitrarily and didn't notice one reference I made before. Sorry about
this.</font></div>
<div>&nbsp;</div>
<div><font face="Arial" size="2">Another question, and hope the last
one, regarding referring an external class. So far I used those classes
only as return type or parameter, so it wasn't problem at all defining
them as a datatype. Now, I just realize that </font><font face="Arial"
size="2">one of the classes in the model should EXTEND an external
class, which means, I can't define this referred external class&nbsp;using a
new&nbsp;data type. Instead, this class&nbsp;must somehow be recognized as an
EClass object (but it shouldn't part of any ecore model). Hope I've
described this clearly.</font></div>
<div><font face="Arial" size="2">Any suggestions how I can solve this
kind of problem?</font></div>
<div>&nbsp;</div>
<div><font face="Arial" size="2">Many thanks in advance</font></div>
<div><font face="Arial" size="2">Regards</font></div>
<div><font face="Arial" size="2">Paul</font></div>
<blockquote
style="border-left: 2px solid rgb(0, 0, 0); padding-right: 0px; padding-left: 5px; margin-left: 5px; margin-right: 0px;">
<div>"Ed Merks" &lt;<a href="mailto:merks@ca.ibm.com">merks@ca.ibm.com</a>&gt;
schrieb im Newsbeitrag <a href="news:f2kgep$lk4$1@build.eclipse.org">news:f2kgep$lk4$1@build.eclipse.org</a>...</div>
Paul,<br>
<br>
It's very clear that you have an EReference with an eType that's an
EDataType and the validation support should spot that (when, for
example, you right click and invoke "Validate" from the root package)
but I'm not sure it was complete in M4.&nbsp; I'd suggest using M7.&nbsp; Your
second problem sounds like a feature with no type at all.&nbsp; Again,
validation should report that.&nbsp;&nbsp; I can't imagine that it would be a
good idea to use ArrayList in your APIs.&nbsp; You're sure that a
multi-valued feature (upperBound set to -1) would not be more
appropriate?<br>
<br>
<br>
Paul Sentosa wrote:
<blockquote cite="midf2kenh$6e1$1@build.eclipse.org" type="cite">
<pre wrap="">Hi Marcelo,
thanks for your answer.
No, I haven't even used the ArrayList; I just defined it first to find out
how the generated code of it looks like, but I got those error report.
And here is also the problem:
In my generated code later, I'd like to have following line generated:

ArrayList children = new ArrayList();
RefererredClass rc;

So as you can see, both are references and not part of the model I defined.

Regarding NPE, yes, I used Eclipse 3.3M4 and its corresponding EMF version.

Any other idea?
Many thanks in advance!

Regards
Paul



"Marcelo Paternostro" <a class="moz-txt-link-rfc2396E"
href="mailto:marcelop@ca.ibm.com">&lt;marcelop@ca.ibm.com&gt;</a> schrieb im Newsbeitrag
<a class="moz-txt-link-freetext"
href="news:f2kbnt$an2$1@build.eclipse.org">news:f2kbnt$an2$1@build.eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Hi Paul,

DataTypes, like primitive types, can only be used as the type of
attributes. I believe the first error is happening because you've
defined the feature as a reference.

Regarding the NPE... Are you using EMF 2.3.0? In this version we are
providing a very complete EcoreValidation that would spot problems in
your Ecore model as soon as you open the GenModel editor. Even if you
are currently tied to an earlier version, I would recommend you to have
a separate Eclipse with 2.3.0 installed just to double check your
models. Believe me... It can save you lots of debugging/newsgroup time
</pre>
</blockquote>
<pre wrap=""><!---->;-)
</pre>
<blockquote type="cite">
<pre wrap="">Cheers,
Marcelo

Paul Sentosa wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Jacek,

thanks for your answer.


I tried to follow your suggestion: create a datatype called ArrayList,
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->set
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">its Instance Class Name to java.util.ArrayList.
But then when I tried to get the .genmodel file, I got the following
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->error
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">report:
java.lang.ClassCastException: org.eclipse.emf.ecore.impl.EDataTypeImpl
at

</pre>
</blockquote>
</blockquote>
<pre wrap=""><!----> org.eclipse.emf.ecore.impl.EReferenceImpl.getEReferenceType( EReferenceImpl.j
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">ava:268)
at
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!----> org.eclipse.emf.ecore.impl.EReferenceImpl.eGet(EReferenceImp l.java:358)
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap=""> at

</pre>
</blockquote>
</blockquote>
<pre wrap=""><!----> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:967)
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap=""> at

</pre>
</blockquote>
</blockquote>
<pre wrap=""><!----> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:959)
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">....
......
how can I get this correct?

And should this approach also work for external class -case I mentioned
before?
I created a DataType called OwnClass representing the class
own.package.OwnClass, a class kept in a certain external package..
Doing this, I could get the .genmodel file, but not the generated code,
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->due
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">to this error:
java.lang.NullPointerException
at

</pre>
</blockquote>
</blockquote>
<pre wrap=""><!----> org.eclipse.emf.codegen.ecore.genmodel.impl.GenTypedElementI mpl.getTypeGenPa
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">ckage(GenTypedElementImpl.java:80)
at

</pre>
</blockquote>
</blockquote>
<pre wrap=""><!----> org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl$D ependencyHelper.
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">&lt;init&gt;(GenPackageImpl.java:2050)
at

</pre>
</blockquote>
</blockquote>
<pre wrap=""><!----> org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl.p repareCache(GenP
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">ackageImpl.java:2777)
...........
...........

and also, one further question: in case I could make this work, how
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->should I
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">make a DataType as a reference in my class?

Thanks for further explanation

Regards
Paul

"Jacek Pospychala" <a class="moz-txt-link-rfc2396E"
href="mailto:jacek.pospychala@pl.ibm.com">&lt;jacek.pospychala@pl.ibm.com&gt;</a> schrieb im Newsbeitrag
<a class="moz-txt-link-freetext"
href="news:f2k25q$vtp$1@build.eclipse.org">news:f2k25q$vtp$1@build.eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Paul,

EDataType's are designed for this purpose. When you create EDataType
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->and
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">set it Instance Class name to e.g. ArrayList, only appropriate feature
id will be defined in package. If you mark it also serializable, then
generated factory implementation will additionally have convertToString
and createFromString methods.

EMF actually has already a versatile set of etypes implementing
java.util Collections interfaces, starting from BasicEList, that you
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->may
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">want to use.
To use them in your ecore, set lower and upper bounds, so EMF will
automatically select apropriate list for you.

Hope this helps

Paul Sentosa wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hi,

In my ecore model, a class should have references to classes that are
</pre>
</blockquote>
</blockquote>
<pre wrap="">not
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">(and shouldn't be) part of this model (or any other model) .These
</pre>
</blockquote>
</blockquote>
<pre wrap="">classes
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">are actually kept in another plug-in project.
How can I reference them in my model? Until now I've only seen an
</pre>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->.ecore
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">file that refers to other .ecore-s, but not to classes.

I tried to create classes which are named based on those external
</pre>
</blockquote>
</blockquote>
<pre wrap="">classes,
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">and in their field "Instance Class Name" I put the qualified class
</pre>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->name
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">of
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">the referred classes.
But then I see in the generated code, that those classes are
</pre>
</blockquote>
</blockquote>
<pre wrap="">IMPLEMENTed.
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">(which is not correct, because they're classes). In case it was an
</pre>
</blockquote>
</blockquote>
<pre wrap="">external
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">interface, it will be OK because a new interface, that extends the
</pre>
</blockquote>
</blockquote>
<pre wrap="">external
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">interface is generated, and this will be implemented by the
</pre>
</blockquote>
</blockquote>
<pre wrap="">corresponding
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">class. But what about classes?

The same problem is also for any java libraries that are not yet
</pre>
</blockquote>
</blockquote>
<pre wrap="">implemented
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">as .ecore data type (e.g ArrayList?). Will it be a good approach to
</pre>
</blockquote>
</blockquote>
<pre wrap="">create a
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">data type that has its filed "Instance Class Name" referring to the
</pre>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->java
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">libraries? But than I would have the same problematic result in the
generated code.

Thanks for any idea and suggestions.

Regards
Paul


</pre>
</blockquote>
</blockquote>
<pre wrap=""> </pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
<br>
</blockquote>
</blockquote>
<br>
</body>
</html>

--------------040201060805070605020509--
Re: How to use external classes in an ecore model [message #1772477 is a reply to message #409382] Mon, 11 September 2017 09:14 Go to previous messageGo to next message
Abdelrahman Fouda is currently offline Abdelrahman FoudaFriend
Messages: 1
Registered: September 2017
Junior Member
Hi all,

I have tried using an edatatype and initialize its instance class with the type I need to link to. However, when I tried to link to my class in a different model, it saves the tostring of the class like in the following example

<tasks description="" id="p1.tsk4" label="1" type="place" time="10">
<requiredCapabilityDescriptor>cod.gen.impl.CapabilityDescriptorImpl@78483404 (description: , id: cap2, label: ) (parent: null)</requiredCapabilityDescriptor>
<involvedResource>cod.gen.impl.ResourceDescriptorImpl@2839ac4c (description: null, id: null, label: null) (cad: null, material: null, pointySurface: &lt;unset>, sharpEdges: &lt;unset>, thumbnail: null, weight: &lt;unset>) (changeCost: null, generic: &lt;unset>, investCost: null, manufacturer: null)</involvedResource>
</tasks>

in this example I am linking to two different external classes CapabilityDescriptorImpl and ResourceDescriptorImpl. As you can see the tostring is stored which is inconvenient in terms of storage and readability, also I am not so sure about the consistency handling in such case (I mean deleting, editing of the referenced instance). According to the thread the tostring is written because I chose the data type to be serializable, I have tried making it non serializable, but that did not work .

So I have tried another approach using an eReference, which minimised the string to save to become

<tasks description="" id="p1.tsk4" label="1" type="place" time="10">
<requiredCapabilityDescriptor xsi:type="CoD:CapabilityDescriptor" description="" id="cap2" label=""/>
<involvedResource xsi:type="CoD:ResourceDescriptor"/>
</tasks>

which is much better in terms of readability and storage, but I really doubt it is an actual reference it does not contain any thing that can refer to the original instance. Actually, I am sure it is not referring to the original object as it does not show any econtainer. And again with the consistency issues.

My last option -that I can think of- is storing the URI of the referenced object but in this case I will have to manage all the consistency issues myself.

So my question is "is there a better way to achieve this external class referencing?"
Re: How to use external classes in an ecore model [message #1774287 is a reply to message #1772477] Thu, 12 October 2017 13:29 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 29655
Registered: July 2009
Senior Member
Sorry because of https://bugs.eclipse.org/bugs/show_bug.cgi?id=525901 I wasn't seeing posts. If you want to have a "reference" to some instance of some type of object that you haven't modeled, not only do you need an EDataType for it, but you need to implement the two methods in the XyzFactoryImpl to convert it to a string and to create an instance from a string, i.e., you need to provide the serialization logic for it. You'll see in EcoreFactoryImpl how it does that for all of Ecore's EDataTypes. You need to do something similar.
Previous Topic:EMF on eclipse Neon
Next Topic:EMF file URI#isPrefix()
Goto Forum:
  


Current Time: Tue Nov 20 12:31:24 GMT 2018

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

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

Back to the top