Skip to main content



      Home
Home » Modeling » EMF » Customized getters and setters
Customized getters and setters [message #417299] Tue, 04 March 2008 15:53 Go to next message
Eclipse UserFriend
Hi,

I want to generate an EMF model from an UML diagram.

Several classes are derived from an abstract super class called
"Identifiable" which specifies an attribute Name : String.

I have a class A which has a containment reference for B where B extends
Identifiable.

A<>-----B
a bs
0..*

Normally EMF only generates a "getBs()" Method which returns a list of all
B's.

Is it possible to extend it in some way, so that I can generate a method
such as
"getBsByName(String name)", i.e. in the best case, all instances of B would
be stored in a map within A, where the key is the name attribute of B and
the value the instance of B itself.

I now that it is possible to force the EMF generator to generate a Map by
introducing an additional EClass called <KeyType>2<ValueType>, but I don't
want to have this in my UML model.

Moreover, convenience methods such as
B A.addToBs();
void A.removeFromBs(B elementToRemove);

would be nice to have...

Thanks in advance for answers,

Daniel
Re: Customized getters and setters [message #417304 is a reply to message #417299] Tue, 04 March 2008 17:06 Go to previous message
Eclipse UserFriend
Daniel,

Comments below.

Daniel wrote:
> Hi,
>
> I want to generate an EMF model from an UML diagram.
>
> Several classes are derived from an abstract super class called
> "Identifiable" which specifies an attribute Name : String.
>
> I have a class A which has a containment reference for B where B extends
> Identifiable.
>
> A<>-----B
> a bs
> 0..*
>
> Normally EMF only generates a "getBs()" Method which returns a list of all
> B's.
>
> Is it possible to extend it in some way, so that I can generate a method
> such as
> "getBsByName(String name)", i.e. in the best case, all instances of B would
> be stored in a map within A, where the key is the name attribute of B and
> the value the instance of B itself.
>
You could add such a method by hand though. Keeping a map up-to-date
with specific to name values would could potentially change is a bit
tricky. What you're doing is not so different from EPackage's
getEClassifier method.
> I now that it is possible to force the EMF generator to generate a Map by
> introducing an additional EClass called <KeyType>2<ValueType>, but I don't
> want to have this in my UML model.
>
> Moreover, convenience methods such as
> B A.addToBs();
> void A.removeFromBs(B elementToRemove);
>
What's wrong with a.getBs().remove(b) or add(b)? It seems a whole
whack of method to duplicate what you can do with the List API is not
all that convenient, but you could add them by hand (or as an EOperation
with a body annotation).
> would be nice to have...
>
> Thanks in advance for answers,
>
> Daniel
>
>
>
>
>
Previous Topic:ExceptionInitializationError
Next Topic:MultiDocument Example
Goto Forum:
  


Current Time: Tue Jul 08 13:21:38 EDT 2025

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

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

Back to the top