1 19 package org.netbeans.modules.j2ee.sun.share.configbean; 20 21 import java.beans.PropertyVetoException ; 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.HashMap ; 25 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 26 import javax.enterprise.deploy.model.DDBean ; 27 import javax.enterprise.deploy.model.XpathEvent ; 28 29 import org.openide.ErrorManager; 30 31 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean; 32 import org.netbeans.modules.j2ee.sun.dd.api.ejb.Ejb; 33 import org.netbeans.modules.j2ee.sun.dd.api.ejb.EnterpriseBeans; 34 import org.netbeans.modules.j2ee.sun.dd.api.ejb.BeanCache; 35 import org.netbeans.modules.j2ee.sun.dd.api.ejb.BeanPool; 36 import org.netbeans.modules.j2ee.sun.dd.api.ejb.IorSecurityConfig; 37 import org.netbeans.modules.j2ee.sun.dd.api.ejb.Principal; 38 39 43 public abstract class BaseEjb extends Base { 44 45 47 public static final String EJB_NAME = "ejbName"; 49 50 private DDBean ejbNameDD; 51 52 53 private String jndiName; 54 55 56 private String passByReference; 57 58 59 private String principalName; 60 61 62 private IorSecurityConfig iorSecurityConfig; 63 64 65 private BeanPool beanPool; 66 67 68 private BeanCache beanCache; 69 70 71 72 public BaseEjb() { 73 setDescriptorElement(bundle.getString("BDN_BaseEjb")); } 75 76 protected void init(DDBean dDBean, Base parent) throws ConfigurationException { 77 super.init(dDBean,parent); 78 79 ejbNameDD = getNameDD("ejb-name"); 81 updateNamedBeanCache(EnterpriseBeans.EJB); 82 83 loadFromPlanFile(getConfig()); 84 } 85 86 protected String getComponentName() { 87 return getEjbName(); 88 } 89 90 95 public void notifyDDChange(XpathEvent xpathEvent) { 96 super.notifyDDChange(xpathEvent); 97 98 if(ejbNameDD == xpathEvent.getBean()) { 99 getPCS().firePropertyChange(EJB_NAME, "", getEjbName()); 101 getPCS().firePropertyChange(DISPLAY_NAME, "", getDisplayName()); 102 103 updateNamedBeanCache(EnterpriseBeans.EJB); 104 } 105 } 106 107 111 protected class BaseEjbSnippet extends DefaultSnippet { 112 public CommonDDBean getDDSnippet() { 113 Ejb ejb = getConfig().getStorageFactory().createEjb(); 114 String version = getAppServerVersion().getEjbJarVersionAsString(); 115 116 ejb.setEjbName(getEjbName()); 117 118 if(null != jndiName){ 119 ejb.setJndiName(getJndiName()); 120 } 121 122 if (null != passByReference) { 123 ejb.setPassByReference(passByReference); 124 } 125 126 if (null != principalName) { 127 Principal principal = ejb.newPrincipal(); 128 principal.setName(principalName); 129 ejb.setPrincipal(principal); 130 } 131 132 IorSecurityConfig iorSecConf = getIorSecurityConfig(); 133 if(null != iorSecConf){ 134 ejb.setIorSecurityConfig((IorSecurityConfig)iorSecConf.cloneVersion(version)); 135 } 136 137 BeanPool beanPool = getBeanPool(); 138 if(null != beanPool){ 139 ejb.setBeanPool((BeanPool)beanPool.cloneVersion(version)); 140 } 141 142 BeanCache beanCache = getBeanCache(); 143 if(null != beanCache){ 144 ejb.setBeanCache((BeanCache)beanCache.cloneVersion(version)); 145 } 146 147 149 restoreAllNamedBeans(ejb, version); 150 151 return ejb; 152 } 153 154 public String getPropertyName() { 155 return EnterpriseBeans.EJB; 156 } 157 158 public boolean hasDDSnippet() { 159 if(null != jndiName){ 160 return true; 161 } 162 163 if (null != passByReference) { 164 return true; 165 } 166 167 if (null != principalName) { 168 return true; 169 } 170 171 if(null != getIorSecurityConfig()){ 172 return true; 173 } 174 175 if(null != getBeanPool()){ 176 return true; 177 } 178 179 if(null != getBeanCache()){ 180 return true; 181 } 182 183 Collection childList = getChildren(); 185 if(childList.size() > 0){ 186 return true; 187 } 188 189 return false; 190 } 191 } 192 193 217 private class EjbFinder extends NameBasedFinder { 218 public EjbFinder(String beanName) { 219 super(Ejb.EJB_NAME, beanName, Ejb.class); 220 } 221 } 222 223 boolean loadFromPlanFile(SunONEDeploymentConfiguration config) { 224 String uriText = getUriText(); 225 226 Ejb ejb = (Ejb) config.getBeans(uriText, constructFileName(), getParser(), 227 new EjbFinder(getEjbName())); 228 229 clearProperties(); 230 231 if(null != ejb) { 232 loadEjbProperties(ejb); 233 234 saveAllNamedBeans(ejb); 236 } else { 237 setDefaultProperties(); 238 } 239 240 return (ejb != null); 241 } 242 243 protected void loadEjbProperties(Ejb savedEjb) { 244 String val = savedEjb.getJndiName(); 245 if(null != val) { 246 this.jndiName = val.trim(); 247 } 248 249 val = savedEjb.getPassByReference(); 250 if(null != val) { 251 this.passByReference = val.trim(); 252 } 253 254 Principal principal = savedEjb.getPrincipal(); 255 if(null != principal){ 256 String name = principal.getName(); 257 assert(name != null); 258 this.principalName = name; 259 } 260 261 IorSecurityConfig iorSecurityConfig = savedEjb.getIorSecurityConfig(); 262 if(null != iorSecurityConfig){ 263 this.iorSecurityConfig = iorSecurityConfig; 264 } 265 266 BeanPool beanPool = savedEjb.getBeanPool(); 267 if(null != beanPool){ 268 this.beanPool = beanPool; 269 } 270 271 BeanCache beanCache = savedEjb.getBeanCache(); 272 if(null != beanCache){ 273 this.beanCache = beanCache; 274 } 275 } 276 277 protected void clearProperties() { 278 jndiName = null; 279 passByReference = null; 280 principalName = null; 281 iorSecurityConfig = null; 282 beanPool = null; 283 beanCache = null; 284 } 285 286 protected void setDefaultProperties() { 287 if(requiresJndiName()) { 290 jndiName = getDefaultJndiName(); 291 getConfig().getMasterDCBRoot().setDirty(); 292 } 293 } 294 295 protected String getDefaultJndiName() { 296 return "ejb/" + getEjbName(); } 298 299 protected boolean requiresJndiName() { 300 boolean needsJndi = super.requiresJndiName(); 302 303 if(needsJndi) { 304 DDBean [] remoteDDBeans = getDDBean().getChildBean("remote"); if(!(remoteDDBeans.length > 0 && remoteDDBeans[0] != null)) { 309 needsJndi = false; 311 } 312 } 313 314 return needsJndi; 315 } 316 317 private static Collection ejbBeanSpecs = new ArrayList (); 318 319 static { 320 ejbBeanSpecs.addAll(getCommonNamedBeanSpecs()); 321 } 322 323 protected Collection getNamedBeanSpecs() { 324 return ejbBeanSpecs; 325 } 326 327 330 private HashMap baseEjbFactoryMap; 331 332 342 protected java.util.Map getXPathToFactoryMap() { 343 if(baseEjbFactoryMap == null) { 344 baseEjbFactoryMap = new HashMap (17); 345 346 baseEjbFactoryMap.put("ejb-ref", new DCBGenericFactory(EjbRef.class)); baseEjbFactoryMap.put("resource-ref", new DCBGenericFactory(ResourceRef.class)); baseEjbFactoryMap.put("resource-env-ref", new DCBGenericFactory(ResourceEnvRef.class)); 350 J2EEBaseVersion moduleVersion = getJ2EEModuleVersion(); 351 if(moduleVersion.compareTo(EjbJarVersion.EJBJAR_2_1) >= 0) { 352 baseEjbFactoryMap.put("service-ref", new DCBGenericFactory(ServiceRef.class)); 354 if(moduleVersion.compareTo(EjbJarVersion.EJBJAR_3_0) >= 0) { 355 baseEjbFactoryMap.put("message-destination-ref", new DCBGenericFactory(MessageDestinationRef.class)); } 357 } 358 } 359 return baseEjbFactoryMap; 360 } 361 362 366 367 370 public String getEjbName() { 371 return cleanDDBeanText(ejbNameDD); 372 } 373 374 377 public String getJndiName() { 378 return this.jndiName; 379 } 380 381 385 public void setJndiName(String jndiName) throws java.beans.PropertyVetoException { 386 String oldJndiName = this.jndiName; 387 getVCS().fireVetoableChange("jndiName", oldJndiName, jndiName); 388 this.jndiName = jndiName; 389 getPCS().firePropertyChange("jndiName", oldJndiName, jndiName); 390 } 391 392 395 public String getPassByReference() { 396 return this.passByReference; 397 } 398 399 405 public void setPassByReference(String passByReference) throws java.beans.PropertyVetoException { 406 String oldPassByReference = this.passByReference; 407 getVCS().fireVetoableChange("passByReference", oldPassByReference, passByReference); 408 this.passByReference = passByReference; 409 getPCS().firePropertyChange("passByReference", oldPassByReference, passByReference); 410 } 411 412 416 public String getPrincipalName() { 417 return this.principalName; 418 } 419 420 426 public void setPrincipalName(String principalName) throws java.beans.PropertyVetoException { 427 String oldPrincipalName = this.principalName; 428 getVCS().fireVetoableChange("principalName", oldPrincipalName, principalName); 429 this.principalName = principalName; 430 getPCS().firePropertyChange("principalName", oldPrincipalName, principalName); 431 } 432 433 437 public IorSecurityConfig getIorSecurityConfig() { 438 return this.iorSecurityConfig; 439 } 440 441 447 public void setIorSecurityConfig(IorSecurityConfig iorSecurityConfig) throws java.beans.PropertyVetoException { 448 IorSecurityConfig oldIorSecurityConfig = this.iorSecurityConfig; 449 getVCS().fireVetoableChange("iorSecurityConfig", oldIorSecurityConfig, iorSecurityConfig); 450 this.iorSecurityConfig = iorSecurityConfig; 451 getPCS().firePropertyChange("iorSecurityConfig", oldIorSecurityConfig, iorSecurityConfig); 452 } 453 454 458 public BeanPool getBeanPool() { 459 return this.beanPool; 460 } 461 462 468 public void setBeanPool(BeanPool beanPool) throws java.beans.PropertyVetoException { 469 BeanPool oldBeanPool = this.beanPool; 470 getVCS().fireVetoableChange("beanPool", oldBeanPool, beanPool); 471 this.beanPool = beanPool; 472 getPCS().firePropertyChange("beanPool", oldBeanPool, beanPool); 473 } 474 475 479 public BeanCache getBeanCache() { 480 return this.beanCache; 481 } 482 483 489 public void setBeanCache(BeanCache beanCache) throws java.beans.PropertyVetoException { 490 BeanCache oldBeanCache = this.beanCache; 491 getVCS().fireVetoableChange("beanCache", oldBeanCache, beanCache); 492 this.beanCache = beanCache; 493 getPCS().firePropertyChange("beanCache", oldBeanCache, beanCache); 494 } 495 496 500 public ConfigQuery.InterfaceData getEJBMethods() { 501 503 java.util.List hi = new ArrayList (); 504 hi.add(new ConfigQuery.MethodData("home_method1", java.util.Arrays.asList(new String [] { "arg1", "arg2" } ))); 505 506 java.util.List ri = new ArrayList (); 507 ri.add(new ConfigQuery.MethodData("remote_method1", java.util.Arrays.asList(new String [] { "arg1", "arg2", "arg3" } ))); 508 ri.add(new ConfigQuery.MethodData("remote_method2", java.util.Arrays.asList(new String [] { "arg1" } ))); 509 510 java.util.List lhi = new ArrayList (); 511 lhi.add(new ConfigQuery.MethodData("local_home_method1", java.util.Arrays.asList(new String [] { "arg1", "arg2" } ))); 512 513 java.util.List li = new ArrayList (); 514 li.add(new ConfigQuery.MethodData("local_method1", java.util.Arrays.asList(new String [] { "arg1", "arg2" } ))); 515 li.add(new ConfigQuery.MethodData("local_method2", java.util.Arrays.asList(new String [] { "arg1" } ))); 516 li.add(new ConfigQuery.MethodData("local_method3", java.util.Arrays.asList(new String [] { "arg1", "arg2", "arg3" } ))); 517 518 return new ConfigQuery.InterfaceData(hi, ri, lhi, li); 519 } 520 } 521 | Popular Tags |