how to adapt the generated objectsI have [message #643502] |
Tue, 07 December 2010 07:28 |
Tom H Messages: 139 Registered: July 2009 |
Senior Member |
|
|
I have some EMF generated objects from an xsd and now have lots of classes like
Type1Request
Type2Request
Type3Request
Type4Request
Type5Request
I need to adapt those objects to a local interface called IMyRequest which specifies how to do something with the request objects
really I just want to check the type of the object and add a method to it, if it one of the classes above, something like;
public RequestAdapter(){
void RequestAdapter(EObject req){
switch(EObject)
{
case Type1Request :
case Type2Request::
case Type3Request::
case Type4Request:
//all is well
case SomeOtherObject:
throw NotSupportedException;
break;
}
}
public string process(){
do something here//
}
}
What pattern should I be looking at?
I am confused by EMF adapter patterns as they seem to be orientated towards adding notifications to objects rather than extra functionality.
Any suggestions would be welcome.Thanks
T
[Updated on: Tue, 07 December 2010 07:30] Report message to a moderator
|
|
|
Re: how to adapt the generated objectsI have [message #643641 is a reply to message #643502] |
Tue, 07 December 2010 17:59 |
Ed Merks Messages: 33217 Registered: July 2009 |
Senior Member |
|
|
Tom,
You could do it in the usual Java way with a bunch of instanceof tests
or use the generated switch. Look at the modelSwitch of the generated
XyzAdapterFactory as a good example.
Tom H wrote:
> I have some EMF generated objects from an xsd and now have lots of
> classes like
> Type1Request
> Type2Request
> Type3Request
> Type4Request
> Type5Request
>
>
> I need to adapt those objects to a local interface called IMyRequest
> which specifies how to do something with the request objects
>
> really I just want to check the type of the object and add a class to
> it, if it one of the classes above, something like;
>
> public RequestAdapter(){
>
> void RequestAdapter(EObject req){
> switch(EObject)
> {
> case Type1Request :
> case Type2Request::
> case Type3Request::
> case Type4Request:
>
> //all is well
>
> case SomeOtherObject:
> throw NotSupportedException;
> break;
> }
> }
>
> public string process(){
> do something here//
>
> }
> }
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03408 seconds