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.Message; 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.data.def.Snippet; 21 import org.jbpm.bpel.wsdl.def.Property; 22 import org.jbpm.bpel.wsdl.def.PropertyAlias; 23 import org.jbpm.bpel.wsdl.util.WsdlUtil; 24 import org.jbpm.bpel.xml.BpelConstants; 25 import org.jbpm.bpel.xml.util.NodeUtil; 26 27 33 public class PropertyAliasSerializer implements ExtensionSerializer, 34 ExtensionDeserializer , Serializable { 35 36 private static final long serialVersionUID = 1L; 37 38 49 public ExtensibilityElement unmarshall(Class parentType, QName elementType, 50 Element elem, Definition def, ExtensionRegistry extReg) throws WSDLException { 51 PropertyAlias alias = (PropertyAlias) extReg.createExtension(parentType, elementType); 52 53 String prefixedName = elem.getAttribute(WsdlConstants.ATTR_PROPERTY_NAME); 55 QName qualifiedName = NodeUtil.getQName(prefixedName, elem); 56 Property property = WsdlUtil.getProperty(def, qualifiedName); 57 if (property == null) { 58 property = (Property) extReg.createExtension(Definition.class, WsdlConstants.Q_PROPERTY); 59 property.setQName(qualifiedName); 60 def.addExtensibilityElement(property); 61 } 62 alias.setProperty(property); 63 64 prefixedName = elem.getAttribute(WsdlConstants.ATTR_MESSAGE_TYPE); 66 qualifiedName = NodeUtil.getQName(prefixedName, elem); 67 Message message = def.getMessage(qualifiedName); 68 if (message == null) { 69 message = def.createMessage(); 70 message.setQName(qualifiedName); 71 def.addMessage(message); 72 } 73 alias.setMessage(message); 74 75 String required = DOMUtils.getAttributeNS(elem, Constants.NS_URI_WSDL, Constants.ATTR_REQUIRED); 77 if (required != null) { 78 alias.setRequired(Boolean.valueOf(required)); 79 } 80 81 Element queryElem = DOMUtils.getFirstChildElement(elem); 83 if (queryElem != null) { 84 alias.setQuery(unmarshallQuery(queryElem)); 85 } 86 87 return alias; 88 } 89 90 102 public void marshall(Class parentType, QName elementType, 103 ExtensibilityElement extension, PrintWriter pw, Definition def, 104 ExtensionRegistry extReg) throws WSDLException { 105 if (extension == null) { 106 return; 107 } 108 PropertyAlias alias = (PropertyAlias) extension; 109 String tagName = DOMUtils.getQualifiedValue(BpelConstants.NS_BPWS, 111 WsdlConstants.ELEM_PROPERTY_ALIAS, def); 112 pw.print(" <" + tagName); 113 DOMUtils.printQualifiedAttribute(WsdlConstants.ATTR_PROPERTY_NAME, 115 alias.getProperty().getQName(), def, pw); 116 DOMUtils.printQualifiedAttribute(WsdlConstants.ATTR_MESSAGE_TYPE, 118 alias.getMessage().getQName(), def, pw); 119 Boolean required = alias.getRequired(); 121 if (required != null) { 122 DOMUtils.printQualifiedAttribute(Constants.Q_ATTR_REQUIRED, required.toString(), def, pw); 123 } 124 Snippet query = alias.getQuery(); 125 if (query != null) { 126 pw.println('>'); 127 marshallQuery(alias.getQuery(), pw, def); 129 pw.println(" </" + tagName + '>'); 131 } 132 else { 133 pw.println("/>"); 134 } 135 } 136 137 142 protected Snippet unmarshallQuery(Element queryElem) { 143 Snippet query = new Snippet(); 144 query.setLanguage(DOMUtils.getAttribute(queryElem, WsdlConstants.ATTR_QUERY_LANGUAGE)); 146 query.setText(DOMUtils.getChildCharacterData(queryElem)); 148 query.setNamespaces(NodeUtil.getNamespaceDeclarations(queryElem)); 150 query.setUse(Snippet.Use.PROPERTY_ALIAS); 152 return query; 153 } 154 155 162 protected void marshallQuery(Snippet query, PrintWriter pw, Definition def) throws WSDLException { 163 String queryTag = DOMUtils.getQualifiedValue(BpelConstants.NS_BPWS, WsdlConstants.ELEM_QUERY, def); 165 pw.print(" <" + queryTag); 166 DOMUtils.printAttribute(WsdlConstants.ATTR_QUERY_LANGUAGE, query.getLanguage(), pw); 168 pw.print('>'); 169 pw.print(DOMUtils.cleanString(query.getText())); 171 pw.println("</" + queryTag + '>'); 173 } 174 } 175 | Popular Tags |