1 64 package com.jcorporate.expresso.kernel; 65 66 import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap; 67 import com.jcorporate.expresso.kernel.exception.ConfigurationException; 68 import org.apache.log4j.Logger; 69 70 import java.util.Collections ; 71 import java.util.Map ; 72 73 85 public class DataContext extends ContainerComponentBase implements ComponentLifecycle { 86 static Logger log = Logger.getLogger(DataContext.class); 87 88 private Map setupValues; 89 90 private Map customProperties; 91 92 private String securityContext; 93 94 private Boolean hasSetupTables = Boolean.TRUE; 95 96 private String contextDescription = "Default Context"; 97 private boolean mailDebug; 98 99 102 public DataContext() { 103 104 } 105 106 114 public synchronized String getSetupValue(String key) { 115 return (String ) setupValues.get(key); 116 } 117 118 124 public synchronized void setSetupValue(String key, String object) { 125 setupValues.put(key, object); 126 } 127 128 134 public synchronized Map getSetupValues() { 135 return Collections.unmodifiableMap(setupValues); 136 } 137 138 144 public synchronized void setSecurityContext(String newValue) { 145 securityContext = newValue; 146 } 147 148 154 public synchronized String getSecurityContext() { 155 String returnValue = this.securityContext; 156 if (securityContext == null || securityContext.length() == 0) { 157 returnValue = this.getMetaData().getName(); 158 } 159 160 return returnValue; 161 } 162 163 167 public synchronized void initialize() { 168 if (log.isDebugEnabled()) { 169 log.debug("Initialing DataContext Container"); 170 } 171 setupValues = new ConcurrentReaderHashMap(1); 172 } 173 174 182 public synchronized void configure(Configuration newConfig) throws ConfigurationException { 183 Map newSetupValues = newConfig.getMappedProperties("SetupValue"); 184 if (newSetupValues != null) { 185 this.setupValues = new ConcurrentReaderHashMap(newSetupValues); 186 } 187 188 Map customProperties = newConfig.getMappedProperties("CustomProperty"); 189 if (customProperties != null) { 190 this.customProperties = new ConcurrentReaderHashMap(customProperties); 191 } 192 193 this.setContextDescription((String ) newConfig.get("ContextDescription")); 194 this.setSecurityContext((String ) newConfig.get("SecurityContext")); 195 this.setHasSetupTables((Boolean ) newConfig.get("HasSetupTables")); 196 this.setMailDebug((Boolean ) newConfig.get("MailDebug")); 197 } 198 199 206 public synchronized void reconfigure(Configuration newConfig) throws ConfigurationException { 207 setupValues = null; 208 customProperties = null; 209 securityContext = null; 210 contextDescription = null; 211 setHasSetupTables(null); 212 213 configure(newConfig); 214 } 215 216 221 public synchronized void destroy() { 222 if (log.isDebugEnabled()) { 223 log.debug("Destroying DataContext Container name: " 224 + this.getMetaData().getName()); 225 } 226 setupValues = null; 227 securityContext = null; 228 } 229 230 237 public synchronized void setHasSetupTables(Boolean hasSetupTables) { 238 this.hasSetupTables = hasSetupTables; 239 } 240 241 247 public synchronized boolean isSetupTables() { 248 return hasSetupTables.booleanValue(); 249 } 250 251 257 public synchronized Boolean getHasSetupTables() { 258 return hasSetupTables; 259 } 260 261 266 public synchronized void setContextDescription(String contextDescription) { 267 this.contextDescription = contextDescription; 268 } 269 270 275 public synchronized String getContextDescription() { 276 return contextDescription; 277 } 278 279 286 public synchronized Map getCustomProperties() { 287 return customProperties; 288 } 289 290 296 public synchronized String getCustomProperty(String key) { 297 return (String ) customProperties.get(key); 298 } 299 300 306 public void setMailDebug(Boolean mailDebug) { 307 this.mailDebug = mailDebug.booleanValue(); 308 } 309 310 public void setMailDebug(boolean mailDebug) { 311 this.mailDebug = mailDebug; 312 } 313 314 315 public boolean isMailDebug() { 316 return mailDebug; 317 } 318 } | Popular Tags |