Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » AdapterFactories
AdapterFactories [message #418700] Thu, 24 April 2008 14:56 Go to next message
Giulio Seregni is currently offline Giulio SeregniFriend
Messages: 21
Registered: July 2009
Junior Member
Hi,
I have this problem usign adaperter factories:
In my model i have 3 classes, A, B and AB. AB has supertipes A and B in
this order.

I have and adapter factory that works with B objects.

When i try to adapt AB using this factory i get a null pointer exception
because the "switch" class used by adapter factory consider only the first
ESupertipe( in this case A)

Here the auto-generated code...

protected T doSwitch(EClass theEClass, EObject theEObject) {
if (theEClass.eContainer() == modelPackage) {
return doSwitch(theEClass.getClassifierID(), theEObject);
}
else {
List<EClass> eSuperTypes = theEClass.getESuperTypes();
return
eSuperTypes.isEmpty() ?
defaultCase(theEObject) :
doSwitch(eSuperTypes.get(0), theEObject);
}
}

Notice the eSuperTypes.get(0).

Now, can i change the implementation of doSwitch to look through all
supertypes, or there is a good reason why u look on the first one ??
Re: AdapterFactories [message #418705 is a reply to message #418700] Thu, 24 April 2008 16:52 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Giulio,

It's not so clear how many packages are involved. A switch is generally
expected to cover all the types in the package. If there are multiple
choices, it's not so clear how it should decide which one to call. It
seems better to have a switch that covers AB directly. A
ComposedAdapterFactory is good for composing multiple factories and for
choosing a best fit; there's logic in there for considering all the
super types.


Giulio Seregni wrote:
> Hi,
> I have this problem usign adaperter factories:
> In my model i have 3 classes, A, B and AB. AB has supertipes A and B
> in this order.
>
> I have and adapter factory that works with B objects.
>
> When i try to adapt AB using this factory i get a null pointer
> exception because the "switch" class used by adapter factory consider
> only the first ESupertipe( in this case A)
>
> Here the auto-generated code...
>
> protected T doSwitch(EClass theEClass, EObject theEObject) {
> if (theEClass.eContainer() == modelPackage) {
> return doSwitch(theEClass.getClassifierID(), theEObject);
> }
> else {
> List<EClass> eSuperTypes = theEClass.getESuperTypes();
> return
> eSuperTypes.isEmpty() ?
> defaultCase(theEObject) :
> doSwitch(eSuperTypes.get(0), theEObject);
> }
> }
>
> Notice the eSuperTypes.get(0).
>
> Now, can i change the implementation of doSwitch to look through all
> supertypes, or there is a good reason why u look on the first one ??
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: AdapterFactories [message #418752 is a reply to message #418705] Mon, 28 April 2008 07:45 Go to previous messageGo to next message
Giulio Seregni is currently offline Giulio SeregniFriend
Messages: 21
Registered: July 2009
Junior Member
> there's logic in there for considering all the
> super types.


The problem seems to be in the logic for considering super types.
the method below does not seems to cycle on all super type but only to "go
up" the hierarchy of the FIRST super type.

could i change the code to cycle all super types ??

thx in adv,

giulio


>> protected T doSwitch(EClass theEClass, EObject theEObject) {
>> if (theEClass.eContainer() == modelPackage) {
>> return doSwitch(theEClass.getClassifierID(), theEObject);
>> }
>> else {
>> List<EClass> eSuperTypes = theEClass.getESuperTypes();
>> return
>> eSuperTypes.isEmpty() ?
>> defaultCase(theEObject) :
>> doSwitch(eSuperTypes.get(0), theEObject);
>> }
>> }
>>
>> Notice the eSuperTypes.get(0).
>>
Re: AdapterFactories [message #418754 is a reply to message #418752] Mon, 28 April 2008 11:48 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Giulio,

Comments below.

Giulio Seregni wrote:
>> there's logic in there for considering all the super types.
>
>
> The problem seems to be in the logic for considering super types.
There's certainly more going on than meets the eye since typically a
factory covers all the types and if it doesn't cover a type the composed
factory will find another one that does. I'm not sure why you don't
make use of that...
> the method below does not seems to cycle on all super type but only to
> "go up" the hierarchy of the FIRST super type.
It doesn't no.
>
> could i change the code to cycle all super types ??
You could if a composed factory wouldn't be more convenient. It's got
all the logic to make sure a type isn't visited more than once. Maybe
there's a bug there though that a given package will not be tried more
than once...
>
> thx in adv,
>
> giulio
>
>
>>> protected T doSwitch(EClass theEClass, EObject theEObject) {
>>> if (theEClass.eContainer() == modelPackage) {
>>> return doSwitch(theEClass.getClassifierID(), theEObject);
>>> }
>>> else {
>>> List<EClass> eSuperTypes = theEClass.getESuperTypes();
>>> return
>>> eSuperTypes.isEmpty() ?
>>> defaultCase(theEObject) :
>>> doSwitch(eSuperTypes.get(0), theEObject);
>>> }
>>> }
>>>
>>> Notice the eSuperTypes.get(0).
>>>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Control deletion
Next Topic:AdapterFactoryLabelProvider doesnt work in TableViewer
Goto Forum:
  


Current Time: Fri Apr 26 06:11:46 GMT 2024

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

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

Back to the top