KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > service > exe > ServiceReference


1 package org.jbpm.bpel.service.exe;
2
3 import javax.wsdl.PortType;
4 import javax.xml.namespace.QName JavaDoc;
5
6 import org.w3c.dom.Element JavaDoc;
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 /**
17  * A wrapper for actual endpoint reference values. It provides pluggability
18  * of different versions of service endpoint referencing schemes.
19  * @see "WS-BPEL 2.0 §7.4"
20  * @author Alejandro Guízar
21  * @version $Revision: 1.9 $ $Date: 2005/06/23 02:22:57 $
22  */

23 public class ServiceReference {
24   
25   private String JavaDoc referenceScheme;
26   private EndpointReference endpointReference;
27   private PortType portType;
28   
29   public String JavaDoc getReferenceScheme() {
30     return referenceScheme;
31   }
32   
33   public void setReferenceScheme(String JavaDoc 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 JavaDoc serviceRefElem) {
54     Element JavaDoc endpointRefElem;
55     // is the given element a service reference container?
56
if (BpelConstants.NS_BPWS.equals(serviceRefElem.getNamespaceURI()) &&
57         BpelConstants.ELEM_SERVICE_REF.equals(serviceRefElem.getLocalName())) {
58       // read element following the schema of bpel:service-ref
59
referenceScheme = NodeUtil.getAttribute(serviceRefElem, BpelConstants.ATTR_REFERENCE_SCHEME);
60       endpointRefElem = DOMUtils.getFirstChildElement(serviceRefElem);
61     }
62     else {
63       // assume the given element is the actual endpoint reference value
64
endpointRefElem = serviceRefElem;
65     }
66     // locate a factory that understands this reference
67
QName JavaDoc endpointRefName = QNameUtils.newQName(endpointRefElem);
68     EndpointReferenceFactory factory = EndpointReferenceFactory.getInstance(endpointRefName, referenceScheme);
69     if (factory == null) {
70       throw new RuntimeException JavaDoc("Unsupported reference: " +
71           "endpointReference=" + endpointRefName + ", scheme=" + referenceScheme);
72     }
73     // produce the endpoint reference
74
endpointReference = factory.createEndpoint(this);
75     endpointReference.readElement(endpointRefElem);
76   }
77   
78   public void writeElement(Element JavaDoc serviceRefElem) {
79     Element JavaDoc endpointRefElem;
80     QName JavaDoc endpointRefName = endpointReference.getElementQName();
81     // is the given element a service reference container?
82
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 JavaDoc 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 JavaDoc("Mismatched assignment: to=" +
109           QNameUtils.newQName(serviceRefElem) + ", from=" + endpointRefName);
110     }
111     endpointReference.writeElement(endpointRefElem);
112   }
113 }
114
Popular Tags