1 19 package org.netbeans.modules.j2ee.sun.share.configbean; 20 21 import java.util.ArrayList ; 22 import java.util.Collection ; 23 import java.util.HashMap ; 24 import java.util.Iterator ; 25 import java.util.Map ; 26 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 27 import javax.enterprise.deploy.model.DDBean ; 28 import javax.enterprise.deploy.model.DDBeanRoot ; 29 30 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean; 31 import org.netbeans.modules.j2ee.sun.dd.api.RootInterface; 32 import org.netbeans.modules.j2ee.sun.dd.api.common.WebserviceEndpoint; 33 import org.netbeans.modules.j2ee.sun.dd.api.ejb.Ejb; 34 import org.netbeans.modules.j2ee.sun.dd.api.ejb.EnterpriseBeans; 35 import org.netbeans.modules.j2ee.sun.dd.api.ejb.SunEjbJar; 36 import org.netbeans.modules.j2ee.sun.dd.api.web.Servlet; 37 import org.netbeans.modules.j2ee.sun.dd.api.web.SunWebApp; 38 import org.netbeans.modules.j2ee.sun.share.configbean.Base.DefaultSnippet; 39 40 58 public class WebServices extends BaseRoot { 59 60 61 private EndpointHelper helper; 62 63 68 private Map savedEndpoints; 69 70 71 72 public WebServices() { 73 setDescriptorElement(bundle.getString("BDN_WebServices")); } 75 76 protected void init(DDBeanRoot dDBeanRoot, SunONEDeploymentConfiguration parent, DDBean ddbExtra) throws ConfigurationException { 77 super.init(dDBeanRoot, parent, ddbExtra); 78 80 BaseRoot masterRoot = parent.getMasterDCBRoot(); 81 if(masterRoot instanceof WebAppRoot) { 82 helper = servletHelper; 83 } else if(masterRoot instanceof EjbJarRoot) { 84 helper = ejbHelper; 85 } else { 86 throw new ConfigurationException ("Unexpected master DConfigBean type: " + masterRoot); } 88 89 loadFromPlanFile(parent); 90 } 91 92 public String generateDocType(ASDDVersion version) { 93 return getMasterRootBean().generateDocType(version); 94 } 95 96 97 100 public String getHelpId() { 101 return "AS_CFG_WebServices"; 102 } 103 104 public J2EEBaseVersion getJ2EEModuleVersion() { 105 return getMasterRootBean().getJ2EEModuleVersion(); 106 } 107 108 113 123 127 Collection getSnippets() { 128 Collection snippets = new ArrayList (); 129 Snippet snipOne = new DefaultSnippet() { 130 public CommonDDBean getDDSnippet() { 131 return null; 136 } 137 138 public CommonDDBean mergeIntoRovingDD(CommonDDBean ddParent) { 139 throw new UnsupportedOperationException (); 140 } 141 142 public CommonDDBean mergeIntoRootDD(CommonDDBean ddParent) { 143 if(ddParent instanceof RootInterface) { 151 153 RootInterface ddRoot = (RootInterface) ddParent; 154 String version = ddRoot.getVersion().toString(); 155 restoreAllNamedBeans(ddRoot, version); 156 } 157 158 return ddParent; 161 } 162 }; 163 164 snippets.add(snipOne); 165 return snippets; 166 } 167 168 public WebServiceDescriptor getWebServiceDescriptor(String wsName) { 169 WebServiceDescriptor result = null; 170 Iterator wsIter = getChildren().iterator(); 171 while(wsIter.hasNext()) { 172 WebServiceDescriptor wsBean = (WebServiceDescriptor) wsIter.next(); 173 if(wsBean.getWebServiceDescriptionName().equals(wsName)) { 174 result = wsBean; 175 break; 176 } 177 } 178 return result; 179 } 180 181 195 private class RootFinder implements ConfigFinder { 196 public Object find(Object obj) { 197 RootInterface result = null; 198 199 if(obj instanceof RootInterface) { 200 result = (RootInterface) obj; 201 } 202 203 return result; 204 } 205 } 206 207 protected ConfigParser getParser() { 208 return getMasterRootBean().getParser(); 209 } 210 211 boolean loadFromPlanFile(SunONEDeploymentConfiguration config) { 212 String uriText = getUriText(); 213 214 RootInterface beanGraph = (RootInterface) config.getBeans(uriText, 215 constructFileName(), getParser(), new RootFinder()); 216 217 clearProperties(); 218 219 if(beanGraph != null) { 220 CommonDDBean [] hosts = helper.getEndpointHosts(beanGraph); 225 if(hosts != null) { 226 for(int i = 0; i < hosts.length; i++) { 227 WebserviceEndpoint [] definedEndpoints = 228 (WebserviceEndpoint []) hosts[i].getValues(helper.getEndpointProperty()); 229 if(definedEndpoints != null && definedEndpoints.length > 0) { 230 String hostName = (String ) hosts[i].getValue(helper.getHostNameProperty()); 231 for(int j = 0; j < definedEndpoints.length; j++) { 232 saveEndpoint(hostName, definedEndpoints[j]); 233 } 234 } 235 } 236 } 237 238 saveAllNamedBeans(beanGraph); 240 } else { 241 setDefaultProperties(); 242 } 243 244 return (beanGraph != null); 245 } 246 247 protected void clearProperties() { 248 savedEndpoints = new HashMap (); 249 } 250 251 protected void setDefaultProperties() { 252 } 253 254 private static Collection webServiceBeanSpecs = new ArrayList (); 255 256 static { 257 webServiceBeanSpecs.add(new NamedBean(SunWebApp.WEBSERVICE_DESCRIPTION, 258 org.netbeans.modules.j2ee.sun.dd.api.common.WebserviceDescription.WEBSERVICE_DESCRIPTION_NAME)); 259 } 260 261 protected Collection getNamedBeanSpecs() { 262 return webServiceBeanSpecs; 263 } 264 265 protected String constructFileName() { 266 return getMasterRootBean().constructFileName(); 268 } 269 270 private BaseRoot getMasterRootBean() { 271 return getConfig().getMasterDCBRoot(); 272 } 273 274 277 private HashMap webServicesRootFactoryMap; 278 279 284 protected java.util.Map getXPathToFactoryMap() { 285 if(webServicesRootFactoryMap == null) { 286 webServicesRootFactoryMap = new HashMap (3); 287 webServicesRootFactoryMap.put("webservice-description", new DCBGenericFactory(WebServiceDescriptor.class)); } 289 290 return webServicesRootFactoryMap; 291 } 292 293 296 297 310 public void saveEndpoint(final String hostName, final WebserviceEndpoint endpoint) { 311 String key = hostName + endpoint.getPortComponentName(); 312 if(Utils.notEmpty(key) && savedEndpoints.get(key) == null) { 313 savedEndpoints.put(key, endpoint); 314 } 315 } 316 317 public WebserviceEndpoint removeEndpoint(final String linkName, final String portName) { 318 WebserviceEndpoint result = null; 319 String key = linkName + portName; 320 if(savedEndpoints != null && savedEndpoints.size() > 0 && Utils.notEmpty(key)) { 321 result = (WebserviceEndpoint) savedEndpoints.remove(key); 322 } 323 return result; 324 } 325 326 327 333 private final EndpointHelper servletHelper = new ServletHelper(); 334 private final EndpointHelper ejbHelper = new EjbHelper(); 335 336 private abstract class EndpointHelper { 337 338 private final String hostNameProperty; 339 private final String endpointProperty; 340 341 public EndpointHelper(String hnp, String epp) { 342 hostNameProperty = hnp; 343 endpointProperty = epp; 344 } 345 346 public String getHostNameProperty() { 347 return hostNameProperty; 348 } 349 350 public String getEndpointProperty() { 351 return endpointProperty; 352 } 353 354 public abstract CommonDDBean [] getEndpointHosts(RootInterface root); 355 356 } 357 358 private class ServletHelper extends EndpointHelper { 359 public ServletHelper() { 360 super(Servlet.SERVLET_NAME, Servlet.WEBSERVICE_ENDPOINT); 361 } 362 363 public CommonDDBean [] getEndpointHosts(RootInterface root) { 364 CommonDDBean [] result = (CommonDDBean []) root.getValues(SunWebApp.SERVLET); 365 return result; 366 } 367 } 368 369 private class EjbHelper extends EndpointHelper { 370 public EjbHelper() { 371 super(Ejb.EJB_NAME, Ejb.WEBSERVICE_ENDPOINT); 372 } 373 374 public CommonDDBean [] getEndpointHosts(RootInterface root) { 375 CommonDDBean [] result = null; 376 CommonDDBean enterpriseBeans = (CommonDDBean) root.getValue(SunEjbJar.ENTERPRISE_BEANS); 377 if(enterpriseBeans != null) { 378 result = (CommonDDBean []) enterpriseBeans.getValues(EnterpriseBeans.EJB); 379 } 380 return result; 381 } 382 } 383 } 384 | Popular Tags |