1 19 20 21 package org.netbeans.modules.j2ee.sun.share.configbean; 22 23 import java.util.ArrayList ; 24 import java.util.Collection ; 25 26 import javax.enterprise.deploy.spi.DConfigBean ; 27 import javax.enterprise.deploy.spi.DeploymentConfiguration ; 28 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 29 import javax.enterprise.deploy.model.DDBean ; 30 31 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean; 32 import org.netbeans.modules.j2ee.sun.dd.api.web.SunWebApp; 33 import org.netbeans.modules.j2ee.sun.dd.api.web.SessionConfig; 34 import org.netbeans.modules.j2ee.sun.dd.api.web.SessionManager; 35 import org.netbeans.modules.j2ee.sun.dd.api.web.ManagerProperties; 36 import org.netbeans.modules.j2ee.sun.dd.api.web.StoreProperties; 37 import org.netbeans.modules.j2ee.sun.dd.api.web.SessionProperties; 38 import org.netbeans.modules.j2ee.sun.dd.api.web.CookieProperties; 39 40 41 67 72 public class SessionConfigSubBean { 73 74 private static final String SunWebFileName = "sun-web.xml"; 76 private static final String SESSION_CONFIG = "session-config"; 79 80 private WebAppRoot webAppRoot; 81 82 83 private String persistenceType; 84 85 86 private ManagerProperties managerProperties; 87 88 89 private StoreProperties storeProperties; 90 91 92 private SessionProperties sessionProperties; 93 94 95 private CookieProperties cookieProperties; 96 97 98 public SessionConfigSubBean() { 99 } 100 101 105 protected void init(WebAppRoot parent) { 106 webAppRoot = parent; 107 108 } 110 111 public Base getParent() { 112 return webAppRoot; 113 } 114 115 119 public String getPersistenceType() { 120 return this.persistenceType; 121 } 122 123 129 public void setPersistenceType(String newPersistenceType) throws java.beans.PropertyVetoException { 130 if(newPersistenceType == null || newPersistenceType.length() == 0) { newPersistenceType = null; 132 } 133 134 String oldPersistenceType = this.persistenceType; 135 getVCS().fireVetoableChange("persistenceType", oldPersistenceType, newPersistenceType); this.persistenceType = newPersistenceType; 137 getPCS().firePropertyChange("persistenceType", oldPersistenceType, persistenceType); } 139 140 144 public ManagerProperties getManagerProperties() { 145 return this.managerProperties; 146 } 147 148 154 public void setManagerProperties(ManagerProperties newManagerProperties) throws java.beans.PropertyVetoException { 155 if(newManagerProperties == null) { 156 newManagerProperties = webAppRoot.getConfig().getStorageFactory().createManagerProperties(); 157 } 158 159 ManagerProperties oldManagerProperties = this.managerProperties; 160 getVCS().fireVetoableChange("managerProperties", oldManagerProperties, newManagerProperties); this.managerProperties = newManagerProperties; 162 getPCS().firePropertyChange("managerProperties", oldManagerProperties, managerProperties); } 164 165 169 public StoreProperties getStoreProperties() { 170 return this.storeProperties; 171 } 172 173 179 public void setStoreProperties(StoreProperties newStoreProperties) throws java.beans.PropertyVetoException { 180 if(newStoreProperties == null) { 181 newStoreProperties = webAppRoot.getConfig().getStorageFactory().createStoreProperties(); 182 } 183 184 StoreProperties oldStoreProperties = this.storeProperties; 185 getVCS().fireVetoableChange("storeProperties", oldStoreProperties, newStoreProperties); this.storeProperties = newStoreProperties; 187 getPCS().firePropertyChange("storeProperties", oldStoreProperties, storeProperties); } 189 190 194 public SessionProperties getSessionProperties() { 195 return this.sessionProperties; 196 } 197 198 204 public void setSessionProperties(SessionProperties newSessionProperties) throws java.beans.PropertyVetoException { 205 if(newSessionProperties == null) { 206 newSessionProperties = webAppRoot.getConfig().getStorageFactory().createSessionProperties(); 207 } 208 209 SessionProperties oldSessionProperties = this.sessionProperties; 210 getVCS().fireVetoableChange("sessionProperties", oldSessionProperties, newSessionProperties); this.sessionProperties = newSessionProperties; 212 getPCS().firePropertyChange("sessionProperties", oldSessionProperties, sessionProperties); } 214 215 219 public CookieProperties getCookieProperties() { 220 return this.cookieProperties; 221 } 222 223 229 public void setCookieProperties(CookieProperties newCookieProperties) throws java.beans.PropertyVetoException { 230 if(newCookieProperties == null) { 231 newCookieProperties = webAppRoot.getConfig().getStorageFactory().createCookieProperties(); 232 } 233 234 CookieProperties oldCookieProperties = this.cookieProperties; 235 getVCS().fireVetoableChange("cookieProperties", oldCookieProperties, newCookieProperties); this.cookieProperties = newCookieProperties; 237 getPCS().firePropertyChange("cookieProperties", oldCookieProperties, cookieProperties); } 239 240 244 Collection getSnippets() { 245 Collection snippets = new ArrayList (); 246 Snippet snipOne = new Snippet() { 247 248 public org.netbeans.modules.schema2beans.BaseBean getCmpDDSnippet() { 249 return null; 250 } 251 252 public CommonDDBean getDDSnippet() { 253 SessionConfig sessionConfig = webAppRoot.getConfig().getStorageFactory().createSessionConfig(); 254 String version = webAppRoot.getAppServerVersion().getWebAppVersionAsString(); 255 256 SessionManager sessionManager = sessionConfig.newSessionManager(); 257 boolean hasSessionManager = false; 258 259 String persistenceType = getPersistenceType(); 261 if(Utils.notEmpty(persistenceType)) { 262 sessionManager.setPersistenceType(getPersistenceType()); 263 hasSessionManager = true; 264 } else { 265 sessionManager.setPersistenceType(null); 266 } 267 268 ManagerProperties mp = getManagerProperties(); 269 if(mp.sizeWebProperty() > 0) { 270 sessionManager.setManagerProperties((ManagerProperties) mp.cloneVersion(version)); 271 hasSessionManager = true; 272 } 273 274 StoreProperties sp = getStoreProperties(); 275 if(sp.sizeWebProperty() > 0) { 276 sessionManager.setStoreProperties((StoreProperties) sp.cloneVersion(version)); 277 hasSessionManager = true; 278 } 279 280 if(hasSessionManager) { 281 sessionConfig.setSessionManager(sessionManager); 282 } 283 284 SessionProperties ssp = getSessionProperties(); 285 if(ssp.sizeWebProperty() > 0) { 286 sessionConfig.setSessionProperties((SessionProperties) ssp.cloneVersion(version)); 287 } 288 289 CookieProperties cp = getCookieProperties(); 290 if(cp.sizeWebProperty() > 0) { 291 sessionConfig.setCookieProperties((CookieProperties) cp.cloneVersion(version)); 292 } 293 294 return sessionConfig; 295 } 296 297 public boolean hasDDSnippet() { 298 if(getPersistenceType() != null) { 299 return true; 300 } 301 302 ManagerProperties mp = getManagerProperties(); 303 if(mp.sizeWebProperty() > 0) { 304 return true; 305 } 306 307 StoreProperties sp = getStoreProperties(); 308 if(sp.sizeWebProperty() > 0) { 309 return true; 310 } 311 312 SessionProperties ssp = getSessionProperties(); 313 if(ssp.sizeWebProperty() > 0) { 314 return true; 315 } 316 317 CookieProperties cp = getCookieProperties(); 318 if(cp.sizeWebProperty() > 0) { 319 return true; 320 } 321 322 return false; 323 } 324 325 public String getPropertyName() { 326 return SunWebApp.SESSION_CONFIG; 327 } 328 329 333 public String getFileName() { 334 return SunWebFileName; } 336 337 public CommonDDBean mergeIntoRootDD(CommonDDBean ddRoot) { 338 SessionConfig sessionConfig = (SessionConfig) getDDSnippet(); 339 340 if(ddRoot instanceof SunWebApp) { 341 SunWebApp swa = (SunWebApp) ddRoot; 342 swa.setSessionConfig(sessionConfig); 343 } 344 345 return sessionConfig; 346 } 347 348 public CommonDDBean mergeIntoRovingDD(CommonDDBean ddParent) { 349 return mergeIntoRootDD(ddParent); 354 } 355 356 357 }; 358 359 snippets.add(snipOne); 360 return snippets; 361 } 362 363 private class SessionConfigFinder implements ConfigFinder { 364 public Object find(Object obj) { 365 SessionConfig result = null; 366 367 if(obj instanceof SunWebApp) { 368 SunWebApp swa = (SunWebApp) obj; 369 370 result = swa.getSessionConfig(); 371 } 372 373 return result; 374 } 375 } 376 377 boolean loadFromPlanFile(SunONEDeploymentConfiguration config) { 378 String uriText = webAppRoot.getUriText(); 379 380 SessionConfig beanGraph = (SessionConfig) config.getBeans( 381 uriText, SunWebFileName, webAppRoot.getParser(), new SessionConfigFinder()); 382 383 clearProperties(); 384 385 if(null != beanGraph) { 386 SessionManager sm = beanGraph.getSessionManager(); 387 if(sm != null) { 388 persistenceType = sm.getPersistenceType(); 389 390 ManagerProperties mp = sm.getManagerProperties(); 391 if(mp != null && mp.sizeWebProperty() > 0) { 392 managerProperties = (ManagerProperties) mp.clone(); 393 } 394 395 StoreProperties sp = sm.getStoreProperties(); 396 if(sp != null && sp.sizeWebProperty() > 0) { 397 storeProperties = (StoreProperties) sp.clone(); 398 } 399 } 400 401 SessionProperties ssp = beanGraph.getSessionProperties(); 402 if(ssp != null && ssp.sizeWebProperty() > 0) { 403 sessionProperties = (SessionProperties) ssp.clone(); 404 } 405 406 CookieProperties cp = beanGraph.getCookieProperties(); 407 if(cp != null && cp.sizeWebProperty() > 0) { 408 cookieProperties = (CookieProperties) cp.clone(); 409 } 410 } else { 411 setDefaultProperties(); 412 } 413 414 return (beanGraph != null); 415 } 416 417 protected void clearProperties() { 418 StorageBeanFactory beanFactory = webAppRoot.getConfig().getStorageFactory(); 419 420 persistenceType = null; 421 managerProperties = beanFactory.createManagerProperties(); 422 storeProperties = beanFactory.createStoreProperties(); 423 sessionProperties = beanFactory.createSessionProperties(); 424 cookieProperties = beanFactory.createCookieProperties(); 425 } 426 427 protected void setDefaultProperties() { 428 } 430 431 438 441 protected java.beans.PropertyChangeSupport getPCS() { 442 return webAppRoot.getPCS(); 443 } 444 445 448 protected java.beans.VetoableChangeSupport getVCS() { 449 return webAppRoot.getVCS(); 450 } 451 } 452 | Popular Tags |