Skip to main content


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 07:28 Go to next message
Tom H is currently offline Tom HFriend
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 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33107
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/
Previous Topic:generics in ecore model
Next Topic:what is the difference between EMF, UML ,Protege and MetaEdit+
Goto Forum:
  


Current Time: Tue Mar 19 05:07:01 GMT 2024

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

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

Back to the top