KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > presumo > util > config > Configuration


1 /**
2  * This file is part of Presumo.
3  *
4  * Presumo is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * Presumo is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Presumo; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  *
19  * Copyright 2001 Dan Greff
20  */

21 package com.presumo.util.config;
22
23 import java.util.Enumeration JavaDoc;
24 import java.util.StringTokenizer JavaDoc;
25
26 /**
27  * This class along with Preferences abstracts out what configuration
28  * subsystem is being used from the JMS implementation.
29  *
30  * @author Dan Greff
31  */

32 public abstract class Configuration
33 {
34   private static Configuration onlyInstance;
35   
36   /**
37    * Access point for the configuration abstraction layer.
38    */

39   public static Configuration getInstance()
40   {
41     if (onlyInstance == null)
42       onlyInstance = new PropertyFileConfiguration();
43      
44     return onlyInstance;
45   }
46   
47   /**
48    * Convience method to parse a list from configuration.
49    *
50    * @returns Each element in the list. The return value
51    * will never be null.
52    */

53   public static String JavaDoc[] parseList(String JavaDoc list, String JavaDoc delim)
54   {
55     String JavaDoc [] retval = null;
56     if (list == null) {
57       retval = new String JavaDoc[0];
58       return retval;
59     } if (delim == null) {
60       retval = new String JavaDoc[1];
61       retval[0] = list;
62       return retval;
63     }
64    
65     StringTokenizer JavaDoc tokens = new StringTokenizer JavaDoc(list, delim);
66     int size = tokens.countTokens();
67     retval = new String JavaDoc[size];
68     
69     for (int i=0; i < size; ++i)
70       retval[i] = tokens.nextToken().trim();
71       
72     return retval;
73   }
74   
75   /**
76    * Used to retrieve the preferences object for the entire system.
77    *
78    * @return The preference object, or null if an error occurred.
79    */

80   public abstract Preferences getSystemPreferences();
81   
82   /**
83    * Used to retrieve the preferences object for the specified subsystem.
84    *
85    * @return The preference object if found, or null if an error occurred
86    * or it was not found.
87    */

88   public abstract Preferences getSubsystemPreferences(String JavaDoc subsystem);
89  
90   /**
91    * List all subsystems containing configuration.
92    *
93    */

94   public abstract Enumeration JavaDoc getSubsystems();
95     
96 }
97
Popular Tags