Hello,
Here's how I pass around Configuration properties in my Struts application.
Certainly this isn't the best practise, but just an idea;
I have created a Singleton class called 'PropertyRetriever' which is simillar
to the "Service Locator" design pattern. It uses Digester to read configuration
properties from a XML file.
Here's what it looks like;
public class PropertyRetriever {
// Singleton's private instance
private static PropertyRetriever me;
private static Digester digester = null;
private static AppRoot root = null;
static {
try {
me = new PropertyRetriever();
} catch (Exception ex) {
//throw new PropertyRetrieverException();
}
}
private PropertyRetriever() throws Exception { //private construtor
to avoid instantiation
getProperties();
}
// Returns PropertyRetriever instance
static public PropertyRetriever getInstance() {
return me;
}
private void getProperties() throws Exception {
// Configure digester
digester = new Digester();
etc etc.
Now from my Action Classes in Struts, I can get any property as follows;
PropertyRetriever propertyRetriever = PropertyRetriever.getInstance();
String appName = propertyRetriever.getAppRoot().getAppName();
I am sure there are pros & cons of this approach.
HTH!
>-- Original Message --
>Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
>From: "Phase Web and Multimedia" <[EMAIL PROTECTED]>
>To: "Struts User List" <[EMAIL PROTECTED]>
>Subject: Best Practice Question.
>Date: Tue, 30 Apr 2002 11:50:30 -0600
>
>
>I have a bean that is created when my app starts and it contains some
>database table conifguration info (I'll call it my config bean). Later
on
>in
>an Action class another bean, that I'll call my logic bean, needs to access
>the values of the config bean. Would it be proper to use the Action class
>to
>pass the config bean to the logic bean and let the logic bean extract the
>values or should I extract all the values from the config bean within the
>Action class and pass the config info in a different manner.
>
>Thanks,
>Brandon Goodin
>Phase Web and Multimedia
>P (406) 862-2245
>F (406) 862-0354
>[EMAIL PROTECTED]
>http://www.phase.ws
>
>
>
>--
>To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
>
Ajay Chitre
Diligent Team, Inc.
(Where Diligent People Work as a Team)
http://www.DiligentTeam.com
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>