Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Unmodifiable lists
Unmodifiable lists [message #430848] Fri, 12 June 2009 14:20 Go to next message
Manuel Selva is currently offline Manuel SelvaFriend
Messages: 189
Registered: July 2009
Location: Grenoble, France
Senior Member
Hi,

I am using EMF through annotated Java code as following:

/**
* Adds the given type to this filter. Has no effect if the given type
* already belongs to this filter.
*
* @param type
* the type to add
* @model
*/
public void addEntityType(String type);

/**
* Returns the list of types belonging to this filter. Types are identified
* by there name.
*
* @return the list of types for this entity type filter
*
* @model
*/
public List<String> getEntityTypes();

/**
* Removes the given type from this filter. Has no effect if the given type
* doesn't belong to this filter.
*
* @param type
* the type to remove
* @model
*/
public void removeEntityType(String type);

After creating ecore and genmodel files from this annotated interface, and
after generating code the getEntityTypes method is modified as following:

public EList<String> getEntityTypes();

For encapsulation purpose I want this EList to be unmodifiable, thus the
interface client's code can only modify the list through add and remove
methods.

Is there any clean way to do that I.e modifying Java annotation or the
genmodel file to tell the generator to generate code returning
unmodifiable list ? (I was unable to find that after googling ...)

How do you manage such situations ?

Thanks in advance

Manu


Re: Unmodifiable lists [message #430853 is a reply to message #430848] Fri, 12 June 2009 15:39 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Manuel,

Comments below.

Manuel Selva wrote:
> Hi,
>
> I am using EMF through annotated Java code as following:
>
> /**
> * Adds the given type to this filter. Has no effect if the given type
> * already belongs to this filter.
> * * @param type
> * the type to add
> * @model
> */
> public void addEntityType(String type);
>
> /**
> * Returns the list of types belonging to this filter. Types are
> identified
> * by there name.
> * * @return the list of types for this entity type filter
> * * @model
> */
> public List<String> getEntityTypes();
>
> /**
> * Removes the given type from this filter. Has no effect if the given
> type
> * doesn't belong to this filter.
> * * @param type
> * the type to remove
> * @model
> */
> public void removeEntityType(String type);
>
> After creating ecore and genmodel files from this annotated interface,
> and after generating code the getEntityTypes method is modified as
> following:
>
> public EList<String> getEntityTypes();
>
> For encapsulation purpose I want this EList to be unmodifiable, thus
> the interface client's code can only modify the list through add and
> remove methods.
But the deserializer and copier won't know to do that...
>
> Is there any clean way to do that I.e modifying Java annotation or the
> genmodel file to tell the generator to generate code returning
> unmodifiable list ? (I was unable to find that after googling ...)
No, even unchangeable list features generate a list that can be changed.
>
> How do you manage such situations ?
Don't. Perhaps it's good to understand why you are doing this...
>
> Thanks in advance
>
> Manu
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Customizing XML format of root element
Next Topic:Code generation for sequence diagram
Goto Forum:
  


Current Time: Fri Apr 26 20:47:13 GMT 2024

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

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

Back to the top