Unmodifiable lists [message #430848] |
Fri, 12 June 2009 14:20 |
Manuel Selva 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
http://manuelselva.wordpress.com/
|
|
|
Re: Unmodifiable lists [message #430853 is a reply to message #430848] |
Fri, 12 June 2009 15:39 |
Ed Merks 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/
|
|
|
Powered by
FUDForum. Page generated in 0.02554 seconds