Today, Neal Kaiser ([EMAIL PROTECTED]) wrote:
> Hello;
>
> Problem: My application has many text strings (i.e. email messages, email
> recipient addresses, canned messages, etc) that both my servlets and EJBs
> need to access. It needs to be done in a way that these are not hardcoded
> and can be accessed easily from servlets, ejbs, and possibly even standalone
> applications.
>
> My Solution: Have a MessageResources object that is created by a startup
> servlet that contains all these strings. You can then use a
> MessageResources.getValue(String) to get the desired string you want.  This
> is all done, the startup servlet runs, reads in the XML file, and creates
> the MessageResources.
>
> My Problem: I now need a way to pass that MessageResource object into scope
> so it is accessible by Servlets and EJBs (I'll worry about standalone
> applications later).
>
> However, I somehow need a way for the Stateless session bean to get this
> MessageResource object.  I can't  do StartupServlet.getMR() because the EJBs
> might be remote.

You can use JNDI.  You can use the standard JNDI API to store objects
in the JNDI name space if you're running in application scope -- well,
that's the only context I've ever tried it from.

Somewhat messier but perhaps more in the spirit of EJB is to create
environment entries in JNDI via the ejb-jar.xml deployment descriptor.
Then rather than one monolithic object you have a bunch of strings
that can be looked up in JNDI in the java:comp/env directory
(as I recall).

The number of different strings and the number of strings used by
any particular application or client will probably determine which
solution you use.  I've never placed an entry in java:comp/env
except as an experiment, but you've got me thinking!

        Gary


Reply via email to