1 package org.jbpm.bpel.wsdl.xml; 2 3 import java.io.PrintWriter ; 4 import java.io.Serializable ; 5 6 import javax.wsdl.Definition; 7 import javax.wsdl.PortType; 8 import javax.wsdl.WSDLException; 9 import javax.wsdl.extensions.ExtensibilityElement; 10 import javax.wsdl.extensions.ExtensionDeserializer; 11 import javax.wsdl.extensions.ExtensionRegistry; 12 import javax.wsdl.extensions.ExtensionSerializer; 13 import javax.xml.namespace.QName ; 14 15 import org.w3c.dom.Element ; 16 17 import com.ibm.wsdl.Constants; 18 import com.ibm.wsdl.util.xml.DOMUtils; 19 20 import org.jbpm.bpel.wsdl.def.PartnerLinkType; 21 import org.jbpm.bpel.xml.util.NodeUtil; 22 23 29 public class PartnerLinkTypeSerializer implements ExtensionDeserializer, 30 ExtensionSerializer, Serializable { 31 32 private static final long serialVersionUID = 1L; 33 34 45 public ExtensibilityElement unmarshall(Class parentType, QName elementType, 46 Element elem, Definition def, ExtensionRegistry extReg) throws WSDLException { 47 PartnerLinkType partnerLinkType = (PartnerLinkType) extReg.createExtension(parentType, elementType); 48 49 String name = elem.getAttribute(WsdlConstants.ATTR_NAME); 51 partnerLinkType.setQName(new QName (def.getTargetNamespace(), name)); 52 53 String required = DOMUtils.getAttributeNS(elem, Constants.NS_URI_WSDL, 55 Constants.ATTR_REQUIRED); 56 if (required != null) { 57 partnerLinkType.setRequired(Boolean.valueOf(required)); 58 } 59 60 Element roleElem = DOMUtils.getFirstChildElement(elem); 62 partnerLinkType.setFirstRole(unmarshallRole(roleElem, partnerLinkType, def)); 63 64 roleElem = DOMUtils.getNextSiblingElement(roleElem); 66 if (roleElem != null) { 67 partnerLinkType.setSecondRole(unmarshallRole(roleElem, partnerLinkType, def)); 68 } 69 return partnerLinkType; 70 } 71 72 84 public void marshall(Class parentType, QName elementType, 85 ExtensibilityElement extension, PrintWriter pw, Definition def, 86 ExtensionRegistry extReg) throws WSDLException { 87 if (extension == null) 88 return; 89 90 PartnerLinkType partnerLinkType = (PartnerLinkType) extension; 91 92 String tagName = DOMUtils.getQualifiedValue(WsdlConstants.NS_PLNK, 94 WsdlConstants.ELEM_PARTNER_LINK_TYPE, def); 95 pw.print(" <" + tagName); 96 97 DOMUtils.printAttribute(WsdlConstants.ATTR_NAME, 99 partnerLinkType.getQName().getLocalPart(), pw); 100 101 Boolean required = partnerLinkType.getRequired(); 103 if (required != null) { 104 DOMUtils.printQualifiedAttribute(Constants.Q_ATTR_REQUIRED, 105 required.toString(), def, pw); 106 } 107 pw.println('>'); 108 109 marshallRole(partnerLinkType.getFirstRole(), pw, def); 111 marshallRole(partnerLinkType.getSecondRole(), pw, def); 112 113 pw.println(" </" + tagName + '>'); 115 } 116 117 126 protected PartnerLinkType.Role unmarshallRole(Element roleElem, 127 PartnerLinkType partnerLinkType, Definition def) { 128 PartnerLinkType.Role role = partnerLinkType.createRole(); 129 130 String name = roleElem.getAttribute(WsdlConstants.ATTR_NAME); 132 role.setName(name); 133 134 String portTypeName = roleElem.getAttribute(WsdlConstants.ATTR_PORT_TYPE); 136 QName portTypeQName = NodeUtil.getQName(portTypeName, roleElem); 137 138 PortType portType = def.getPortType(portTypeQName); 139 if (portType == null) { 140 portType = def.createPortType(); 141 portType.setQName(portTypeQName); 142 def.addPortType(portType); 143 } 144 role.setPortType(portType); 145 return role; 146 } 147 148 156 protected void marshallRole(PartnerLinkType.Role role, PrintWriter pw, Definition def) 157 throws WSDLException { 158 if (role == null) 159 return; 160 161 String roleTag = DOMUtils.getQualifiedValue(WsdlConstants.NS_PLNK, 163 WsdlConstants.ELEM_ROLE, def); 164 pw.print(" <" + roleTag); 165 166 DOMUtils.printAttribute(WsdlConstants.ATTR_NAME, role.getName(), pw); 168 169 DOMUtils.printQualifiedAttribute(WsdlConstants.ATTR_PORT_TYPE, 171 role.getPortType().getQName(), def, pw); 172 173 pw.println("/>"); 175 } 176 } 177 | Popular Tags |