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

Quick Search    Search Deep

Source code: com/clra/member/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/02/26 03:38:45 $
6    * $Revision: 1.12 $
7    */
8   
9   package com.clra.member;
10  
11  import com.clra.util.DBConfiguration;
12  import com.clra.util.ConfigurationException;
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.12 2003/02/26 03:38:45 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    /** A hard-coded JAAS LoginContext == "clra" */
30    public final static String LOGIN_CONTEXT = "clra";
31  
32    private final static String base = Configuration.class.getName();
33  
34    private final static Category theLog = Category.getInstance( base );
35  
36    /** Session SQL property-name prefix */
37    public final static String PN_PREFIX_SQL_SESSION = "memberset.sql.";
38  
39    /** SQL date format spec */
40    public final static String PN_SQL_DATE_FORMAT =
41            PN_PREFIX_SQL_SESSION + "dateformat." + DBConfiguration.DBTYPE;
42  
43    public final static String PN_PREFIX_SQL_01 = "memberset.sql.01.";
44  
45    public final static String PN_SQL_01 =
46            PN_PREFIX_SQL_01 + DBConfiguration.DBTYPE;
47  
48    public final static String PN_PREFIX_SQL_02 = "memberset.sql.02.";
49  
50    public final static String PN_SQL_02 =
51            PN_PREFIX_SQL_02 + DBConfiguration.DBTYPE;
52  
53    public final static String PN_PREFIX_SQL_03 = "memberset.sql.03.";
54  
55    public final static String PN_SQL_03 =
56            PN_PREFIX_SQL_03 + DBConfiguration.DBTYPE;
57  
58    public final static String PN_PREFIX_SQL_04 = "memberset.sql.04.";
59  
60    public final static String PN_SQL_04 =
61            PN_PREFIX_SQL_04 + DBConfiguration.DBTYPE;
62  
63    public final static String PN_PREFIX_SQL_05 = "memberset.sql.05.";
64  
65    public final static String PN_SQL_05 =
66            PN_PREFIX_SQL_05 + DBConfiguration.DBTYPE;
67  
68    public final static String PN_PREFIX_SQL_06 = "memberset.sql.06.";
69  
70    public final static String PN_SQL_06 =
71            PN_PREFIX_SQL_06 + DBConfiguration.DBTYPE;
72  
73    public final static String PN_PREFIX_SQL_07 = "memberset.sql.07.";
74  
75    public final static String PN_SQL_07 =
76            PN_PREFIX_SQL_07 + DBConfiguration.DBTYPE;
77  
78    public final static String PN_PREFIX_SQL_08 = "memberset.sql.08.";
79  
80    public final static String PN_SQL_08 =
81            PN_PREFIX_SQL_08 + DBConfiguration.DBTYPE;
82  
83    public final static String PN_PREFIX_SQL_081 = "memberset.sql.081.";
84  
85    public final static String PN_SQL_081 =
86            PN_PREFIX_SQL_081 + DBConfiguration.DBTYPE;
87  
88    public final static String PN_PREFIX_SQL_09 = "memberset.sql.09.";
89  
90    public final static String PN_SQL_09 =
91            PN_PREFIX_SQL_09 + DBConfiguration.DBTYPE;
92            
93    public final static String PN_PREFIX_SQL_10 = "memberset.sql.10.";
94  
95    public final static String PN_SQL_10 =
96            PN_PREFIX_SQL_10 + DBConfiguration.DBTYPE;
97            
98    public final static String PN_PREFIX_SQL_11 = "memberset.sql.11.";
99  
100   public final static String PN_SQL_11 =
101           PN_PREFIX_SQL_11 + DBConfiguration.DBTYPE;
102           
103   public final static String PN_PREFIX_SQL_12 = "memberset.sql.12.";
104 
105   public final static String PN_SQL_12 =
106           PN_PREFIX_SQL_12 + DBConfiguration.DBTYPE;
107           
108   public final static String PN_PREFIX_SQL_15 = "memberset.sql.15.";
109 
110   public final static String PN_SQL_15 =
111           PN_PREFIX_SQL_15 + DBConfiguration.DBTYPE;
112           
113   public final static String PN_PREFIX_SQL_15A = "memberset.sql.15a.";
114 
115   public final static String PN_SQL_15A =
116           PN_PREFIX_SQL_15A + DBConfiguration.DBTYPE;
117           
118   public final static String PN_PREFIX_SQL_16 = "memberset.sql.16.";
119 
120   public final static String PN_SQL_16 =
121           PN_PREFIX_SQL_16 + DBConfiguration.DBTYPE;
122           
123   public final static String PN_PREFIX_SQL_17 = "memberset.sql.17.";
124 
125   public final static String PN_SQL_17 =
126           PN_PREFIX_SQL_17 + DBConfiguration.DBTYPE;
127           
128   public final static String PN_PREFIX_SQL_18 = "memberset.sql.18.";
129 
130   public final static String PN_SQL_18 =
131           PN_PREFIX_SQL_18 + DBConfiguration.DBTYPE;
132 
133   public final static String PN_MEMBER_HOME = "member.home";
134 
135   private final static String DEFAULTS_FILE =
136           "com/clra/member/member.properties";
137 
138   private final static Properties defaultProperties = new Properties();
139   static {
140     InputStream is = null;
141     try {
142       URL url = Loader.getResource( DEFAULTS_FILE, Configuration.class );
143       is = url.openStream();
144       defaultProperties.load( is );
145       if ( theLog.isDebugEnabled() ) {
146         theLog.debug( "loaded properties from '" + DEFAULTS_FILE + "'" );
147         java.util.Enumeration _e = defaultProperties.propertyNames();
148         while ( _e.hasMoreElements() ) {
149           theLog.debug( "property: " + _e.nextElement() );
150         }
151       }
152     }
153     catch( Exception x ){
154       String msg = "unable to load default properties from '"
155               + DEFAULTS_FILE + "'";
156       theLog.fatal(msg,x);
157       throw new IllegalStateException( msg );
158     }
159     finally {
160       if ( is != null ) {
161         try { is.close(); } catch( Exception x ) {}
162         is = null;
163       }
164     } // finally
165   } // static
166 
167   private static String getDefaultProperty( String PN ) {
168     // Precondition
169     if ( PN == null || PN.trim().length()== 0 ) {
170       throw new IllegalArgumentException( "invalid property name" );
171     }
172 
173     String retVal = defaultProperties.getProperty( PN );
174     if ( retVal == null || retVal.trim().length() == 0 ) {
175       String msg = "invalid or missing value for '" + PN + "'";
176       theLog.error(msg);
177       retVal = null;
178     }
179     else {
180       retVal = retVal.trim();
181     }
182 
183     return retVal;
184   } // getDefaultProperty(String)
185 
186   /** Utility that looks up a System property or assigns a default value */
187   private static String getProperty( String PN, String DEFAULT ) {
188     // Preconditions
189     //theLog.debug( "PN == '" + PN + "'" );
190     //theLog.debug( "DEFAULT == '" + DEFAULT + "'" );
191     if ( PN == null || PN.trim().length() == 0 ) {
192       throw new IllegalArgumentException( "invalid property name" );
193     }
194     if ( DEFAULT != null && DEFAULT.trim().length() == 0 ) {
195       DEFAULT = null;
196     }
197       
198     String retVal = System.getProperty( PN );
199     if ( retVal == null || retVal.trim().length() == 0 ) {
200       retVal = DEFAULT;
201     }
202     if ( retVal == null || retVal.trim().length() == 0 ) {
203       String msg = "no property for '" + PN + "'";
204       theLog.fatal( msg );
205       throw new IllegalStateException( msg );
206     }
207     retVal = retVal.trim();
208 
209     return retVal;
210   } // getProperty(String,String)
211 
212   private static String DEFAULT_SQL_DATE_FORMAT = null;
213   public static String SQL_DATE_FORMAT = null;
214   static {
215     DEFAULT_SQL_DATE_FORMAT = getDefaultProperty( PN_SQL_DATE_FORMAT );
216     theLog.info("DEFAULT_SQL_DATE_FORMAT == '" + DEFAULT_SQL_DATE_FORMAT + "'");
217     SQL_DATE_FORMAT = getProperty(PN_SQL_DATE_FORMAT, DEFAULT_SQL_DATE_FORMAT);
218     theLog.info( "SQL_DATE_FORMAT == '" + SQL_DATE_FORMAT + "'" );
219   } // static
220 
221   private static String DEFAULT_SQL_01 = null;
222   static {
223     String tmp = defaultProperties.getProperty( PN_SQL_01 );
224     if ( tmp == null || tmp.trim().length() == 0 ) {
225       String msg = "invalid or missing value for '" + PN_SQL_01 + "'";
226       theLog.error(msg);
227     }
228     else {
229       DEFAULT_SQL_01 = tmp.trim();
230     }
231     theLog.info( "DEFAULT_SQL_01 == '" + DEFAULT_SQL_01 + "'" );
232   } // static
233 
234   public static String SQL_01 = null;
235   static {
236     SQL_01 = System.getProperty( PN_SQL_01 );
237     if ( SQL_01 == null || SQL_01.trim().length() == 0 ) {
238       SQL_01 = DEFAULT_SQL_01;
239     }
240     if ( SQL_01 == null || SQL_01.trim().length() == 0 ) {
241       String msg = "no property for '" + PN_SQL_01 + "'";
242       theLog.fatal( msg );
243       throw new IllegalStateException( msg );
244     }
245     theLog.info( "SQL_01 == '" + SQL_01 + "'" );
246   } // static
247 
248   public static String SQL_02 = null;
249   static {
250     String tmp = defaultProperties.getProperty( PN_SQL_02 );
251     if ( tmp != null ) {
252       tmp = tmp.trim();
253     }
254     theLog.debug( "DEFAULT_SQL_02 == " + tmp );
255     SQL_02 = System.getProperty( PN_SQL_02, tmp );
256     if ( SQL_02 == null || SQL_02.trim().length() == 0 ) {
257       String msg = "no property for '" + PN_SQL_02 + "'";
258       theLog.fatal( msg );
259       throw new IllegalStateException( msg );
260     }
261     theLog.info( "SQL_02 == '" + SQL_02 + "'" );
262   } // static
263 
264   public static String SQL_03 = null;
265   static {
266     String tmp = defaultProperties.getProperty( PN_SQL_03 );
267     if ( tmp != null ) {
268       tmp = tmp.trim();
269     }
270     theLog.debug( "DEFAULT_SQL_03 == " + tmp );
271     SQL_03 = System.getProperty( PN_SQL_03, tmp );
272     if ( SQL_03 == null || SQL_03.trim().length() == 0 ) {
273       String msg = "no property for '" + PN_SQL_03 + "'";
274       theLog.fatal( msg );
275       throw new IllegalStateException( msg );
276     }
277     theLog.info( "SQL_03 == '" + SQL_03 + "'" );
278   } // static
279 
280   public static String SQL_04 = null;
281   static {
282     String tmp = defaultProperties.getProperty( PN_SQL_04 );
283     if ( tmp != null ) {
284       tmp = tmp.trim();
285     }
286     theLog.debug( "DEFAULT_SQL_04 == " + tmp );
287     SQL_04 = System.getProperty( PN_SQL_04, tmp );
288     if ( SQL_04 == null || SQL_04.trim().length() == 0 ) {
289       String msg = "no property for '" + PN_SQL_04 + "'";
290       theLog.fatal( msg );
291       throw new IllegalStateException( msg );
292     }
293     theLog.info( "SQL_04 == '" + SQL_04 + "'" );
294   } // static
295 
296   private static String DEFAULT_SQL_05 = null;
297   static {
298     String tmp = defaultProperties.getProperty( PN_SQL_05 );
299     if ( tmp == null || tmp.trim().length() == 0 ) {
300       String msg = "invalid or missing value for '" + PN_SQL_05 + "'";
301       theLog.error(msg);
302     }
303     else {
304       DEFAULT_SQL_05 = tmp.trim();
305     }
306     theLog.info( "DEFAULT_SQL_05 == '" + DEFAULT_SQL_05 + "'" );
307   } // static
308 
309   public static String SQL_05 = null;
310   static {
311     SQL_05 = System.getProperty( PN_SQL_05 );
312     if ( SQL_05 == null || SQL_05.trim().length() == 0 ) {
313       SQL_05 = DEFAULT_SQL_05;
314     }
315     if ( SQL_05 == null || SQL_05.trim().length() == 0 ) {
316       String msg = "no property for '" + PN_SQL_05 + "'";
317       theLog.fatal( msg );
318       throw new IllegalStateException( msg );
319     }
320     theLog.info( "SQL_05 == '" + SQL_05 + "'" );
321   } // static
322 
323   private static String DEFAULT_SQL_06 = null;
324   public static String SQL_06 = null;
325   static {
326     DEFAULT_SQL_06 = defaultProperties.getProperty( PN_SQL_06 );
327     theLog.info( "DEFAULT_SQL_06 == '" + DEFAULT_SQL_06 + "'" );
328     SQL_06 = System.getProperty( PN_SQL_06, DEFAULT_SQL_06 );
329     if ( SQL_06 == null || SQL_06.trim().length() == 0 ) {
330       String msg = "no property for '" + PN_SQL_06 + "'";
331       theLog.fatal( msg );
332       throw new IllegalStateException( msg );
333     }
334     SQL_06 = SQL_06.trim();
335   } // static
336 
337   private static String DEFAULT_SQL_07 = null;
338   public static String SQL_07 = null;
339   static {
340     DEFAULT_SQL_07 = defaultProperties.getProperty( PN_SQL_07 );
341     theLog.info( "DEFAULT_SQL_07 == '" + DEFAULT_SQL_07 + "'" );
342     SQL_07 = System.getProperty( PN_SQL_07, DEFAULT_SQL_07 );
343     if ( SQL_07 == null || SQL_07.trim().length() == 0 ) {
344       String msg = "no property for '" + PN_SQL_07 + "'";
345       theLog.fatal( msg );
346       throw new IllegalStateException( msg );
347     }
348     SQL_07 = SQL_07.trim();
349   } // static
350 
351   private static String DEFAULT_SQL_08 = null;
352   public static String SQL_08 = null;
353   static {
354     DEFAULT_SQL_08 = defaultProperties.getProperty( PN_SQL_08 );
355     theLog.info( "DEFAULT_SQL_08 == '" + DEFAULT_SQL_08 + "'" );
356     SQL_08 = System.getProperty( PN_SQL_08, DEFAULT_SQL_08 );
357     if ( SQL_08 == null || SQL_08.trim().length() == 0 ) {
358       String msg = "no property for '" + PN_SQL_08 + "'";
359       theLog.fatal( msg );
360       throw new IllegalStateException( msg );
361     }
362     SQL_08 = SQL_08.trim();
363   } // static
364 
365   private static String DEFAULT_SQL_081 = null;
366   public static String SQL_081 = null;
367   static {
368     DEFAULT_SQL_081 = defaultProperties.getProperty( PN_SQL_081 );
369     theLog.info( "DEFAULT_SQL_081 == '" + DEFAULT_SQL_081 + "'" );
370     SQL_081 = System.getProperty( PN_SQL_081, DEFAULT_SQL_081 );
371     if ( SQL_081 == null || SQL_081.trim().length() == 0 ) {
372       String msg = "no property for '" + PN_SQL_081 + "'";
373       theLog.fatal( msg );
374       throw new IllegalStateException( msg );
375     }
376     SQL_081 = SQL_081.trim();
377   } // static
378 
379   private static String DEFAULT_SQL_09 = null;
380   public static String SQL_09 = null;
381   static {
382     DEFAULT_SQL_09 = defaultProperties.getProperty( PN_SQL_09 );
383     theLog.info( "DEFAULT_SQL_09 == '" + DEFAULT_SQL_09 + "'" );
384     SQL_09 = System.getProperty( PN_SQL_09, DEFAULT_SQL_09 );
385     if ( SQL_09 == null || SQL_09.trim().length() == 0 ) {
386       String msg = "no property for '" + PN_SQL_09 + "'";
387       theLog.fatal( msg );
388       throw new IllegalStateException( msg );
389     }
390     SQL_09 = SQL_09.trim();
391   } // static
392 
393   private static String DEFAULT_SQL_10 = null;
394   public static String SQL_10 = null;
395   static {
396     DEFAULT_SQL_10 = defaultProperties.getProperty( PN_SQL_10 );
397     theLog.info( "DEFAULT_SQL_10 == '" + DEFAULT_SQL_10 + "'" );
398     SQL_10 = System.getProperty( PN_SQL_10, DEFAULT_SQL_10 );
399     if ( SQL_10 == null || SQL_10.trim().length() == 0 ) {
400       String msg = "no property for '" + PN_SQL_10 + "'";
401       theLog.fatal( msg );
402       throw new IllegalStateException( msg );
403     }
404     SQL_10 = SQL_10.trim();
405   } // static
406 
407   private static String DEFAULT_SQL_11 = null;
408   public static String SQL_11 = null;
409   static {
410     DEFAULT_SQL_11 = defaultProperties.getProperty( PN_SQL_11 );
411     theLog.info( "DEFAULT_SQL_11 == '" + DEFAULT_SQL_11 + "'" );
412     SQL_11 = System.getProperty( PN_SQL_11, DEFAULT_SQL_11 );
413     if ( SQL_11 == null || SQL_11.trim().length() == 0 ) {
414       String msg = "no property for '" + PN_SQL_11 + "'";
415       theLog.fatal( msg );
416       throw new IllegalStateException( msg );
417     }
418     SQL_11 = SQL_11.trim();
419   } // static
420 
421   private static String DEFAULT_SQL_12 = null;
422   public static String SQL_12 = null;
423   static {
424     DEFAULT_SQL_12 = defaultProperties.getProperty( PN_SQL_12 );
425     theLog.info( "DEFAULT_SQL_12 == '" + DEFAULT_SQL_12 + "'" );
426     SQL_12 = System.getProperty( PN_SQL_12, DEFAULT_SQL_12 );
427     if ( SQL_12 == null || SQL_12.trim().length() == 0 ) {
428       String msg = "no property for '" + PN_SQL_12 + "'";
429       theLog.fatal( msg );
430       throw new IllegalStateException( msg );
431     }
432     SQL_12 = SQL_12.trim();
433   } // static
434 
435   private static String DEFAULT_SQL_15 = null;
436   public static String SQL_15 = null;
437   static {
438     DEFAULT_SQL_15 = defaultProperties.getProperty( PN_SQL_15 );
439     theLog.info( "DEFAULT_SQL_15 == '" + DEFAULT_SQL_15 + "'" );
440     SQL_15 = System.getProperty( PN_SQL_15, DEFAULT_SQL_15 );
441     if ( SQL_15 == null || SQL_15.trim().length() == 0 ) {
442       String msg = "no property for '" + PN_SQL_15 + "'";
443       theLog.fatal( msg );
444       throw new IllegalStateException( msg );
445     }
446     SQL_15 = SQL_15.trim();
447   } // static
448 
449   private static String DEFAULT_SQL_15A = null;
450   public static String SQL_15A = null;
451   static {
452     DEFAULT_SQL_15A = defaultProperties.getProperty( PN_SQL_15A );
453     theLog.info( "DEFAULT_SQL_15A == '" + DEFAULT_SQL_15A + "'" );
454     SQL_15A = System.getProperty( PN_SQL_15A, DEFAULT_SQL_15A );
455     if ( SQL_15A == null || SQL_15A.trim().length() == 0 ) {
456       String msg = "no property for '" + PN_SQL_15A + "'";
457       theLog.fatal( msg );
458       throw new IllegalStateException( msg );
459     }
460     SQL_15A = SQL_15A.trim();
461   } // static
462 
463   private static String DEFAULT_SQL_16 = null;
464   public static String SQL_16 = null;
465   static {
466     DEFAULT_SQL_16 = defaultProperties.getProperty( PN_SQL_16 );
467     theLog.info( "DEFAULT_SQL_16 == '" + DEFAULT_SQL_16 + "'" );
468     SQL_16 = System.getProperty( PN_SQL_16, DEFAULT_SQL_16 );
469     if ( SQL_16 == null || SQL_16.trim().length() == 0 ) {
470       String msg = "no property for '" + PN_SQL_16 + "'";
471       theLog.fatal( msg );
472       throw new IllegalStateException( msg );
473     }
474     SQL_16 = SQL_16.trim();
475   } // static
476 
477   private static String DEFAULT_SQL_17 = null;
478   public static String SQL_17 = null;
479   static {
480     DEFAULT_SQL_17 = defaultProperties.getProperty( PN_SQL_17 );
481     theLog.info( "DEFAULT_SQL_17 == '" + DEFAULT_SQL_17 + "'" );
482     SQL_17 = System.getProperty( PN_SQL_17, DEFAULT_SQL_17 );
483     if ( SQL_17 == null || SQL_17.trim().length() == 0 ) {
484       String msg = "no property for '" + PN_SQL_17 + "'";
485       theLog.fatal( msg );
486       throw new IllegalStateException( msg );
487     }
488     SQL_17 = SQL_17.trim();
489   } // static
490 
491   private static String DEFAULT_SQL_18 = null;
492   static {
493     String tmp = defaultProperties.getProperty( PN_SQL_18 );
494     if ( tmp == null || tmp.trim().length() == 0 ) {
495       String msg = "invalid or missing value for '" + PN_SQL_18 + "'";
496       theLog.error(msg);
497     }
498     else {
499       DEFAULT_SQL_18 = tmp.trim();
500     }
501     theLog.info( "DEFAULT_SQL_18 == '" + DEFAULT_SQL_18 + "'" );
502   } // static
503 
504   public static String SQL_18 = null;
505   static {
506     SQL_18 = System.getProperty( PN_SQL_18 );
507     if ( SQL_18 == null || SQL_18.trim().length() == 0 ) {
508       SQL_18 = DEFAULT_SQL_18;
509     }
510     if ( SQL_18 == null || SQL_18.trim().length() == 0 ) {
511       String msg = "no property for '" + PN_SQL_18 + "'";
512       theLog.fatal( msg );
513       throw new IllegalStateException( msg );
514     }
515     theLog.info( "SQL_18 == '" + SQL_18 + "'" );
516   } // static
517 
518   // method to look up home for MemberEJB
519   private static String _DEFAULT_MEMBER_HOME = null;
520   private static String _MEMBER_HOME = null;
521   static {
522     _DEFAULT_MEMBER_HOME = getDefaultProperty( PN_MEMBER_HOME );
523     theLog.info(
524         "DEFAULT_MEMBER_HOME == '" + _DEFAULT_MEMBER_HOME + "'");
525     _MEMBER_HOME = getProperty(
526         PN_MEMBER_HOME, _DEFAULT_MEMBER_HOME );
527     theLog.info( "MEMBER_HOME == '" + _MEMBER_HOME + "'" );
528   } // static
529 
530   public static String MEMBER_HOME() { return _MEMBER_HOME; }
531 
532 } // Configuration
533 
534 /*
535  * $Log: Configuration.java,v $
536  * Revision 1.12  2003/02/26 03:38:45  rphall
537  * Added copyright and GPL license
538  *
539  * Revision 1.11  2003/02/21 19:12:52  rphall
540  * Added SQL for checking duplicate user names during editing
541  *
542  * Revision 1.10  2003/02/19 22:08:34  rphall
543  * Removed gratuitous use of CLRA acronym
544  *
545  * Revision 1.9  2003/02/19 12:58:37  rphall
546  * Added SQL to insert/delete MemberRole rows
547  *
548  * Revision 1.8  2003/02/16 00:40:29  rphall
549  * Fixed bug with SQL for nextId updates
550  *
551  * Revision 1.7  2003/02/15 04:31:41  rphall
552  * Changes connected to major revision of MemberBean
553  *
554  */
555