Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Modeling (top-level project) » how to adapt the generated objectsI have
how to adapt the generated objectsI have [message #643502] Tue, 07 December 2010 02:28 Go to next message
Tom H is currently offline Tom H
Messages: 136
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 02: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 12:59 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 25918
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//
>
> }
> }
>
>
Previous Topic:generics in ecore model
Next Topic:what is the difference between EMF, UML ,Protege and MetaEdit+
Goto Forum:
  


Current Time: Fri Jul 25 06:45:03 EDT 2014

Powered by FUDForum. Page generated in 0.02447 seconds