1 19 20 21 package org.netbeans.modules.j2ee.sun.share.configbean; 22 23 import java.util.ArrayList ; 24 import java.util.Collection ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 28 import javax.enterprise.deploy.model.DDBean ; 29 import javax.enterprise.deploy.model.DDBeanRoot ; 30 import javax.enterprise.deploy.model.DeployableObject ; 31 import javax.enterprise.deploy.model.exceptions.DDBeanCreateException; 32 import javax.enterprise.deploy.model.XpathEvent ; 33 34 import org.openide.ErrorManager; 35 36 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean; 37 import org.netbeans.modules.j2ee.sun.dd.api.VersionNotSupportedException; 38 import org.netbeans.modules.j2ee.sun.dd.api.common.CallProperty; 39 import org.netbeans.modules.j2ee.sun.dd.api.common.MessageSecurityBinding; 40 import org.netbeans.modules.j2ee.sun.dd.api.common.PortInfo; 41 import org.netbeans.modules.j2ee.sun.dd.api.common.WsdlPort; 42 import org.netbeans.modules.j2ee.sun.dd.api.web.SunWebApp; 43 44 import org.netbeans.modules.j2ee.sun.share.configbean.Base.DefaultSnippet; 45 46 47 75 public class ServiceRef extends Base { 76 77 79 public static final String SERVICE_REF_NAME = "serviceRefName"; 81 82 private DDBean serviceRefNameDD; 83 84 85 private List ports; 86 87 88 private List callProperties; 89 90 91 private String wsdlOverride; 92 93 94 96 97 99 100 public ServiceRef() { 101 setDescriptorElement(bundle.getString("BDN_ServiceRef")); } 103 104 109 protected void init(DDBean dDBean, Base parent) throws ConfigurationException { 110 super.init(dDBean, parent); 111 dDBean.addXpathListener(dDBean.getXpath(), this); 112 115 serviceRefNameDD = getNameDD("service-ref-name"); 117 updateNamedBeanCache(SunWebApp.SERVICE_REF); 118 119 loadFromPlanFile(getConfig()); 120 } 121 122 protected String getComponentName() { 123 return getServiceRefName(); 124 } 125 126 129 public String getHelpId() { 130 return "AS_CFG_ServiceRefGeneral"; 131 } 132 133 138 public void notifyDDChange(XpathEvent xpathEvent) { 139 super.notifyDDChange(xpathEvent); 140 141 if(serviceRefNameDD == xpathEvent.getBean()) { 142 getPCS().firePropertyChange(SERVICE_REF_NAME, "", getServiceRefName()); 144 getPCS().firePropertyChange(DISPLAY_NAME, "", getDisplayName()); 145 146 updateNamedBeanCache(SunWebApp.SERVICE_REF); 147 } 148 } 149 150 154 public String getServiceRefName() { 155 return cleanDDBeanText(serviceRefNameDD); 156 } 157 158 162 Collection getSnippets() { 163 Collection snippets = new ArrayList (); 164 Snippet snipOne = new DefaultSnippet() { 165 public CommonDDBean getDDSnippet() { 166 org.netbeans.modules.j2ee.sun.dd.api.common.ServiceRef serviceRef = 167 getConfig().getStorageFactory().createServiceRef(); 168 String version = getAppServerVersion().getEjbJarVersionAsString(); 169 170 String sn = getServiceRefName(); 172 if(sn != null) { 173 serviceRef.setServiceRefName(sn); 174 } 175 176 if(wsdlOverride != null && wsdlOverride.length() > 0) { 177 serviceRef.setWsdlOverride(wsdlOverride); 178 } 179 180 PortInfo [] portInfos = (PortInfo []) 181 Utils.listToArray(getPortInfos(), PortInfo.class, version); 182 if(portInfos != null) { 183 serviceRef.setPortInfo(portInfos); 184 } 185 186 CallProperty [] callProps = (CallProperty []) 187 Utils.listToArray(getCallProperties(), CallProperty.class, version); 188 if(callProps != null) { 189 serviceRef.setCallProperty(callProps); 190 } 191 192 return serviceRef; 193 } 194 195 public boolean hasDDSnippet() { 196 if(wsdlOverride != null && wsdlOverride.length() > 0) { 197 return true; 198 } 199 200 if(ports != null && ports.size() > 0) { 201 return true; 202 } 203 204 if(callProperties != null && callProperties.size() > 0) { 205 return true; 206 } 207 208 return false; 209 } 210 211 public String getPropertyName() { 212 return SunWebApp.SERVICE_REF; 213 } 214 }; 215 216 snippets.add(snipOne); 217 return snippets; 218 } 219 220 private class ServiceRefFinder extends NameBasedFinder { 221 public ServiceRefFinder(String beanName) { 222 super(org.netbeans.modules.j2ee.sun.dd.api.common.ServiceRef.SERVICE_REF_NAME, 223 beanName, org.netbeans.modules.j2ee.sun.dd.api.common.ServiceRef.class); 224 } 225 } 226 227 boolean loadFromPlanFile(SunONEDeploymentConfiguration config) { 228 String uriText = getUriText(); 229 230 org.netbeans.modules.j2ee.sun.dd.api.common.ServiceRef beanGraph = 231 (org.netbeans.modules.j2ee.sun.dd.api.common.ServiceRef) config.getBeans(uriText, 232 constructFileName(), getParser(), new ServiceRefFinder(getServiceRefName())); 233 234 clearProperties(); 235 236 if(beanGraph != null) { 237 wsdlOverride = beanGraph.getWsdlOverride(); 238 ports = Utils.arrayToList(beanGraph.getPortInfo()); 239 callProperties = Utils.arrayToList(beanGraph.getCallProperty()); 240 } else { 241 setDefaultProperties(); 242 } 243 244 return (beanGraph != null); 245 } 246 247 protected void clearProperties() { 248 wsdlOverride = null; 249 ports = null; 250 callProperties = null; 251 } 252 253 protected void setDefaultProperties() { 254 setDefaultPorts(); 255 getConfig().getMasterDCBRoot().setDirty(); 256 } 257 258 private void setDefaultPorts() { 259 List portInfoList = getDefaultPortInfos(); 260 try { 261 setPortInfos(portInfoList); 262 } catch(java.beans.PropertyVetoException ex) { 263 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 265 } 266 } 267 268 private List getDefaultPortInfos() { 269 List result = new ArrayList (); 270 try { 271 DeployableObject dobj = getConfig().getDeployableObject(); 272 273 DDBeanRoot webRootDD = dobj.getDDBeanRoot("WEB-INF/web.xml"); if(webRootDD == null) { 276 jsr88Logger.warning("ServiceRef.getDefaultServiceRefs() failed to retrieve web DDRoot via xpath. Using fallback method."); 277 } 278 279 if(webRootDD != null) { 280 DDBean [] serviceRefNameDDBean = 281 webRootDD.getChildBean("web-app/service-ref/service-ref-name"); for(int i = 0; i < serviceRefNameDDBean.length; i++) { 284 if(serviceRefNameDD.getText().equals(serviceRefNameDDBean[i].getText())) { 285 DDBean [] portComponentRefDDs = 286 serviceRefNameDDBean[i].getChildBean("../port-component-ref"); String serviceEndpointInterface = null; 288 for(int j = 0; j < portComponentRefDDs.length; j++) { 289 DDBean [] serviceEndpointInterfaceDD = 290 portComponentRefDDs[j].getChildBean("service-endpoint-interface"); if(serviceEndpointInterfaceDD != null && serviceEndpointInterfaceDD.length > 0) { 292 serviceEndpointInterface = serviceEndpointInterfaceDD[0].getText(); 293 if(serviceEndpointInterface != null){ 294 PortInfo portInfo = getConfig().getStorageFactory().createPortInfo(); 295 portInfo.setServiceEndpointInterface(serviceEndpointInterface); 296 result.add(portInfo); 297 } 298 } 299 } 300 } 301 } 302 } 303 } catch(DDBeanCreateException ex) { 304 jsr88Logger.warning(ex.getMessage()); 305 } catch(java.io.FileNotFoundException ex) { 306 jsr88Logger.warning(ex.getMessage()); 307 } catch(java.lang.NullPointerException ex) { 308 jsr88Logger.warning(ex.getMessage()); 311 } 312 313 return result; 314 } 315 316 319 320 323 public String getWsdlOverride() { 324 return wsdlOverride; 325 } 326 327 332 public void setWsdlOverride(String newWsdlOverride) throws java.beans.PropertyVetoException { 333 String oldWsdlOverride = wsdlOverride; 334 getVCS().fireVetoableChange("wsdlOverride", oldWsdlOverride, newWsdlOverride); 335 wsdlOverride = newWsdlOverride; 336 getPCS().firePropertyChange("wsdlOverride", oldWsdlOverride, wsdlOverride); 337 } 338 339 343 public List getPortInfos() { 344 return ports; 345 } 346 347 public PortInfo getPortInfo(int index) { 348 return (PortInfo) ports.get(index); 349 } 350 351 357 public void setPortInfos(List newPorts) throws java.beans.PropertyVetoException { 358 List oldPorts = ports; 359 getVCS().fireVetoableChange("portInfos", oldPorts, newPorts); ports = newPorts; 361 getPCS().firePropertyChange("portInfos", oldPorts, ports); } 363 364 public void addPortInfo(PortInfo newPortInfo) throws java.beans.PropertyVetoException { 365 getVCS().fireVetoableChange("portInfo", null, newPortInfo); if(ports == null) { 367 ports = new ArrayList (); 368 } 369 ports.add(newPortInfo); 370 getPCS().firePropertyChange("portInfo", null, newPortInfo ); } 372 373 public void removePortInfo(PortInfo oldPortInfo) throws java.beans.PropertyVetoException { 374 getVCS().fireVetoableChange("portInfo", oldPortInfo, null); ports.remove(oldPortInfo); 376 getPCS().firePropertyChange("portInfo", oldPortInfo, null ); } 378 379 384 public void setMessageSecurityBinding(MessageSecurityBinding newBinding) throws java.beans.PropertyVetoException , VersionNotSupportedException { 385 if(ports != null && ports.size() > 0) { 386 MessageSecurityBinding oldBinding; 387 oldBinding = ((PortInfo) ports.get(0)).getMessageSecurityBinding(); 388 getVCS().fireVetoableChange("messageSecurityBinding", oldBinding, newBinding); Iterator portIterator = ports.iterator(); 390 while(portIterator.hasNext()) { 391 PortInfo portInfo = (PortInfo) portIterator.next(); 392 portInfo.setMessageSecurityBinding((newBinding != null) ? (MessageSecurityBinding) newBinding.clone() : null); 393 } 394 getPCS().firePropertyChange("messageSecurityBinding", oldBinding, newBinding ); } 396 } 397 398 401 public void setMessageSecurityBinding(String namespaceURI, String localpart, MessageSecurityBinding newBinding) 402 throws java.beans.PropertyVetoException , VersionNotSupportedException { 403 PortInfo thePortInfo = null; 404 405 if(ports != null) { 407 Iterator iter = ports.iterator(); 408 while(iter.hasNext()) { 409 PortInfo portInfo = (PortInfo) iter.next(); 410 WsdlPort port = portInfo.getWsdlPort(); 411 if(port != null && namespaceURI.equals(port.getNamespaceURI()) && localpart.equals(port.getLocalpart())) { 412 thePortInfo = portInfo; 413 break; 414 } 415 } 416 } else { 417 ports = new ArrayList (); 419 } 420 421 if(thePortInfo == null) { 422 thePortInfo = getConfig().getStorageFactory().createPortInfo(); 424 WsdlPort wsdlPort = thePortInfo.newWsdlPort(); 425 wsdlPort.setNamespaceURI(namespaceURI); 426 wsdlPort.setLocalpart(localpart); 427 thePortInfo.setWsdlPort(wsdlPort); 428 ports.add(thePortInfo); 429 } 430 431 MessageSecurityBinding oldBinding = thePortInfo.getMessageSecurityBinding(); 433 getVCS().fireVetoableChange("messageSecurityBinding", oldBinding, newBinding); thePortInfo.setMessageSecurityBinding((newBinding != null) ? (MessageSecurityBinding) newBinding.clone() : null); 435 getPCS().firePropertyChange("messageSecurityBinding", oldBinding, newBinding ); } 437 438 442 public List getCallProperties() { 443 return callProperties; 444 } 445 446 public CallProperty getCallProperty(int index) { 447 return (CallProperty) ports.get(index); 448 } 449 450 456 public void setCallProperties(List newCallProperties) throws java.beans.PropertyVetoException { 457 List oldCallProperties = callProperties; 458 getVCS().fireVetoableChange("callProperties", oldCallProperties, newCallProperties); callProperties = newCallProperties; 460 getPCS().firePropertyChange("callProperties", oldCallProperties, callProperties); } 462 463 public void addCallProperty(CallProperty newCallProperty) throws java.beans.PropertyVetoException { 464 getVCS().fireVetoableChange("callProperty", null, newCallProperty); if(callProperties == null) { 466 callProperties = new ArrayList (); 467 } 468 callProperties.add(newCallProperty); 469 getPCS().firePropertyChange("callProperty", null, newCallProperty ); } 471 472 public void removeCallProperty(CallProperty oldCallProperty) throws java.beans.PropertyVetoException { 473 getVCS().fireVetoableChange("callProperty", oldCallProperty, null); callProperties.remove(oldCallProperty); 475 getPCS().firePropertyChange("callProperty", oldCallProperty, null ); } 477 478 public void fireXpathEvent(XpathEvent xpathEvent) { 479 String xpath = xpathEvent.getBean().getXpath(); 480 if(xpath.equals("/web-app/service-ref/port-component-ref")){ setDefaultPorts(); 482 } 483 } 484 485 489 public java.util.List getServiceOperations(DDBean portInfoDD) { 490 492 java.util.List operationList = new ArrayList (); 493 operationList.add(new ConfigQuery.MethodData("pi_operation1", java.util.Arrays.asList(new String [] { "arg1", "arg2" } ))); 494 operationList.add(new ConfigQuery.MethodData("pi_operation2", java.util.Arrays.asList(new String [] { "arg1" } ))); 495 operationList.add(new ConfigQuery.MethodData("pi_operation3", java.util.Arrays.asList(new String [] { "arg1", "arg2", "arg3" } ))); 496 return operationList; 497 } 498 } 499 | Popular Tags |