1 64 65 package com.jcorporate.expresso.core.dataobjects; 66 67 import com.jcorporate.expresso.core.db.DBConfig; 68 import com.jcorporate.expresso.core.db.TypeMapper; 69 import com.jcorporate.expresso.kernel.ComponentLifecycle; 70 import com.jcorporate.expresso.kernel.Configuration; 71 import com.jcorporate.expresso.kernel.ContainerComponentBase; 72 import com.jcorporate.expresso.kernel.DataContext; 73 import com.jcorporate.expresso.kernel.ExpressoComponent; 74 import com.jcorporate.expresso.kernel.exception.ConfigurationException; 75 76 84 public class PersistenceManager extends ContainerComponentBase implements ComponentLifecycle { 85 86 89 private String dataContext; 90 91 94 private String configName; 95 96 99 private String dataURL; 100 101 104 private String userName; 105 106 109 private String password; 110 111 112 115 public PersistenceManager() { 116 } 117 118 121 public void initialize() { 122 123 } 124 125 132 public void configure(Configuration newConfig) throws ConfigurationException { 133 ExpressoComponent ec = (ExpressoComponent) this.getParent(); 134 if (!(ec instanceof DataContext)) { 135 throw new IllegalStateException ("Persistence Manager must be embedded directly under a DataContext object"); 136 } 137 138 dataContext = ec.getMetaData().getName(); 139 140 configName = (String ) newConfig.get("ConfigName"); 141 dataURL = (String ) newConfig.get("DataURL"); userName = (String ) newConfig.get("UserName"); password = (String ) newConfig.get("Password"); 145 if (configName == null || configName.length() == 0) { 146 if (dataURL == null || dataURL.length() == 0) { 147 throw new ConfigurationException("For a valid configuration," + 148 " a Database URL is required"); 149 } 150 } 151 152 if (dataContext == null) { 153 throw new ConfigurationException("Couldn't get a name for the data context."); 154 } 155 } 156 157 164 public void reconfigure(Configuration newConfig) throws ConfigurationException { 165 dataContext = null; 166 configName = null; 167 dataURL = null; 168 userName = null; 169 password = null; 170 configure(newConfig); 171 } 172 173 176 public void destroy() { 177 dataContext = null; 178 configName = null; 179 dataURL = null; 180 userName = null; 181 password = null; 182 } 183 184 189 public TypeMapper getTypeMapper() { 190 return (TypeMapper) this.locateComponent("TypeMapper"); 191 } 192 193 198 public DBConfig getDBConfig() { 199 return (DBConfig) this.locateComponent("DBConfig"); 200 } 201 202 208 public String getDataContext() { 209 return dataContext; 210 } 211 212 217 public void setConfigName(String configName) { 218 this.configName = configName; 219 } 220 221 226 public String getConfigName() { 227 return configName; 228 } 229 230 235 public void setDataURL(String dataURL) { 236 this.dataURL = dataURL; 237 } 238 239 244 245 public String getDataURL() { 246 return dataURL; 247 } 248 249 254 public void setUserName(String userName) { 255 this.userName = userName; 256 } 257 258 263 public String getUserName() { 264 return userName; 265 } 266 267 272 public void setPassword(String password) { 273 this.password = password; 274 } 275 276 281 public String getPassword() { 282 return password; 283 } 284 } 285 286 | Popular Tags |