If you really want to return an unmodifiable Collection structure, you
can use one of these helper methods in the java.util.Collections class:
static Collection unmodifiableCollection(Collection c)
static List unmodifiableList(List list)
static Map unmodifiableMap(Map m)
static Set unmodifiableSet(Set s)
static SortedMap unmodifiableSortedMap(SortedMap m)
static SortedSet unmodifiableSortedSet(SortedSet s)
So you could do:
{
...
origList = new ArrayList();
origList.add(x);
...
return Collections.unmodifiableList( origList );
}
Just make sure the contents of the Collection are Serializable or Remote.
Now, that being said, if this EJB you're talking about is a stateless
session bean (slsb) accessing entities, it would be ***BAD*** to return
remote interfaces of those entities. Much network calls and separate
transactions = bad performance and more.
Instead, use local interfaces to your entites from your slsb, put the
data into Serializable data transfer objects (reg. javabeans, or
"dto's"), shove them into an ArrayList, and return that. Of course,
that's just one (common) design pattern among other viable options.
Hope this helps,
David
--
Brandon Knitter wrote:
> Okay, I know this is not JBoss specific, but I got a good response from my last
> question, and this is a question in the context of EJB.
>
> When returning a java.util.Collection, what object is the best to return? I'm
> assuming that returning a Vector is not really a good idea as it is able to be
> modified. What options for immutable Collection implementations are there?
>
>
_______________________________________________________________
Sponsored by:
ThinkGeek at http://www.ThinkGeek.com/
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user