| 1 17 18 package org.sape.carbon.core.bootstrap; 19 20 import java.io.IOException ; 21 import java.io.InputStream ; 22 import java.net.URL ; 23 import java.util.Properties ; 24 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 28 29 39 final class DeploymentProperties { 40 41 private Log log = LogFactory.getLog(this.getClass()); 42 43 46 private static final String DEPLOYMENT_CONFIG_FILE_NAME = 47 "CarbonDeploymentConfig.properties"; 48 49 50 private final Properties deploymentProperties = fetchDeploymentProperties(); 51 52 75 public String get(String key) { 76 77 String value = System.getProperty(key); 78 79 if (value == null || value.equals("")) { 80 synchronized (this) { 81 value = this.deploymentProperties.getProperty(key); 82 } 83 } 84 85 return value; 86 } 87 88 106 public Object set(String key, String value) { 107 if (System.getProperties().contains(key)) { 108 return System.setProperty(key, value); 109 } else { 110 synchronized (this) { 111 if (value == null) { 112 return this.deploymentProperties.remove(key); 113 } else { 114 return this.deploymentProperties.setProperty(key, value); 115 } 116 } 117 } 118 } 119 120 125 private Properties fetchDeploymentProperties() { 126 127 log.trace("Attempting to load deployment properties"); 128 129 ClassLoader classLoader = BootStrapper.class.getClassLoader(); 132 URL bootConfigURL = 133 classLoader.getResource( 134 DeploymentProperties.DEPLOYMENT_CONFIG_FILE_NAME); 135 136 Properties bootProperties = new Properties (); 137 if (bootConfigURL == null) { 138 log.info( 139 "Deployment properties file [" 140 + DeploymentProperties.DEPLOYMENT_CONFIG_FILE_NAME 141 + "] not found by ClassLoader, " 142 + "that's OK, none will be used"); 143 144 } else { 145 146 InputStream bootConfigInputStream = null; 147 try { 148 log.info( 149 "Loading Deployment Properties resource from " 150 + "ClassLoader: [" 151 + bootConfigURL 152 + "]"); 153 154 bootConfigInputStream = bootConfigURL.openStream(); 156 bootProperties.load(bootConfigInputStream); 157 158 } catch (IOException ioe) { 159 log.warn( 160 "Deployment properties file could not be 'read'\n" 161 + "Filename = [" 162 + bootConfigURL.getPath() 163 + "], none will be used", ioe); 164 165 } finally { 166 if (bootConfigInputStream != null) { 168 try { 169 bootConfigInputStream.close(); 170 } catch (IOException ioe) { 171 } 173 } 174 } 175 } 176 return bootProperties; 177 } 178 } 179 | Popular Tags |