KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > ServerConfiguration


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise;
24
25 import java.rmi.RemoteException JavaDoc;
26 import com.sun.enterprise.util.ORBManager;
27 import com.sun.enterprise.util.Utility;
28 import com.sun.enterprise.repository.Configuration;
29 import com.sun.enterprise.repository.ConfigurationImpl;
30 import com.sun.enterprise.repository.J2EEResourceFactory;
31 /* IASRI #4626188
32 import com.sun.enterprise.repository.J2EEResourceFactoryImpl;
33  */

34 // START OF IASRI #4626188
35
import com.sun.enterprise.repository.IASJ2EEResourceFactoryImpl;
36 // END OF IASRI #4626188
37
import javax.rmi.CORBA.Tie JavaDoc;
38 import java.util.Properties JavaDoc;
39 // IASRI 4660742 START
40
import java.util.logging.*;
41 import com.sun.logging.*;
42 // IASRI 4660742 END
43

44 /**
45  * A Server Configuration is a singleton object that stores all the
46  * properties that are needed by various components.
47  * @author Harish Prabandham
48  */

49 public class ServerConfiguration {
50
51 // IASRI 4660742 START
52
private static Logger _logger=null;
53     static{
54        _logger=LogDomains.getLogger(LogDomains.ROOT_LOGGER);
55         }
56 // IASRI 4660742 END
57
public static final String JavaDoc JNDI_NAME = "ServerConfiguration";
58
59     private static final boolean debug = false;
60     private static ServerConfiguration serverconfig = null;
61
62     private Configuration config;
63     private boolean remote = true;
64
65     public static ServerConfiguration getConfiguration() {
66         if(serverconfig == null) {
67             serverconfig = new ServerConfiguration();
68         }
69         return serverconfig;
70     }
71
72     public static J2EEResourceFactory getJ2EEResourceFactory() {
73         /* IASRI #4626188
74         return new J2EEResourceFactoryImpl();
75          */

76         // START OF IASRI #4626188
77
return new IASJ2EEResourceFactoryImpl();
78         // END OF IASRI #4626188
79
}
80
81     private ServerConfiguration() {
82         try{
83             config = (Configuration) Utility.lookupObject(
84                     JNDI_NAME, Configuration.class);
85         } catch (Exception JavaDoc ne) {
86             // we could not connect to the naming .. lets use a local copy
87
// IASRI 4660742
88
// ne.printStackTrace(System.err);
89
// START OF IASRI 4660742
90
// _logger.log(Level.WARNING,"enterprise.error_connecting",ne);
91
// END OF IASRI 4660742
92
try{
93                 config = new ConfigurationImpl();
94         /* not needed for local copy
95         javax.rmi.PortableRemoteObject.exportObject(config);
96         if(ORBManager.getORB() != null) {
97             Tie servantsTie = javax.rmi.CORBA.Util.getTie(config);
98             servantsTie.orb(ORBManager.getORB());
99         }
100         */

101                 remote = false;
102             } catch(Exception JavaDoc e) {
103         if ( debug )
104 // IASRI 4660742 e.printStackTrace(System.err);
105
// START OF IASRI 4660742
106
_logger.log(Level.WARNING,"enterprise.config_create_error",e);
107 // END OF IASRI 4660742
108
}
109         }
110     }
111
112     /**
113      * This method gets a property value associated with the given key.
114      * @return A property value corresponding to the key
115      */

116     public String JavaDoc getProperty(String JavaDoc key) {
117         String JavaDoc val = null;
118
119         try {
120             val = config.getProperty(key);
121         } catch (Exception JavaDoc e) {
122 // IASRI 4660742 e.printStackTrace(System.err);
123
// START OF IASRI 4660742
124
_logger.log(Level.SEVERE,"enterprise.getpropertry_exception",e);
125 // END OF IASRI 4660742
126
}
127         return val;
128         
129     }
130
131     /**
132      * This method gets a property value associated with the given key.
133      * @param The key
134      * @param The default Value
135      * @return A property value corresponding to the key
136      */

137     public String JavaDoc getProperty(String JavaDoc key, String JavaDoc defaultvalue) {
138         String JavaDoc val = defaultvalue;
139
140         try {
141             val = config.getProperty(key);
142         } catch (Exception JavaDoc e) {
143 // IASRI 4660742 e.printStackTrace(System.err);
144
// START OF IASRI 4660742
145
_logger.log(Level.SEVERE,"enterprise.getpropertry_exception",e);
146 // END OF IASRI 4660742
147
}
148         if(val != null) {
149         return val;
150         } else {
151         return defaultvalue;
152         }
153         
154     }
155
156
157     /**
158      * This method associates a property value with the given key.
159      */

160     public void setProperty(String JavaDoc key, String JavaDoc value) {
161 // IASRI 466074
162
// System.out.println("Setting Property: " + key + " value =" + value +
163
// " " + remote);
164
// START OF IASRI 4660742
165
// _logger.log(Level.FINE,"Setting Property: " + key + " value =" + value +
166
// " " + remote);
167
// END OF IASRI 4660742
168
try {
169             if (remote) {
170                 config.setProperty(key, value);
171             } else {
172                 throw new IllegalStateException JavaDoc("Cannot set properties n local mode");
173             }
174         } catch (Exception JavaDoc e) {
175 // IASRI 4660742 e.printStackTrace(System.err);
176
// START OF IASRI 4660742
177
_logger.log(Level.SEVERE,"enterprise.setpropertry_exception",e);
178 // END OF IASRI 4660742
179
}
180     }
181
182     /**
183      * This method gets an Object associated with the given key.
184      * @return An Object corresponding to the key
185      */

186     public Object JavaDoc getObject(String JavaDoc key) {
187         Object JavaDoc obj = null;
188
189         try {
190             obj = config.getObject(key);
191         } catch (Exception JavaDoc e) {
192 // IASRI 4660742 e.printStackTrace(System.err);
193
// START OF IASRI 4660742
194
_logger.log(Level.SEVERE,"enterprise.getobject_exception",e);
195 // END OF IASRI 4660742
196
}
197         return obj;
198        
199     }
200
201     /**
202      * This method associates an Object with the given key.
203      */

204     public void setObject(String JavaDoc key, Object JavaDoc obj) {
205         try {
206             if (remote) {
207                 config.setObject(key, obj);
208         } else {
209                 throw new IllegalStateException JavaDoc("Cannot set objects in local mode");
210             }
211         } catch(Exception JavaDoc e) {
212 // IASRI 4660742 e.printStackTrace(System.err);
213
// START OF IASRI 4660742
214
_logger.log(Level.SEVERE,"enterprise.setobject_exception",e);
215 // END OF IASRI 4660742
216
}
217     }
218
219     /**
220      * This method returns all the keys for a given index.
221      *
222      */

223     public String JavaDoc[] getKeys(String JavaDoc index) {
224         String JavaDoc[] keys = null;
225
226         try {
227             keys = config.getKeys(index);
228         } catch(Exception JavaDoc e) {
229 // IASRI 4660742 e.printStackTrace(System.err);
230
// START OF IASRI 4660742
231
_logger.log(Level.SEVERE,"enterprise.getkey_exception",e);
232 // END OF IASRI 4660742
233
}
234         return keys;
235         
236     }
237
238     /**
239      * Return the subset of properties for a given index.
240      *
241      */

242     public Properties JavaDoc getProperties(String JavaDoc index) {
243         Properties JavaDoc props = new Properties JavaDoc();
244         try {
245             String JavaDoc[] keys = config.getKeys(index);
246             for (int i=0; i<keys.length; i++) {
247                 props.put(keys[i], getProperty(keys[i]));
248             }
249         } catch (Exception JavaDoc e) {
250 // IASRI 4660742 e.printStackTrace(System.err);
251
// START OF IASRI 4660742
252
_logger.log(Level.SEVERE,"enterprise.get_put_key_exception",e);
253 // END OF IASRI 4660742
254
}
255         return props;
256         
257     }
258
259     public void removeProperty(String JavaDoc key) {
260         try {
261             if (remote) {
262                 config.removeProperty(key);
263             } else {
264                 throw new IllegalStateException JavaDoc("Cannot remove properties in local mode");
265             }
266         } catch(Exception JavaDoc e) {
267 // IASRI 4660742 e.printStackTrace(System.err);
268
// START OF IASRI 4660742
269
_logger.log(Level.SEVERE,"enterprise.remove_property_exception",e);
270 // END OF IASRI 4660742
271
}
272     }
273
274     public void removeObject(String JavaDoc key) {
275         try {
276             if (remote) {
277                 config.removeObject(key);
278         } else {
279                 throw new IllegalStateException JavaDoc("Cannot remove objects in local mode");
280             }
281         } catch(Exception JavaDoc e) {
282 // IASRI 4660742 e.printStackTrace(System.err);
283
// START OF IASRI 4660742
284
_logger.log(Level.SEVERE,"enterprise.remove_object_exception",e);
285 // END OF IASRI 4660742
286
}
287     }
288 }
289
290
291
292
Popular Tags