1 package org.jbpm.bpel.service.exe; 2 3 import javax.wsdl.PortType; 4 import javax.xml.namespace.QName ; 5 6 import org.w3c.dom.Element ; 7 8 import com.ibm.wsdl.util.xml.DOMUtils; 9 import com.ibm.wsdl.util.xml.QNameUtils; 10 11 import org.jbpm.bpel.service.spi.EndpointReference; 12 import org.jbpm.bpel.service.spi.EndpointReferenceFactory; 13 import org.jbpm.bpel.xml.BpelConstants; 14 import org.jbpm.bpel.xml.util.NodeUtil; 15 16 23 public class ServiceReference { 24 25 private String referenceScheme; 26 private EndpointReference endpointReference; 27 private PortType portType; 28 29 public String getReferenceScheme() { 30 return referenceScheme; 31 } 32 33 public void setReferenceScheme(String referenceScheme) { 34 this.referenceScheme = referenceScheme; 35 } 36 37 public EndpointReference getEndpointReference() { 38 return endpointReference; 39 } 40 41 public void setEndpointReference(EndpointReference endpointReference) { 42 this.endpointReference = endpointReference; 43 } 44 45 public PortType getPortType() { 46 return portType; 47 } 48 49 public void setPortType(PortType portType) { 50 this.portType = portType; 51 } 52 53 public void readElement(Element serviceRefElem) { 54 Element endpointRefElem; 55 if (BpelConstants.NS_BPWS.equals(serviceRefElem.getNamespaceURI()) && 57 BpelConstants.ELEM_SERVICE_REF.equals(serviceRefElem.getLocalName())) { 58 referenceScheme = NodeUtil.getAttribute(serviceRefElem, BpelConstants.ATTR_REFERENCE_SCHEME); 60 endpointRefElem = DOMUtils.getFirstChildElement(serviceRefElem); 61 } 62 else { 63 endpointRefElem = serviceRefElem; 65 } 66 QName endpointRefName = QNameUtils.newQName(endpointRefElem); 68 EndpointReferenceFactory factory = EndpointReferenceFactory.getInstance(endpointRefName, referenceScheme); 69 if (factory == null) { 70 throw new RuntimeException ("Unsupported reference: " + 71 "endpointReference=" + endpointRefName + ", scheme=" + referenceScheme); 72 } 73 endpointReference = factory.createEndpoint(this); 75 endpointReference.readElement(endpointRefElem); 76 } 77 78 public void writeElement(Element serviceRefElem) { 79 Element endpointRefElem; 80 QName endpointRefName = endpointReference.getElementQName(); 81 if (BpelConstants.NS_BPWS.equals(serviceRefElem.getNamespaceURI()) && 83 BpelConstants.ELEM_SERVICE_REF.equals(serviceRefElem.getLocalName())) { 84 serviceRefElem.setAttribute(BpelConstants.ATTR_REFERENCE_SCHEME, referenceScheme); 85 endpointRefElem = DOMUtils.getFirstChildElement(serviceRefElem); 86 if (endpointRefElem != null) { 87 if (QNameUtils.matches(endpointRefName, endpointRefElem)) { 88 NodeUtil.removeChildNodes(endpointRefElem); 89 } 90 else { 91 Element newEndpointRefElem = serviceRefElem.getOwnerDocument().createElementNS( 92 endpointRefName.getNamespaceURI(), endpointRefName.getLocalPart()); 93 serviceRefElem.replaceChild(newEndpointRefElem, endpointRefElem); 94 endpointRefElem = newEndpointRefElem; 95 } 96 } 97 else { 98 endpointRefElem = serviceRefElem.getOwnerDocument().createElementNS( 99 endpointRefName.getNamespaceURI(), endpointRefName.getLocalPart()); 100 serviceRefElem.appendChild(endpointRefElem); 101 } 102 } 103 else if (QNameUtils.matches(endpointRefName, serviceRefElem)) { 104 endpointRefElem = serviceRefElem; 105 NodeUtil.removeChildNodes(endpointRefElem); 106 } 107 else { 108 throw new RuntimeException ("Mismatched assignment: to=" + 109 QNameUtils.newQName(serviceRefElem) + ", from=" + endpointRefName); 110 } 111 endpointReference.writeElement(endpointRefElem); 112 } 113 } 114 | Popular Tags |