1 23 package com.sun.enterprise; 24 25 import java.rmi.RemoteException ; 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 34 import com.sun.enterprise.repository.IASJ2EEResourceFactoryImpl; 36 import javax.rmi.CORBA.Tie ; 38 import java.util.Properties ; 39 import java.util.logging.*; 41 import com.sun.logging.*; 42 44 49 public class ServerConfiguration { 50 51 private static Logger _logger=null; 53 static{ 54 _logger=LogDomains.getLogger(LogDomains.ROOT_LOGGER); 55 } 56 public static final String 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 76 return new IASJ2EEResourceFactoryImpl(); 78 } 80 81 private ServerConfiguration() { 82 try{ 83 config = (Configuration) Utility.lookupObject( 84 JNDI_NAME, Configuration.class); 85 } catch (Exception ne) { 86 try{ 93 config = new ConfigurationImpl(); 94 101 remote = false; 102 } catch(Exception e) { 103 if ( debug ) 104 _logger.log(Level.WARNING,"enterprise.config_create_error",e); 107 } 109 } 110 } 111 112 116 public String getProperty(String key) { 117 String val = null; 118 119 try { 120 val = config.getProperty(key); 121 } catch (Exception e) { 122 _logger.log(Level.SEVERE,"enterprise.getpropertry_exception",e); 125 } 127 return val; 128 129 } 130 131 137 public String getProperty(String key, String defaultvalue) { 138 String val = defaultvalue; 139 140 try { 141 val = config.getProperty(key); 142 } catch (Exception e) { 143 _logger.log(Level.SEVERE,"enterprise.getpropertry_exception",e); 146 } 148 if(val != null) { 149 return val; 150 } else { 151 return defaultvalue; 152 } 153 154 } 155 156 157 160 public void setProperty(String key, String value) { 161 try { 169 if (remote) { 170 config.setProperty(key, value); 171 } else { 172 throw new IllegalStateException ("Cannot set properties n local mode"); 173 } 174 } catch (Exception e) { 175 _logger.log(Level.SEVERE,"enterprise.setpropertry_exception",e); 178 } 180 } 181 182 186 public Object getObject(String key) { 187 Object obj = null; 188 189 try { 190 obj = config.getObject(key); 191 } catch (Exception e) { 192 _logger.log(Level.SEVERE,"enterprise.getobject_exception",e); 195 } 197 return obj; 198 199 } 200 201 204 public void setObject(String key, Object obj) { 205 try { 206 if (remote) { 207 config.setObject(key, obj); 208 } else { 209 throw new IllegalStateException ("Cannot set objects in local mode"); 210 } 211 } catch(Exception e) { 212 _logger.log(Level.SEVERE,"enterprise.setobject_exception",e); 215 } 217 } 218 219 223 public String [] getKeys(String index) { 224 String [] keys = null; 225 226 try { 227 keys = config.getKeys(index); 228 } catch(Exception e) { 229 _logger.log(Level.SEVERE,"enterprise.getkey_exception",e); 232 } 234 return keys; 235 236 } 237 238 242 public Properties getProperties(String index) { 243 Properties props = new Properties (); 244 try { 245 String [] 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 e) { 250 _logger.log(Level.SEVERE,"enterprise.get_put_key_exception",e); 253 } 255 return props; 256 257 } 258 259 public void removeProperty(String key) { 260 try { 261 if (remote) { 262 config.removeProperty(key); 263 } else { 264 throw new IllegalStateException ("Cannot remove properties in local mode"); 265 } 266 } catch(Exception e) { 267 _logger.log(Level.SEVERE,"enterprise.remove_property_exception",e); 270 } 272 } 273 274 public void removeObject(String key) { 275 try { 276 if (remote) { 277 config.removeObject(key); 278 } else { 279 throw new IllegalStateException ("Cannot remove objects in local mode"); 280 } 281 } catch(Exception e) { 282 _logger.log(Level.SEVERE,"enterprise.remove_object_exception",e); 285 } 287 } 288 } 289 290 291 292 | Popular Tags |