On a previous project, we solved this problem by abstracting the
environment into a BusinessContext interface. Each business component
object was passed a reference to a BusinessContext in an init() method. The
BusinessContext allowed you to access configuration values with a
getAttribute(String key) API. By abstracting the "environment" in which a
business component is running, you can add support for different
environments.
One of the implementations of BusinessContext was EjbBusinessContext, which
implemented getAttribute() by looking up the configured values in the
java:comp/env namespace via an InitialContext. In EJB (1.1+), that's how
you're supposed to pass configuration values to your business components.
If you still want to go the Properties route, there's an easier way than
has been suggested. Use resoruces:
Properties p = new Properties();
p.load(MyClass.class.getResourceAsStream("/myapplication.properties"));
-eric
Tim Endres To: [EMAIL PROTECTED]
<[EMAIL PROTECTED] cc:
M> Subject: Re: Uniform
Environment/Property Access for
Sent by: A EJBs and Non-EJBs
mailing list for
Enterprise
JavaBeans
development
<EJB-INTEREST@JAV
A.SUN.COM>
06/25/2002 05:47
PM
Please respond to
Tim Endres
We used java.util.Properties, but instead of reading/writing the properties
from/to a file, we stored them in the database. Wrote a simple utility
class
that knew whether to get the JDBC connection from the app server or
directly
via a JDBC URL + driver_class_name, and voila, universal properties.
Finally,
we wrote a web service (and a servlet) to dish up the properties remotely
over the web.
>
> I've designed many cute ways for "global properties", including JNDI,
RMI, JMS, etc... However, the simpliest way is till using
java.util.Properties and reading from a file. Just the spec says you can't
access File I/O from ejbs doesn't mean you can't. Create a
PropertiesFactory with a static synchronized init method. Call this method
explicitly from your plain-old-java class, and call from intializeContext
from you ejbs, or better, a startup class of your container if supported.
> Gene
> Mike Dunbar <[EMAIL PROTECTED]> wrote: Hello,
> I am wondering if some of you have already fought this battle and could
> help me out before I do my own brainstorming. Basically, we don't want
> to "hard-code" our business logic components into the EJB model. We
> would like to develop the core components in plain ol' Java and
> "wrap"/deploy them as EJBs when it makes sense. Basically, the EJB
> would just delegate to the "wrapped" Java component. Sounds simply
> enough, right?
>
> The part I need help with is: how to give the components access to
> configurable properties in a way that works both when they are deployed
> as an EJB, and when they are not deployed as an EJB? The most straight
> forward way would seem to be putting such properties a Java properties
> file, but I believe EJBs are not allowed to do file I/O - right? I
> think EJBs usually get such information from JNDI entries specified
> in the EJB's deployment descriptor as 's. Is there a uniform
> mechanism that will work both when the components are deploy as EJBs
> and when they are not? For example, maybe the components could always
> access the properties via JNDI. Sometimes an application server would
> have put them there (when deployed as an EJB), sometimes they would've
> got there via another mechanism (when they are not deployed as an EJB).
> But, I've heard that JNDI lookup's give pretty bad performance. This
> would also require a naming server to present whenever they are
> Deployed, which I think is more demanding than something like a simple
> properties file.
>
> Has anyone else tried to do this? Could you point me in the right
> dirction? This seems like a common approach people would want to use -
> not tying your code to a given component model so it could be used
> outside of that model also.
>
> Much Thanks for Your Help!
> Mike
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! - Official partner of 2002 FIFA World Cup
> http://fifaworldcup.yahoo.com
>
>
===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff EJB-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
>
>
> ---------------------------------
> Do You Yahoo!?
> Sign-up for Video Highlights of 2002 FIFA World Cup
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".