1 19 package org.netbeans.modules.j2ee.sun.share.configbean; 20 21 import java.io.IOException ; 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.HashMap ; 25 import java.util.List ; 26 import java.util.Map ; 27 28 import javax.enterprise.deploy.model.DDBean ; 29 import javax.enterprise.deploy.model.DDBeanRoot ; 30 import javax.enterprise.deploy.spi.DeploymentConfiguration ; 31 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 32 import javax.enterprise.deploy.spi.DConfigBean ; 33 import org.netbeans.modules.j2ee.sun.dd.api.client.JavaWebStartAccess; 34 35 import org.xml.sax.SAXException ; 36 37 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean; 38 import org.netbeans.modules.j2ee.sun.dd.api.DDException; 39 import org.netbeans.modules.j2ee.sun.dd.api.DDProvider; 40 import org.netbeans.modules.j2ee.sun.dd.api.VersionNotSupportedException; 41 import org.netbeans.modules.j2ee.sun.dd.api.client.SunApplicationClient; 42 import org.netbeans.modules.j2ee.sun.dd.api.common.MessageDestination; 43 44 import org.netbeans.modules.schema2beans.BaseBean; 45 46 47 61 public class AppClientRoot extends BaseRoot { 62 63 64 private List messageDestinations; 65 66 67 private String contextRoot; 68 69 70 private Boolean eligible; 71 72 73 private String vendor; 74 75 76 public AppClientRoot() { 77 setDescriptorElement(bundle.getString("BDN_AppClientRoot")); } 79 80 protected void init(DDBeanRoot dDBean, SunONEDeploymentConfiguration parent, DDBean ddbExtra) throws ConfigurationException { 81 super.init(dDBean, parent, ddbExtra); 82 loadFromPlanFile(parent); 83 } 84 85 88 public String getHelpId() { 89 return "AS_CFG_AppClient"; 90 } 91 92 96 public J2EEBaseVersion getJ2EEModuleVersion() { 97 DDBeanRoot ddbRoot = (DDBeanRoot ) getDDBean(); 98 99 String versionString = ddbRoot.getDDBeanRootVersion(); 101 if(versionString == null) { 102 versionString = ddbRoot.getModuleDTDVersion(); 104 } 105 106 J2EEBaseVersion appClientVersion = AppClientVersion.getAppClientVersion(versionString); 107 if(appClientVersion == null) { 108 appClientVersion = AppClientVersion.APP_CLIENT_1_4; 110 } 111 112 return appClientVersion; 113 } 114 115 118 public String generateDocType(ASDDVersion version) { 119 return generateDocType("sun-application-client", version.getSunAppClientPublicId(), version.getSunAppClientSystemId()); } 121 122 125 128 public String getContextRoot() { 129 return contextRoot; 130 } 131 132 137 public void setContextRoot(String newContextRoot) throws java.beans.PropertyVetoException { 138 newContextRoot = Utils.encodeUrlField(newContextRoot); 139 String oldContextRoot = contextRoot; 140 getVCS().fireVetoableChange("contextRoot", oldContextRoot, newContextRoot); contextRoot = newContextRoot; 142 getPCS().firePropertyChange("contextRoot", oldContextRoot, contextRoot); } 144 145 148 public boolean isEligible() { 149 return eligible != null ? eligible.booleanValue() : false; 150 } 151 152 157 public void setEligible(boolean newEligible) throws java.beans.PropertyVetoException { 158 Boolean oldEligible = eligible; 159 Boolean newEligibleAsBoolean = newEligible ? Boolean.TRUE : Boolean.FALSE; 160 getVCS().fireVetoableChange("eligible", oldEligible, newEligibleAsBoolean); 161 eligible = newEligibleAsBoolean; 162 getPCS().firePropertyChange("eligible", oldEligible, eligible); 163 164 } 165 166 169 public String getVendor() { 170 return vendor; 171 } 172 173 178 public void setVendor(String newVendor) throws java.beans.PropertyVetoException { 179 String oldVendor = vendor; 180 getVCS().fireVetoableChange("vendor", oldVendor, newVendor); vendor = newVendor; 182 getPCS().firePropertyChange("vendor", oldVendor, vendor); } 184 185 189 public List getMessageDestinations() { 190 return messageDestinations; 191 } 192 193 public MessageDestination getMessageDestination(int index) { 194 return (MessageDestination) messageDestinations.get(index); 195 } 196 197 203 public void setMessageDestinations(List newMessageDestinations) throws java.beans.PropertyVetoException { 204 List oldMessageDestinations = messageDestinations; 205 getVCS().fireVetoableChange("messageDestinations", oldMessageDestinations, newMessageDestinations); messageDestinations = newMessageDestinations; 207 getPCS().firePropertyChange("messageDestinations", oldMessageDestinations, messageDestinations); } 209 210 public void addMessageDestination(MessageDestination newMessageDestination) throws java.beans.PropertyVetoException { 211 getVCS().fireVetoableChange("messageDestination", null, newMessageDestination); if(messageDestinations == null) { 213 messageDestinations = new ArrayList (); 214 } 215 messageDestinations.add(newMessageDestination); 216 getPCS().firePropertyChange("messageDestination", null, newMessageDestination ); } 218 219 public void removeMessageDestination(MessageDestination oldMessageDestination) throws java.beans.PropertyVetoException { 220 getVCS().fireVetoableChange("messageDestination", oldMessageDestination, null); messageDestinations.remove(oldMessageDestination); 222 getPCS().firePropertyChange("messageDestination", oldMessageDestination, null ); } 224 225 229 Collection getSnippets() { 230 Collection snippets = new ArrayList (); 231 Snippet snipOne = new DefaultSnippet() { 232 233 public CommonDDBean getDDSnippet() { 234 SunApplicationClient sac = getConfig().getStorageFactory().createSunApplicationClient(); 235 String version = sac.getVersion().toString(); 236 237 try { 238 JavaWebStartAccess jwsa = sac.newJavaWebStartAccess(); 239 if(jwsa != null) { 240 boolean hasContent = false; 241 if(Utils.notEmpty(contextRoot)) { 242 jwsa.setContextRoot(contextRoot); 243 hasContent = true; 244 } 245 246 if(eligible != null) { 247 jwsa.setEligible(Boolean.toString(isEligible())); 248 hasContent = true; 249 } 250 251 if(Utils.notEmpty(vendor)) { 252 jwsa.setVendor(vendor); 253 hasContent = true; 254 } 255 256 if(hasContent) { 257 sac.setJavaWebStartAccess(jwsa); 258 } 259 } 260 } catch(VersionNotSupportedException ex) { 261 } 262 263 MessageDestination [] msgDests = (MessageDestination []) 264 Utils.listToArray(getMessageDestinations(), MessageDestination.class, version); 265 if(msgDests != null) { 266 sac.setMessageDestination(msgDests); 267 } 268 269 271 restoreAllNamedBeans(sac, version); 272 273 return sac; 274 } 275 }; 276 277 snippets.add(snipOne); 278 return snippets; 279 } 280 281 public class AppClientRootParser implements ConfigParser { 282 public Object parse(java.io.InputStream stream) throws IOException , SAXException , DDException { 283 DDProvider provider = DDProvider.getDefault(); 284 SunApplicationClient result = null; 285 286 if(stream != null) { 287 result = provider.getAppClientDDRoot(new org.xml.sax.InputSource (stream)); 289 } else { 290 result = (SunApplicationClient) provider.newGraph(SunApplicationClient.class, 292 getConfig().getAppServerVersion().getAppClientVersionAsString()); 293 } 294 295 getConfig().internalSetAppServerVersion(ASDDVersion.getASDDVersionFromAppClientVersion(result.getVersion())); 297 298 return result; 299 } 300 } 301 302 public class AppClientRootFinder implements ConfigFinder { 303 public Object find(Object obj) { 304 SunApplicationClient result = null; 305 if(obj instanceof SunApplicationClient) { 306 result = (SunApplicationClient) obj; 307 } 308 return result; 309 } 310 } 311 312 protected ConfigParser getParser() { 313 return new AppClientRootParser(); 314 } 315 316 boolean loadFromPlanFile(SunONEDeploymentConfiguration config) { 317 String uriText = getUriText(); 318 SunApplicationClient beanGraph = (SunApplicationClient) config.getBeans(uriText, constructFileName(), 319 getParser(), new AppClientRootFinder()); 320 321 clearProperties(); 322 323 if(null != beanGraph) { 324 try { 325 JavaWebStartAccess jwsa = beanGraph.getJavaWebStartAccess(); 326 if(jwsa != null) { 327 contextRoot = jwsa.getContextRoot(); 328 vendor = jwsa.getVendor(); 329 330 String eligibleAsString = jwsa.getEligible(); 331 if(eligibleAsString != null) { 332 eligible = Utils.booleanValueOf(eligibleAsString) ? Boolean.TRUE : Boolean.FALSE; 333 } 334 } 335 } catch (VersionNotSupportedException ex) { 336 } 337 338 messageDestinations = Utils.arrayToList(beanGraph.getMessageDestination()); 339 340 saveAllNamedBeans(beanGraph); 342 } else { 343 setDefaultProperties(); 344 } 345 346 return (beanGraph != null); 347 } 348 349 protected void clearProperties() { 350 contextRoot = null; 351 eligible = null; 352 vendor = null; 353 messageDestinations = null; 354 } 355 356 protected void setDefaultProperties() { 357 } 358 359 private static Collection appClientBeanSpecs = new ArrayList (); 360 361 static { 362 appClientBeanSpecs.addAll(getCommonNamedBeanSpecs()); 363 } 366 367 protected Collection getNamedBeanSpecs() { 368 return appClientBeanSpecs; 369 } 370 371 374 private HashMap appClientRootMap; 375 376 381 protected Map getXPathToFactoryMap() { 382 if(appClientRootMap == null) { 383 appClientRootMap = new HashMap (17); 384 385 appClientRootMap.put("ejb-ref", new DCBGenericFactory(EjbRef.class)); appClientRootMap.put("resource-ref", new DCBGenericFactory(ResourceRef.class)); appClientRootMap.put("resource-env-ref", new DCBGenericFactory(ResourceEnvRef.class)); 389 J2EEBaseVersion moduleVersion = getJ2EEModuleVersion(); 390 if(moduleVersion.compareTo(AppClientVersion.APP_CLIENT_1_4) >= 0) { 391 appClientRootMap.put("service-ref", new DCBGenericFactory(ServiceRef.class)); 394 if(moduleVersion.compareTo(AppClientVersion.APP_CLIENT_5_0) >= 0) { 395 appClientRootMap.put("message-destination-ref", new DCBGenericFactory(MessageDestinationRef.class)); } 397 } 398 } 399 400 return appClientRootMap; 401 } 402 } 403 | Popular Tags |