KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sape > carbon > core > config > Config


1 /*
2  * The contents of this file are subject to the Sapient Public License
3  * Version 1.0 (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  * http://carbon.sf.net/License.html.
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is The Carbon Component Framework.
12  *
13  * The Initial Developer of the Original Code is Sapient Corporation
14  *
15  * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
16  */

17
18 package org.sape.carbon.core.config;
19
20 import org.sape.carbon.core.bootstrap.BootStrapper;
21 import org.sape.carbon.core.config.node.Node;
22 import org.sape.carbon.core.config.node.NodeNotFoundException;
23 import org.sape.carbon.core.config.node.event.NodeEventListener;
24
25 /**
26  * <P>
27  * <code>Config</code> implements a static singleton pattern to provide
28  * a single point of access for configuration data. Configuration data
29  * in the form of <code>Configuration</code> objects can be accessed from
30  * an underlying data store, and written to an underlying data store via
31  * <code>Config</code>. The <code>Config</code> is the preferred class
32  * for accessing configuration data.
33  * </P>
34  *
35  * Copyright 2002 Sapient
36  * @since carbon 1.0
37  * @author Mike Redd, January 2002
38  * @version $Revision: 1.26 $($Author: dvoet $ / $Date: 2003/05/05 21:21:15 $)
39  */

40 public class Config implements ConfigurationService {
41
42     /**
43      * Reference to the one and only instance of this class, following
44      * the Item 2 in Josh Bloch's "Effective Java".
45      */

46     private static Config INSTANCE = new Config();
47
48     /** The name of the root node for use in the fetchNode method */
49     public static final String JavaDoc ROOT_NODE_NAME =
50         String.valueOf(Node.DELIMITER);
51
52     /**
53      * Cached reference to the initial <code>ConfigurationService</code>
54      * in the system.
55      */

56     private ConfigurationService configService = null;
57
58     /**
59      * Private constructor to ensure that others do not instantiate
60      * a unique <code>Config</code> object.
61      */

62     private Config() {
63     }
64
65     /**
66      * Accessor to the single instance of <code>Config</code>.
67      *
68      * @return The single instance of <code>Config</code>.
69      */

70     public static Config getInstance() {
71         return INSTANCE;
72     }
73
74     /**
75      * @see ConfigurationService#fetchConfiguration
76      */

77     public Configuration fetchConfiguration(String JavaDoc name) {
78         return this.getConfigurationService().fetchConfiguration(name);
79     }
80
81     /**
82      * @see ConfigurationService#fetchWritableConfiguration
83      */

84     public Configuration fetchWritableConfiguration(String JavaDoc name) {
85         return this.getConfigurationService().fetchWritableConfiguration(name);
86     }
87
88     /**
89      * @see ConfigurationService#storeConfiguration
90      */

91     public void storeConfiguration(String JavaDoc name, Configuration config)
92                                     throws ConfigurationStoreException {
93
94         this.getConfigurationService().storeConfiguration(name, config);
95     }
96
97
98     /**
99      * @see ConfigurationService#createConfiguration
100      */

101     public Configuration createConfiguration(Class JavaDoc configurationType) {
102          return
103             this.getConfigurationService().
104                  createConfiguration(configurationType);
105     }
106
107
108     /**
109      * @see ConfigurationService#fetchNode
110      */

111     public Node fetchNode(String JavaDoc nodeName) throws NodeNotFoundException {
112         return getConfigurationService().fetchNode(nodeName);
113     }
114
115     /**
116      * @see ConfigurationService#nodeExists
117      */

118     public boolean nodeExists(String JavaDoc nodeName) {
119         return getConfigurationService().nodeExists(nodeName);
120     }
121
122     /**
123      * @see ConfigurationService#addNodeListener
124      */

125     public void addNodeListener(String JavaDoc nodeName, NodeEventListener listener)
126         throws NodeNotFoundException {
127
128         getConfigurationService().addNodeListener(nodeName, listener);
129     }
130
131     /**
132      * Provides static access to the Configuration Service.
133      * @return returns the configuration service used by default in
134      * the system.
135      */

136     public ConfigurationService getConfigurationService() {
137
138         if (this.configService == null) {
139             this.configService =
140                 BootStrapper.getInstance().fetchConfigurationService();
141         }
142
143         return this.configService;
144     }
145 }
146
Popular Tags