Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/clra/web/Configuration.java


1   /*
2    * Copyright (c) Carnegie Lake Rowing Association 2002. All rights reserved.
3    * Distributed under the GPL license. See doc/COPYING.
4    * $RCSfile: Configuration.java,v $
5    * $Date: 2003/03/04 02:35:32 $
6    * $Revision: 1.6 $
7    */
8   
9   package com.clra.web;
10  
11  import com.clra.util.ConfigurationException;
12  import com.clra.util.DBConfiguration;
13  import java.io.InputStream;
14  import java.net.URL;
15  import java.util.Properties;
16  import org.apache.log4j.Category;
17  import org.apache.log4j.helpers.Loader;
18  
19  /**
20   * A collection of configurable properties used by this package.
21   * @version $Id: Configuration.java,v 1.6 2003/03/04 02:35:32 rphall Exp $
22   * @author <a href="mailto:rphall@pluto.njcc.com">Rick Hall</a>
23   */
24  public class Configuration {
25  
26    /** All methods are static */
27    private Configuration() {}
28  
29    private final static String base = Configuration.class.getName();
30  
31    private final static Category theLog = Category.getInstance( base );
32  
33    /** Name of the property that holds the default Member key */
34    public final static String PN_KEY_MEMBER = "membertag.key";
35  
36    /** Name of the property that holds the default MemberTag property */
37    public final static String PN_MEMBER_PROPERTY = "membertag.property";
38  
39    /** Name of the property that holds the value for the assn's first year */
40    public final static String PN_ACCOUNT_FIRSTYEAR =
41      "validate.member.account.firstYear";
42  
43    /** Name of the property that holds the value of the SOAP server URL */
44    public final static String PN_SOAP_SERVER_URL = "membership.soap.url";
45  
46    /** Boat SQL property-name prefix */
47    public final static String PN_PREFIX_SQL_BOAT = "boatset.sql.";
48  
49    /** All Boats */
50    public final static String PN_SQL_BOAT_01 =
51            PN_PREFIX_SQL_BOAT + "01." + DBConfiguration.DBTYPE;
52  
53    /** Specific Boat by id */
54    public final static String PN_SQL_BOAT_02 =
55            PN_PREFIX_SQL_BOAT + "02." + DBConfiguration.DBTYPE;
56  
57    /** Specific Boat by name */
58    public final static String PN_SQL_BOAT_03 =
59            PN_PREFIX_SQL_BOAT + "03." + DBConfiguration.DBTYPE;
60  
61    /** Oarset SQL property-name prefix */
62    public final static String PN_PREFIX_SQL_OARSET = "oarsetset.sql.";
63  
64    /** All Oarsets */
65    public final static String PN_SQL_OARSET_01 =
66            PN_PREFIX_SQL_OARSET + "01." + DBConfiguration.DBTYPE;
67  
68    /** Specific Oarset by id */
69    public final static String PN_SQL_OARSET_02 =
70            PN_PREFIX_SQL_OARSET + "02." + DBConfiguration.DBTYPE;
71  
72    /** Specific Oarset by name */
73    public final static String PN_SQL_OARSET_03 =
74            PN_PREFIX_SQL_OARSET + "03." + DBConfiguration.DBTYPE;
75  
76    /** Name of file that holds default values for this package */
77    private final static String DEFAULTS_FILE =
78            "com/clra/web/web.properties";
79  
80    /** Default properties for this package */
81    private final static Properties defaultProperties = new Properties();
82    static {
83      InputStream is = null;
84      try {
85        URL url = Loader.getResource( DEFAULTS_FILE, Configuration.class );
86        is = url.openStream();
87        defaultProperties.load( is );
88        if ( theLog.isDebugEnabled() ) {
89          theLog.debug( "loaded properties from '" + DEFAULTS_FILE + "'" );
90          java.util.Enumeration _e = defaultProperties.propertyNames();
91          while ( _e.hasMoreElements() ) {
92            theLog.debug( "property: " + _e.nextElement() );
93          }
94        }
95      }
96      catch( Exception x ){
97        String msg = "unable to load default properties from '"
98                + DEFAULTS_FILE + "'";
99        theLog.fatal(msg,x);
100       throw new IllegalStateException( msg );
101     }
102     finally {
103       if ( is != null ) {
104         try { is.close(); } catch( Exception x ) {}
105         is = null;
106       }
107     } // finally
108   } // static
109 
110   /** Utility that looks up a default property by name */
111   private static String getDefaultProperty( String PN ) {
112     // Precondition
113     if ( PN == null || PN.trim().length()== 0 ) {
114       throw new IllegalArgumentException( "invalid property name" );
115     }
116 
117     String retVal = defaultProperties.getProperty( PN );
118     if ( retVal == null || retVal.trim().length() == 0 ) {
119       String msg = "invalid or missing value for '" + PN + "'";
120       theLog.error(msg);
121       retVal = null;
122     }
123     else {
124       retVal = retVal.trim();
125     }
126 
127     return retVal;
128   } // getDefaultProperty(String)
129 
130   /** Utility that looks up a System property or assigns a default value */
131   private static String getProperty( String PN, String DEFAULT ) {
132     // Preconditions
133     //theLog.debug( "PN == '" + PN + "'" );
134     //theLog.debug( "DEFAULT == '" + DEFAULT + "'" );
135     if ( PN == null || PN.trim().length() == 0 ) {
136       throw new IllegalArgumentException( "invalid property name" );
137     }
138     if ( DEFAULT != null && DEFAULT.trim().length() == 0 ) {
139       DEFAULT = null;
140     }
141       
142     String retVal = System.getProperty( PN );
143     if ( retVal == null || retVal.trim().length() == 0 ) {
144       retVal = DEFAULT;
145     }
146     if ( retVal == null || retVal.trim().length() == 0 ) {
147       String msg = "no property for '" + PN + "'";
148       theLog.fatal( msg );
149       throw new IllegalStateException( msg );
150     }
151     retVal = retVal.trim();
152 
153     return retVal;
154   } // getProperty(String,String)
155 
156   /** Default Member key */
157   private static String DEFAULT_KEY_MEMBER = null;
158   public static String KEY_MEMBER = null;
159   static {
160     DEFAULT_KEY_MEMBER = getDefaultProperty( PN_KEY_MEMBER );
161     theLog.info( "DEFAULT_KEY_MEMBER == '" + DEFAULT_KEY_MEMBER + "'" );
162     KEY_MEMBER = getProperty( PN_KEY_MEMBER, DEFAULT_KEY_MEMBER );
163     theLog.info( "KEY_MEMBER == '" + KEY_MEMBER + "'" );
164   } // static
165 
166   /** Default MemberTag property */
167   private static String DEFAULT_MEMBER_PROPERTY = null;
168   public static String MEMBER_PROPERTY = null;
169   static {
170     DEFAULT_MEMBER_PROPERTY = getDefaultProperty( PN_MEMBER_PROPERTY );
171     theLog.info("DEFAULT_MEMBER_PROPERTY == '" + DEFAULT_MEMBER_PROPERTY + "'");
172     MEMBER_PROPERTY = getProperty(PN_MEMBER_PROPERTY, DEFAULT_MEMBER_PROPERTY );
173     theLog.info( "MEMBER_PROPERTY == '" + MEMBER_PROPERTY + "'" );
174   } // static
175 
176   /** The rowing association's first year */
177   public static String DEFAULT_ACCOUNT_FIRSTYEAR = null;
178   public static String ACCOUNT_FIRSTYEAR = null;
179   static {
180     DEFAULT_ACCOUNT_FIRSTYEAR = getDefaultProperty( PN_ACCOUNT_FIRSTYEAR );
181     theLog.info("DEFAULT_ACCT_FIRSTYEAR == '" +DEFAULT_ACCOUNT_FIRSTYEAR+ "'");
182     ACCOUNT_FIRSTYEAR =
183       getProperty(PN_ACCOUNT_FIRSTYEAR, DEFAULT_ACCOUNT_FIRSTYEAR );
184     theLog.info( "ACCT_FIRSTYEAR == '" + ACCOUNT_FIRSTYEAR + "'" );
185   } // static
186 
187   /** The URL of the membership SOAP server */
188   public static String DEFAULT_SOAP_SERVER_URL = null;
189   public static String SOAP_SERVER_URL = null;
190   static {
191     DEFAULT_SOAP_SERVER_URL = getDefaultProperty( PN_SOAP_SERVER_URL );
192     theLog.info("DEFAULT_ACCT_FIRSTYEAR == '" +DEFAULT_SOAP_SERVER_URL+ "'");
193     SOAP_SERVER_URL =
194       getProperty(PN_SOAP_SERVER_URL, DEFAULT_SOAP_SERVER_URL );
195     theLog.info( "ACCT_FIRSTYEAR == '" + SOAP_SERVER_URL + "'" );
196   } // static
197 
198   /** Default SQL that selects up all boats */
199   private static String DEFAULT_SQL_BOAT_01 = null;
200   static {
201     DEFAULT_SQL_BOAT_01 = getDefaultProperty( PN_SQL_BOAT_01 );
202     theLog.info( "DEFAULT_SQL_BOAT_01 == '" + DEFAULT_SQL_BOAT_01 + "'" );
203   } // static
204 
205   /** SQL that selects all boats */
206   public static String SQL_BOAT_01 = null;
207   static {
208     SQL_BOAT_01 = getProperty( PN_SQL_BOAT_01, DEFAULT_SQL_BOAT_01 );
209     theLog.info( "SQL_BOAT_01 == '" + SQL_BOAT_01 + "'" );
210   } // static
211 
212   /** Default SQL that selects a boat by id */
213   private static String DEFAULT_SQL_BOAT_02 = null;
214   static {
215     DEFAULT_SQL_BOAT_02 = getDefaultProperty( PN_SQL_BOAT_02 );
216     theLog.info( "DEFAULT_SQL_BOAT_02 == '" + DEFAULT_SQL_BOAT_02 + "'" );
217   } // static
218 
219   /** SQL that selects a boat by id */
220   public static String SQL_BOAT_02 = null;
221   static {
222     SQL_BOAT_02 = getProperty( PN_SQL_BOAT_02, DEFAULT_SQL_BOAT_02 );
223     theLog.info( "SQL_BOAT_02 == '" + SQL_BOAT_02 + "'" );
224   } // static
225 
226   /** Default SQL that selects a boat by name */
227   private static String DEFAULT_SQL_BOAT_03 = null;
228   static {
229     DEFAULT_SQL_BOAT_03 = getDefaultProperty( PN_SQL_BOAT_03 );
230     theLog.info( "DEFAULT_SQL_BOAT_03 == '" + DEFAULT_SQL_BOAT_03 + "'" );
231   } // static
232 
233   /** SQL that selects a boat by name */
234   public static String SQL_BOAT_03 = null;
235   static {
236     SQL_BOAT_03 = getProperty( PN_SQL_BOAT_02, DEFAULT_SQL_BOAT_03 );
237     theLog.info( "SQL_BOAT_03 == '" + SQL_BOAT_03 + "'" );
238   } // static
239 
240   /** Default SQL that selects up all oarsets */
241   private static String DEFAULT_SQL_OARSET_01 = null;
242   static {
243     DEFAULT_SQL_OARSET_01 = getDefaultProperty( PN_SQL_OARSET_01 );
244     theLog.info( "DEFAULT_SQL_OARSET_01 == '" + DEFAULT_SQL_OARSET_01 + "'" );
245   } // static
246 
247   /** SQL that selects all oarsets */
248   public static String SQL_OARSET_01 = null;
249   static {
250     SQL_OARSET_01 = getProperty( PN_SQL_OARSET_01, DEFAULT_SQL_OARSET_01 );
251     theLog.info( "SQL_OARSET_01 == '" + SQL_OARSET_01 + "'" );
252   } // static
253 
254   /** Default SQL that selects a oarset by id */
255   private static String DEFAULT_SQL_OARSET_02 = null;
256   static {
257     DEFAULT_SQL_OARSET_02 = getDefaultProperty( PN_SQL_OARSET_02 );
258     theLog.info( "DEFAULT_SQL_OARSET_02 == '" + DEFAULT_SQL_OARSET_02 + "'" );
259   } // static
260 
261   /** SQL that selects a oarset by id */
262   public static String SQL_OARSET_02 = null;
263   static {
264     SQL_OARSET_02 = getProperty( PN_SQL_OARSET_02, DEFAULT_SQL_OARSET_02 );
265     theLog.info( "SQL_OARSET_02 == '" + SQL_OARSET_02 + "'" );
266   } // static
267 
268   /** Default SQL that selects a oarset by name */
269   private static String DEFAULT_SQL_OARSET_03 = null;
270   static {
271     DEFAULT_SQL_OARSET_03 = getDefaultProperty( PN_SQL_OARSET_03 );
272     theLog.info( "DEFAULT_SQL_OARSET_03 == '" + DEFAULT_SQL_OARSET_03 + "'" );
273   } // static
274 
275   /** SQL that selects a oarset by name */
276   public static String SQL_OARSET_03 = null;
277   static {
278     SQL_OARSET_03 = getProperty( PN_SQL_OARSET_02, DEFAULT_SQL_OARSET_03 );
279     theLog.info( "SQL_OARSET_03 == '" + SQL_OARSET_03 + "'" );
280   } // static
281 
282 } // Configuration
283 
284 /*
285  * $Log: Configuration.java,v $
286  * Revision 1.6  2003/03/04 02:35:32  rphall
287  * Add property for membership SOAP url
288  *
289  * Revision 1.5  2003/02/26 03:38:46  rphall
290  * Added copyright and GPL license
291  *
292  * Revision 1.4  2003/02/19 22:09:17  rphall
293  * Removed gratuitous use of CLRA acronym
294  *
295  * Revision 1.3  2003/02/19 20:50:31  rphall
296  * Moved validation values to Configuration class and web.properties file
297  */
298