|
Re: AdapterFactories [message #418705 is a reply to message #418700] |
Thu, 24 April 2008 16:52 |
Ed Merks 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 #418754 is a reply to message #418752] |
Mon, 28 April 2008 11:48 |
Ed Merks 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/
|
|
|
Powered by
FUDForum. Page generated in 0.03437 seconds