Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » instanceof for (dynamic) EObject
instanceof for (dynamic) EObject [message #504309] Fri, 18 December 2009 04:36 Go to next message
Andre Ribeiro is currently offline Andre RibeiroFriend
Messages: 58
Registered: July 2009
Member
Hi all,

short story:
I must find out if a given dynamic EObject (model instance) is an
instance of a known EClassifier (model) previously generated via the
classic "EMF Generator Model" wizard from an XSD.

The particularity here is that the model instance (EObject) may come
from a model which comes from an XSD file which imports another XSD
which has the ComplexType to which am i trying to test the instanceof
against.

Unsuccessful attempts so far are like these (where TextArea is my known
ComplexType and eRef is the reference to my dynamic EObject) :

#1
CommonPackage.eINSTANCE.getTextArea().isInstance(eRef.getERe ferenceType());

#2
CommonPackage.eINSTANCE.getTextArea().isSuperTypeOf(eRef.get EReferenceType());

#3
CommonPackage.eINSTANCE.getTextArea().isInstance(eRef);


long story:
I've got an RCP app which allows my users to load XSD files and creates
ECore models from them. The app then allows the users to create model
instances from these generated ECores.

I've got some "special" XSDs in which i know some ComplexTypes a-priori
and hence i would like my app to behave in special way if a given model
instance is derived from any of these "special" ComplexTypes.

The users may perfectly import my "special" XSD files into their XSDs
and then construct ComplexTypes of their own which "subclass" my
"special" ComplexTypes.

I must recognize this type hierarchy via the "instanceof" operation
which i am trying to develop, such that i can tell if a given model
instance subclasses one of my "special" ComplexTypes.

much thanks & kind regards,
ARibeiro
Re: instanceof for (dynamic) EObject [message #504321 is a reply to message #504309] Fri, 18 December 2009 10:22 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
ARibeiro,

Comments below.

flai wrote:
> Hi all,
>
> short story:
> I must find out if a given dynamic EObject (model instance) is an
> instance of a known EClassifier (model) previously generated via the
> classic "EMF Generator Model" wizard from an XSD.
That sounds like a contradiction....
>
> The particularity here is that the model instance (EObject) may come
> from a model which comes from an XSD file which imports another XSD
> which has the ComplexType to which am i trying to test the instanceof
> against.
>
> Unsuccessful attempts so far are like these (where TextArea is my
> known ComplexType and eRef is the reference to my dynamic EObject) :
>
> #1
> CommonPackage.eINSTANCE.getTextArea().isInstance(eRef.getERe ferenceType());
>
Here you're at the wrong meta level.
>
> #2
> CommonPackage.eINSTANCE.getTextArea().isSuperTypeOf(eRef.get EReferenceType());
>
This would work, but if you literally have a dynamic copy of
CommonPackage, they simply aren't related in this way.
>
> #3
> CommonPackage.eINSTANCE.getTextArea().isInstance(eRef);
Here too you're at the wrong meta level.

In no case will a dynamic instance ever be an instance of a generated
classifier.
>
>
> long story:
> I've got an RCP app which allows my users to load XSD files and
> creates ECore models from them. The app then allows the users to
> create model instances from these generated ECores.
>
> I've got some "special" XSDs in which i know some ComplexTypes
> a-priori and hence i would like my app to behave in special way if a
> given model instance is derived from any of these "special" ComplexTypes.
You'd have to make sure that the XSDEcoreBuilder uses those special
generated Ecore instances rather than creating new dynamic versions of them.
>
> The users may perfectly import my "special" XSD files into their XSDs
> and then construct ComplexTypes of their own which "subclass" my
> "special" ComplexTypes.
>
> I must recognize this type hierarchy via the "instanceof" operation
> which i am trying to develop, such that i can tell if a given model
> instance subclasses one of my "special" ComplexTypes.
They won't ever be instances of your generated type unless you ensure
the Ecore model being used is really the generated one and not a dynamic
copy of it.
>
> much thanks & kind regards,
> ARibeiro


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: instanceof for (dynamic) EObject [message #504329 is a reply to message #504321] Fri, 18 December 2009 10:48 Go to previous messageGo to next message
Andre Ribeiro is currently offline Andre RibeiroFriend
Messages: 58
Registered: July 2009
Member
Hi Ed,

(as always, lots of thanks in advance)

comments inline.

On 18-12-2009 10:22, Ed Merks wrote:
> ARibeiro,
>
> Comments below.
>
> flai wrote:
>> Hi all,
>>
>> short story:
>> I must find out if a given dynamic EObject (model instance) is an
>> instance of a known EClassifier (model) previously generated via the
>> classic "EMF Generator Model" wizard from an XSD.
> That sounds like a contradiction....
>>
>> The particularity here is that the model instance (EObject) may come
>> from a model which comes from an XSD file which imports another XSD
>> which has the ComplexType to which am i trying to test the instanceof
>> against.
>>
>> Unsuccessful attempts so far are like these (where TextArea is my
>> known ComplexType and eRef is the reference to my dynamic EObject) :
>>
>> #1
>> CommonPackage.eINSTANCE.getTextArea().isInstance(eRef.getERe ferenceType());
>>
> Here you're at the wrong meta level.
>>
>> #2
>> CommonPackage.eINSTANCE.getTextArea().isSuperTypeOf(eRef.get EReferenceType());
>>
> This would work, but if you literally have a dynamic copy of
> CommonPackage, they simply aren't related in this way.
>>
>> #3
>> CommonPackage.eINSTANCE.getTextArea().isInstance(eRef);
> Here too you're at the wrong meta level.
>
> In no case will a dynamic instance ever be an instance of a generated
> classifier.
>>
>>
>> long story:
>> I've got an RCP app which allows my users to load XSD files and
>> creates ECore models from them. The app then allows the users to
>> create model instances from these generated ECores.
>>
>> I've got some "special" XSDs in which i know some ComplexTypes
>> a-priori and hence i would like my app to behave in special way if a
>> given model instance is derived from any of these "special" ComplexTypes.
> You'd have to make sure that the XSDEcoreBuilder uses those special
> generated Ecore instances rather than creating new dynamic versions of
> them.
How could I do this?
(I've got here your EMF book if you think there's a good example of this
case in it)
>>
>> The users may perfectly import my "special" XSD files into their XSDs
>> and then construct ComplexTypes of their own which "subclass" my
>> "special" ComplexTypes.
>>
>> I must recognize this type hierarchy via the "instanceof" operation
>> which i am trying to develop, such that i can tell if a given model
>> instance subclasses one of my "special" ComplexTypes.
> They won't ever be instances of your generated type unless you ensure
> the Ecore model being used is really the generated one and not a dynamic
> copy of it.
How could i tell the generator to use my previously generated instance
instead of the dynamic one?

I though that having the same namespace in the schema would do this.
>>
>> much thanks & kind regards,
>> ARibeiro
Re: instanceof for (dynamic) EObject [message #504336 is a reply to message #504329] Fri, 18 December 2009 11:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
André,

If you look at XSDEcoreBuilder's getEPackage method you'll see how it
creates a new package if it doesn't find an existing package in
targetNamespaceToEPackageMap so you'd need to populate that map with
existing package instances.


André Ribeiro wrote:
> Hi Ed,
>
> (as always, lots of thanks in advance)
>
> comments inline.
>
> On 18-12-2009 10:22, Ed Merks wrote:
>> ARibeiro,
>>
>> Comments below.
>>
>> flai wrote:
>>> Hi all,
>>>
>>> short story:
>>> I must find out if a given dynamic EObject (model instance) is an
>>> instance of a known EClassifier (model) previously generated via the
>>> classic "EMF Generator Model" wizard from an XSD.
>> That sounds like a contradiction....
>>>
>>> The particularity here is that the model instance (EObject) may come
>>> from a model which comes from an XSD file which imports another XSD
>>> which has the ComplexType to which am i trying to test the instanceof
>>> against.
>>>
>>> Unsuccessful attempts so far are like these (where TextArea is my
>>> known ComplexType and eRef is the reference to my dynamic EObject) :
>>>
>>> #1
>>> CommonPackage.eINSTANCE.getTextArea().isInstance(eRef.getERe ferenceType());
>>>
>>>
>> Here you're at the wrong meta level.
>>>
>>> #2
>>> CommonPackage.eINSTANCE.getTextArea().isSuperTypeOf(eRef.get EReferenceType());
>>>
>>>
>> This would work, but if you literally have a dynamic copy of
>> CommonPackage, they simply aren't related in this way.
>>>
>>> #3
>>> CommonPackage.eINSTANCE.getTextArea().isInstance(eRef);
>> Here too you're at the wrong meta level.
>>
>> In no case will a dynamic instance ever be an instance of a generated
>> classifier.
>>>
>>>
>>> long story:
>>> I've got an RCP app which allows my users to load XSD files and
>>> creates ECore models from them. The app then allows the users to
>>> create model instances from these generated ECores.
>>>
>>> I've got some "special" XSDs in which i know some ComplexTypes
>>> a-priori and hence i would like my app to behave in special way if a
>>> given model instance is derived from any of these "special"
>>> ComplexTypes.
>> You'd have to make sure that the XSDEcoreBuilder uses those special
>> generated Ecore instances rather than creating new dynamic versions of
>> them.
> How could I do this?
> (I've got here your EMF book if you think there's a good example of
> this case in it)
>>>
>>> The users may perfectly import my "special" XSD files into their XSDs
>>> and then construct ComplexTypes of their own which "subclass" my
>>> "special" ComplexTypes.
>>>
>>> I must recognize this type hierarchy via the "instanceof" operation
>>> which i am trying to develop, such that i can tell if a given model
>>> instance subclasses one of my "special" ComplexTypes.
>> They won't ever be instances of your generated type unless you ensure
>> the Ecore model being used is really the generated one and not a dynamic
>> copy of it.
> How could i tell the generator to use my previously generated instance
> instead of the dynamic one?
>
> I though that having the same namespace in the schema would do this.
>>>
>>> much thanks & kind regards,
>>> ARibeiro
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: instanceof for (dynamic) EObject [message #504572 is a reply to message #504336] Mon, 21 December 2009 14:56 Go to previous messageGo to next message
Andre Ribeiro is currently offline Andre RibeiroFriend
Messages: 58
Registered: July 2009
Member
Hi again Ed,

I've implemented your suggestion, but i still fail to understand why my
CommonPackage is creating *new EClasses* when i invoke the lines:

CommonPackage.eINSTANCE.getCheckList();
CommonPackage.eINSTANCE.getTextArea();

if i do
System.out.println(CommonPackage.eINSTANCE.getCheckList());

i get smth like:
org.eclipse.emf.ecore.impl.EClassImpl@40993028 (name: CheckList11)
(instanceClassName: null) (abstract: false, interface: false)

NOTE: the 11 after the name

(full source in
http://code.google.com/p/emf-generic-editor/source/browse/tr unk/com.rd.genericeditor/src/com/rd/emf/geneditor/view/edito rs/generic/binding/EmfSwtBindingFactory.java?r=6#148)

the *CommonPackage* should be already registered and should return
instances of my generated object, right? i really dont get it this time?!

thanks a lot,
André

On 18-12-2009 11:33, Ed Merks wrote:
> André,
>
> If you look at XSDEcoreBuilder's getEPackage method you'll see how it
> creates a new package if it doesn't find an existing package in
> targetNamespaceToEPackageMap so you'd need to populate that map with
> existing package instances.
>
>
> André Ribeiro wrote:
>> Hi Ed,
>>
>> (as always, lots of thanks in advance)
>>
>> comments inline.
>>
>> On 18-12-2009 10:22, Ed Merks wrote:
>>> ARibeiro,
>>>
>>> Comments below.
>>>
>>> flai wrote:
>>>> Hi all,
>>>>
>>>> short story:
>>>> I must find out if a given dynamic EObject (model instance) is an
>>>> instance of a known EClassifier (model) previously generated via the
>>>> classic "EMF Generator Model" wizard from an XSD.
>>> That sounds like a contradiction....
>>>>
>>>> The particularity here is that the model instance (EObject) may come
>>>> from a model which comes from an XSD file which imports another XSD
>>>> which has the ComplexType to which am i trying to test the instanceof
>>>> against.
>>>>
>>>> Unsuccessful attempts so far are like these (where TextArea is my
>>>> known ComplexType and eRef is the reference to my dynamic EObject) :
>>>>
>>>> #1
>>>> CommonPackage.eINSTANCE.getTextArea().isInstance(eRef.getERe ferenceType());
>>>>
>>>>
>>> Here you're at the wrong meta level.
>>>>
>>>> #2
>>>> CommonPackage.eINSTANCE.getTextArea().isSuperTypeOf(eRef.get EReferenceType());
>>>>
>>>>
>>> This would work, but if you literally have a dynamic copy of
>>> CommonPackage, they simply aren't related in this way.
>>>>
>>>> #3
>>>> CommonPackage.eINSTANCE.getTextArea().isInstance(eRef);
>>> Here too you're at the wrong meta level.
>>>
>>> In no case will a dynamic instance ever be an instance of a generated
>>> classifier.
>>>>
>>>>
>>>> long story:
>>>> I've got an RCP app which allows my users to load XSD files and
>>>> creates ECore models from them. The app then allows the users to
>>>> create model instances from these generated ECores.
>>>>
>>>> I've got some "special" XSDs in which i know some ComplexTypes
>>>> a-priori and hence i would like my app to behave in special way if a
>>>> given model instance is derived from any of these "special"
>>>> ComplexTypes.
>>> You'd have to make sure that the XSDEcoreBuilder uses those special
>>> generated Ecore instances rather than creating new dynamic versions of
>>> them.
>> How could I do this?
>> (I've got here your EMF book if you think there's a good example of
>> this case in it)
>>>>
>>>> The users may perfectly import my "special" XSD files into their XSDs
>>>> and then construct ComplexTypes of their own which "subclass" my
>>>> "special" ComplexTypes.
>>>>
>>>> I must recognize this type hierarchy via the "instanceof" operation
>>>> which i am trying to develop, such that i can tell if a given model
>>>> instance subclasses one of my "special" ComplexTypes.
>>> They won't ever be instances of your generated type unless you ensure
>>> the Ecore model being used is really the generated one and not a dynamic
>>> copy of it.
>> How could i tell the generator to use my previously generated instance
>> instead of the dynamic one?
>>
>> I though that having the same namespace in the schema would do this.
>>>>
>>>> much thanks & kind regards,
>>>> ARibeiro
>>
Re: instanceof for (dynamic) EObject [message #504608 is a reply to message #504572] Mon, 21 December 2009 13:26 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
André,

Set a breakpoint in the constructor for EPackage or where the nsURI is
set and what how the XSDEcoreBuilder gets to that point and creates a
clone of the model (and all the other places that get you there...


André Ribeiro wrote:
> Hi again Ed,
>
> I've implemented your suggestion, but i still fail to understand why
> my CommonPackage is creating *new EClasses* when i invoke the lines:
>
> CommonPackage.eINSTANCE.getCheckList();
> CommonPackage.eINSTANCE.getTextArea();
>
> if i do
> System.out.println(CommonPackage.eINSTANCE.getCheckList());
>
> i get smth like:
> org.eclipse.emf.ecore.impl.EClassImpl@40993028 (name: CheckList11)
> (instanceClassName: null) (abstract: false, interface: false)
>
> NOTE: the 11 after the name
>
> (full source in
> http://code.google.com/p/emf-generic-editor/source/browse/tr unk/com.rd.genericeditor/src/com/rd/emf/geneditor/view/edito rs/generic/binding/EmfSwtBindingFactory.java?r=6#148)
>
>
> the *CommonPackage* should be already registered and should return
> instances of my generated object, right? i really dont get it this time?!
I don't actually get the question. The CommonPackage's structure is
created when eINSTANCE is first access...
>
> thanks a lot,
> André
>
> On 18-12-2009 11:33, Ed Merks wrote:
>> André,
>>
>> If you look at XSDEcoreBuilder's getEPackage method you'll see how it
>> creates a new package if it doesn't find an existing package in
>> targetNamespaceToEPackageMap so you'd need to populate that map with
>> existing package instances.
>>
>>
>> André Ribeiro wrote:
>>> Hi Ed,
>>>
>>> (as always, lots of thanks in advance)
>>>
>>> comments inline.
>>>
>>> On 18-12-2009 10:22, Ed Merks wrote:
>>>> ARibeiro,
>>>>
>>>> Comments below.
>>>>
>>>> flai wrote:
>>>>> Hi all,
>>>>>
>>>>> short story:
>>>>> I must find out if a given dynamic EObject (model instance) is an
>>>>> instance of a known EClassifier (model) previously generated via the
>>>>> classic "EMF Generator Model" wizard from an XSD.
>>>> That sounds like a contradiction....
>>>>>
>>>>> The particularity here is that the model instance (EObject) may come
>>>>> from a model which comes from an XSD file which imports another XSD
>>>>> which has the ComplexType to which am i trying to test the instanceof
>>>>> against.
>>>>>
>>>>> Unsuccessful attempts so far are like these (where TextArea is my
>>>>> known ComplexType and eRef is the reference to my dynamic EObject) :
>>>>>
>>>>> #1
>>>>> CommonPackage.eINSTANCE.getTextArea().isInstance(eRef.getERe ferenceType());
>>>>>
>>>>>
>>>>>
>>>> Here you're at the wrong meta level.
>>>>>
>>>>> #2
>>>>> CommonPackage.eINSTANCE.getTextArea().isSuperTypeOf(eRef.get EReferenceType());
>>>>>
>>>>>
>>>>>
>>>> This would work, but if you literally have a dynamic copy of
>>>> CommonPackage, they simply aren't related in this way.
>>>>>
>>>>> #3
>>>>> CommonPackage.eINSTANCE.getTextArea().isInstance(eRef);
>>>> Here too you're at the wrong meta level.
>>>>
>>>> In no case will a dynamic instance ever be an instance of a generated
>>>> classifier.
>>>>>
>>>>>
>>>>> long story:
>>>>> I've got an RCP app which allows my users to load XSD files and
>>>>> creates ECore models from them. The app then allows the users to
>>>>> create model instances from these generated ECores.
>>>>>
>>>>> I've got some "special" XSDs in which i know some ComplexTypes
>>>>> a-priori and hence i would like my app to behave in special way if a
>>>>> given model instance is derived from any of these "special"
>>>>> ComplexTypes.
>>>> You'd have to make sure that the XSDEcoreBuilder uses those special
>>>> generated Ecore instances rather than creating new dynamic versions of
>>>> them.
>>> How could I do this?
>>> (I've got here your EMF book if you think there's a good example of
>>> this case in it)
>>>>>
>>>>> The users may perfectly import my "special" XSD files into their XSDs
>>>>> and then construct ComplexTypes of their own which "subclass" my
>>>>> "special" ComplexTypes.
>>>>>
>>>>> I must recognize this type hierarchy via the "instanceof" operation
>>>>> which i am trying to develop, such that i can tell if a given model
>>>>> instance subclasses one of my "special" ComplexTypes.
>>>> They won't ever be instances of your generated type unless you ensure
>>>> the Ecore model being used is really the generated one and not a
>>>> dynamic
>>>> copy of it.
>>> How could i tell the generator to use my previously generated instance
>>> instead of the dynamic one?
>>>
>>> I though that having the same namespace in the schema would do this.
>>>>>
>>>>> much thanks & kind regards,
>>>>> ARibeiro
>>>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: instanceof for (dynamic) EObject [message #507548 is a reply to message #504608] Wed, 13 January 2010 19:29 Go to previous messageGo to next message
Andre Ribeiro is currently offline Andre RibeiroFriend
Messages: 58
Registered: July 2009
Member
Hi again,

Perhaps you may shed a bit more of light over this problem ...

I've got the XSDEcoreBuilder running with options
xsdECoreBuilderOptions.put(XSDEcoreBuilder.OPTION_REUSE_REGI STERED_PACKAGES,
Boolean.TRUE);
and
xsdEcoreBuilder.getTargetNamespaceToEPackageMap().put(MyPack age.eNS_URI,
MyPackage.eINSTANCE);

but i am getting to the conclusion that XSDEcoreBuilder creates new
EClasses (of form ComplexType1, ComplexType11, ComplexType111, etc ..)
in XSDEcoreBuilder.resolveNameConflicts() due to the fact that it
already has (previously statically generated) EClassifiers with same
name in MyPackage.

Although i wanted it to use my existing EClassifiers in MyPackage, but
somehow it fails to do so ... do you have any idea why that might be
happening?

Much thanks in advance,
André

On 21-12-2009 18:14, Ed Merks wrote:
> André,
>
> Set a breakpoint in the constructor for EPackage or where the nsURI is
> set and what how the XSDEcoreBuilder gets to that point and creates a
> clone of the model (and all the other places that get you there...
>
>
> André Ribeiro wrote:
>> Hi again Ed,
>>
>> I've implemented your suggestion, but i still fail to understand why
>> my CommonPackage is creating *new EClasses* when i invoke the lines:
>>
>> CommonPackage.eINSTANCE.getCheckList();
>> CommonPackage.eINSTANCE.getTextArea();
>>
>> if i do
>> System.out.println(CommonPackage.eINSTANCE.getCheckList());
>>
>> i get smth like:
>> org.eclipse.emf.ecore.impl.EClassImpl@40993028 (name: CheckList11)
>> (instanceClassName: null) (abstract: false, interface: false)
>>
>> NOTE: the 11 after the name
>>
>> (full source in
>> http://code.google.com/p/emf-generic-editor/source/browse/tr unk/com.rd.genericeditor/src/com/rd/emf/geneditor/view/edito rs/generic/binding/EmfSwtBindingFactory.java?r=6#148)
>>
>>
>> the *CommonPackage* should be already registered and should return
>> instances of my generated object, right? i really dont get it this
>> time?!
> I don't actually get the question. The CommonPackage's structure is
> created when eINSTANCE is first access...
>>
>> thanks a lot,
>> André
>>
>> On 18-12-2009 11:33, Ed Merks wrote:
>>> André,
>>>
>>> If you look at XSDEcoreBuilder's getEPackage method you'll see how it
>>> creates a new package if it doesn't find an existing package in
>>> targetNamespaceToEPackageMap so you'd need to populate that map with
>>> existing package instances.
>>>
>>>
>>> André Ribeiro wrote:
>>>> Hi Ed,
>>>>
>>>> (as always, lots of thanks in advance)
>>>>
>>>> comments inline.
>>>>
>>>> On 18-12-2009 10:22, Ed Merks wrote:
>>>>> ARibeiro,
>>>>>
>>>>> Comments below.
>>>>>
>>>>> flai wrote:
>>>>>> Hi all,
>>>>>>
>>>>>> short story:
>>>>>> I must find out if a given dynamic EObject (model instance) is an
>>>>>> instance of a known EClassifier (model) previously generated via the
>>>>>> classic "EMF Generator Model" wizard from an XSD.
>>>>> That sounds like a contradiction....
>>>>>>
>>>>>> The particularity here is that the model instance (EObject) may come
>>>>>> from a model which comes from an XSD file which imports another XSD
>>>>>> which has the ComplexType to which am i trying to test the
>>>>>> instanceof
>>>>>> against.
>>>>>>
>>>>>> Unsuccessful attempts so far are like these (where TextArea is my
>>>>>> known ComplexType and eRef is the reference to my dynamic EObject) :
>>>>>>
>>>>>> #1
>>>>>> CommonPackage.eINSTANCE.getTextArea().isInstance(eRef.getERe ferenceType());
>>>>>>
>>>>>>
>>>>>>
>>>>> Here you're at the wrong meta level.
>>>>>>
>>>>>> #2
>>>>>> CommonPackage.eINSTANCE.getTextArea().isSuperTypeOf(eRef.get EReferenceType());
>>>>>>
>>>>>>
>>>>>>
>>>>> This would work, but if you literally have a dynamic copy of
>>>>> CommonPackage, they simply aren't related in this way.
>>>>>>
>>>>>> #3
>>>>>> CommonPackage.eINSTANCE.getTextArea().isInstance(eRef);
>>>>> Here too you're at the wrong meta level.
>>>>>
>>>>> In no case will a dynamic instance ever be an instance of a generated
>>>>> classifier.
>>>>>>
>>>>>>
>>>>>> long story:
>>>>>> I've got an RCP app which allows my users to load XSD files and
>>>>>> creates ECore models from them. The app then allows the users to
>>>>>> create model instances from these generated ECores.
>>>>>>
>>>>>> I've got some "special" XSDs in which i know some ComplexTypes
>>>>>> a-priori and hence i would like my app to behave in special way if a
>>>>>> given model instance is derived from any of these "special"
>>>>>> ComplexTypes.
>>>>> You'd have to make sure that the XSDEcoreBuilder uses those special
>>>>> generated Ecore instances rather than creating new dynamic
>>>>> versions of
>>>>> them.
>>>> How could I do this?
>>>> (I've got here your EMF book if you think there's a good example of
>>>> this case in it)
>>>>>>
>>>>>> The users may perfectly import my "special" XSD files into their
>>>>>> XSDs
>>>>>> and then construct ComplexTypes of their own which "subclass" my
>>>>>> "special" ComplexTypes.
>>>>>>
>>>>>> I must recognize this type hierarchy via the "instanceof" operation
>>>>>> which i am trying to develop, such that i can tell if a given model
>>>>>> instance subclasses one of my "special" ComplexTypes.
>>>>> They won't ever be instances of your generated type unless you ensure
>>>>> the Ecore model being used is really the generated one and not a
>>>>> dynamic
>>>>> copy of it.
>>>> How could i tell the generator to use my previously generated instance
>>>> instead of the dynamic one?
>>>>
>>>> I though that having the same namespace in the schema would do this.
>>>>>>
>>>>>> much thanks & kind regards,
>>>>>> ARibeiro
>>>>
>>
Re: instanceof for (dynamic) EObject [message #507562 is a reply to message #507548] Wed, 13 January 2010 20:31 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------040902070004020605050403
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Andr


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: instanceof for (dynamic) EObject [message #507814 is a reply to message #507562] Thu, 14 January 2010 18:24 Go to previous messageGo to next message
Andre Ribeiro is currently offline Andre RibeiroFriend
Messages: 58
Registered: July 2009
Member
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Ed Almighty!<br>
<br>
By analyzing the code that you suggested I found my 2 problems:<br>
1) I was building the options map, but i was not passing it to the
XSDEcoreBuilder (shame on me!)<br>
2) I was passing new BasicExtendedMetaData(new EPackageRegistryImpl())
to the XSDECoreBuilder constructor cause i copied it from the
XSDEcoreBuilder() (no-args constructor), instead of
EPackage.Registry.INSTANCE<br>
<br>
Now I moved on to a new challenge, which is to build an ecore model
from this XSD<br>
<a class="moz-txt-link-freetext" href="http://docs.oasis-open.org/emergency/cap/v1.2/CAP-v1.2.xsd">http://docs.oasis-open.org/emergency/cap/v1.2/CAP-v1.2.xsd</a> (OASIS
Common Alerting Protocol)<br>
which i sadly acknowledge is not possible ... probably due to the way
the way the schema is designed, i'll devote some time to understand why<br>
<br>
Thanks a lot for the help,<br>
Andr&eacute;<br>
<br>
PS in your next visit to Portugal, drinks are on me ;)<br>
<br>
On 13-01-2010 20:31, Ed Merks wrote:
<blockquote cite="mid:hilai6$7k6$1@build.eclipse.org" type="cite">
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
Andr&eacute;,<br>
<br>
Comments below.<br>
<br>
Andr&eacute; Ribeiro wrote:
<blockquote cite="mid:hil6vn$sbv$1@build.eclipse.org" type="cite">Hi
again, <br>
<br>
Perhaps you may shed a bit more of light over this problem ... <br>
<br>
I've got the XSDEcoreBuilder running with options <br>
xsdECoreBuilderOptions.put(XSDEcoreBuilder.OPTION_REUSE_REGI STERED_PACKAGES,
Boolean.TRUE);

<br>
and <br>
xsdEcoreBuilder.getTargetNamespaceToEPackageMap().put(MyPack age.eNS_URI,
MyPackage.eINSTANCE);

<br>
<br>
but i am getting to the conclusion that XSDEcoreBuilder creates new
EClasses (of form ComplexType1, ComplexType11, ComplexType111, etc ..)
in XSDEcoreBuilder.resolveNameConflicts() due to the fact that it
already has (previously statically generated) EClassifiers with same
name in MyPackage. <br>
</blockquote>
So it must be doing that here in computeEClass<br>
<blockquote><small>&nbsp;&nbsp;&nbsp; else if (reuseRegisteredPackages)</small><br>
<small>&nbsp;&nbsp;&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EClass eClass =
(EClass)extendedMetaData.getType(xsdComplexTypeDefinition.ge tTargetNamespace(),
xsdComplexTypeDefinition.getName());</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (eClass != null)</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; return eClass;</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</small><br>
<small>&nbsp;&nbsp;&nbsp; }</small><br>
<br>
<small>&nbsp;&nbsp;&nbsp; EClass eClass = EcoreFactory.eINSTANCE.createEClass();
&lt;&lt;&lt;&lt;&lt;&lt;</small><br >
<small>&nbsp;&nbsp;&nbsp; setAnnotations(eClass, xsdComplexTypeDefinition);</small><br>
</blockquote>
So that means the type isn't found in the extended metadata, which
leads me to wonder which XSDEcoreBuilder constructor you used.<br>
<blockquote cite="mid:hil6vn$sbv$1@build.eclipse.org" type="cite"><br>
Although i wanted it to use my existing EClassifiers in MyPackage, but
somehow it fails to do so ... do you have any idea why that might be
happening? <br>
</blockquote>
I expect you want to use new BasicExtendedMetaData(new
EPackageRegistryImpl(EPackage.Registry.INSTANCE))&nbsp; or even
ExtendedMetaData.INSTANCE in the constructor, but the latter will
update the global shared registry with the results of your builders, so
not something you'd want to do when running inside of an Eclipse
application that might be hosting other EMF clients).<br>
<blockquote cite="mid:hil6vn$sbv$1@build.eclipse.org" type="cite"><br>
Much thanks in advance, <br>
Andr&eacute; <br>
<br>
On 21-12-2009 18:14, Ed Merks wrote: <br>
<blockquote type="cite">Andr&eacute;, <br>
<br>
Set a breakpoint in the constructor for EPackage or where the nsURI is
set and what how the XSDEcoreBuilder gets to that point and creates a
clone of the model (and all the other places that get you there... <br>
<br>
<br>
Andr&eacute; Ribeiro wrote: <br>
<blockquote type="cite">Hi again Ed, <br>
<br>
I've implemented your suggestion, but i still fail to understand why my
CommonPackage is creating *new EClasses* when i invoke the lines: <br>
<br>
CommonPackage.eINSTANCE.getCheckList(); <br>
CommonPackage.eINSTANCE.getTextArea(); <br>
<br>
if i do <br>
System.out.println(CommonPackage.eINSTANCE.getCheckList()); <br>
<br>
i get smth like: <br>
org.eclipse.emf.ecore.impl.EClassImpl@40993028 (name: CheckList11)
(instanceClassName: null) (abstract: false, interface: false) <br>
<br>
NOTE: the 11 after the name <br>
<br>
(full source in
<a moz-do-not-send="true" class="moz-txt-link-freetext"
href=" http://code.google.com/p/emf-generic-editor/source/browse/tr unk/com.rd.genericeditor/src/com/rd/emf/geneditor/view/edito rs/generic/binding/EmfSwtBindingFactory.java?r=6#148"> http://code.google.com/p/emf-generic-editor/source/browse/tr unk/com.rd.genericeditor/src/com/rd/emf/geneditor/view/edito rs/generic/binding/EmfSwtBindingFactory.java?r=6#148</a>)

<br>
<br>
the *CommonPackage* should be already registered and should return
instances of my generated object, right? i really dont get it this
time?! <br>
</blockquote>
I don't actually get the question.&nbsp; The CommonPackage's structure is
created when eINSTANCE is first access... <br>
<blockquote type="cite"><br>
thanks a lot, <br>
Andr&eacute; <br>
<br>
On 18-12-2009 11:33, Ed Merks wrote: <br>
<blockquote type="cite">Andr&eacute;, <br>
<br>
If you look at XSDEcoreBuilder's getEPackage method you'll see how it <br>
creates a new package if it doesn't find an existing package in <br>
targetNamespaceToEPackageMap so you'd need to populate that map with <br>
existing package instances. <br>
<br>
<br>
Andr&eacute; Ribeiro wrote: <br>
<blockquote type="cite">Hi Ed, <br>
<br>
(as always, lots of thanks in advance) <br>
<br>
comments inline. <br>
<br>
On 18-12-2009 10:22, Ed Merks wrote: <br>
<blockquote type="cite">ARibeiro, <br>
<br>
Comments below. <br>
<br>
flai wrote: <br>
<blockquote type="cite">Hi all, <br>
<br>
short story: <br>
I must find out if a given dynamic EObject (model instance) is an <br>
instance of a known EClassifier (model) previously generated via the <br>
classic "EMF Generator Model" wizard from an XSD. <br>
</blockquote>
That sounds like a contradiction.... <br>
<blockquote type="cite"><br>
The particularity here is that the model instance (EObject) may come <br>
from a model which comes from an XSD file which imports another XSD <br>
which has the ComplexType to which am i trying to test the instanceof <br>
against. <br>
<br>
Unsuccessful attempts so far are like these (where TextArea is my <br>
known ComplexType and eRef is the reference to my dynamic EObject) : <br>
<br>
#1 <br>
CommonPackage.eINSTANCE.getTextArea().isInstance(eRef.getERe ferenceType());

<br>
<br>
<br>
</blockquote>
Here you're at the wrong meta level. <br>
<blockquote type="cite"><br>
#2 <br>
CommonPackage.eINSTANCE.getTextArea().isSuperTypeOf(eRef.get EReferenceType());

<br>
<br>
<br>
</blockquote>
This would work, but if you literally have a dynamic copy of <br>
CommonPackage, they simply aren't related in this way. <br>
<blockquote type="cite"><br>
#3 <br>
CommonPackage.eINSTANCE.getTextArea().isInstance(eRef); <br>
</blockquote>
Here too you're at the wrong meta level. <br>
<br>
In no case will a dynamic instance ever be an instance of a generated <br>
classifier. <br>
<blockquote type="cite"><br>
<br>
long story: <br>
I've got an RCP app which allows my users to load XSD files and <br>
creates ECore models from them. The app then allows the users to <br>
create model instances from these generated ECores. <br>
<br>
I've got some "special" XSDs in which i know some ComplexTypes <br>
a-priori and hence i would like my app to behave in special way if a <br>
given model instance is derived from any of these "special" <br>
ComplexTypes. <br>
</blockquote>
You'd have to make sure that the XSDEcoreBuilder uses those special <br>
generated Ecore instances rather than creating new dynamic versions of <br>
them. <br>
</blockquote>
How could I do this? <br>
(I've got here your EMF book if you think there's a good example of <br>
this case in it) <br>
<blockquote type="cite">
<blockquote type="cite"><br>
The users may perfectly import my "special" XSD files into their XSDs <br>
and then construct ComplexTypes of their own which "subclass" my <br>
"special" ComplexTypes. <br>
<br>
I must recognize this type hierarchy via the "instanceof" operation <br>
which i am trying to develop, such that i can tell if a given model <br>
instance subclasses one of my "special" ComplexTypes. <br>
</blockquote>
They won't ever be instances of your generated type unless you ensure <br>
the Ecore model being used is really the generated one and not a
dynamic <br>
copy of it. <br>
</blockquote>
How could i tell the generator to use my previously generated instance <br>
instead of the dynamic one? <br>
<br>
I though that having the same namespace in the schema would do this. <br>
<blockquote type="cite">
<blockquote type="cite"><br>
much thanks &amp; kind regards, <br>
ARibeiro <br>
</blockquote>
</blockquote>
<br>
</blockquote>
</blockquote>
<br>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</body>
</html>
Re: instanceof for (dynamic) EObject [message #507894 is a reply to message #507814] Fri, 15 January 2010 01:22 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------000308030407010208030708
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Andr


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Re: [emf-dev] exposing Ecore models via web services
Next Topic:Re: JMerger Example and Standalone Use
Goto Forum:
  


Current Time: Sat Apr 20 05:12:31 GMT 2024

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

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

Back to the top