01: package com.bostechcorp.cbesb.common.util.generators.wsdl.extensions;
02:
03: import java.io.PrintWriter;
04: import java.io.Serializable;
05: import java.util.List;
06: import java.util.Properties;
07:
08: import javax.wsdl.Definition;
09: import javax.wsdl.WSDLException;
10: import javax.wsdl.extensions.ExtensibilityElement;
11: import javax.wsdl.extensions.ExtensionDeserializer;
12: import javax.wsdl.extensions.ExtensionRegistry;
13: import javax.wsdl.extensions.ExtensionSerializer;
14: import javax.xml.namespace.QName;
15:
16: import org.w3c.dom.Element;
17: import org.w3c.dom.Node;
18:
19: import com.ibm.wsdl.Constants;
20: import com.ibm.wsdl.util.xml.DOMUtils;
21:
22: public class BindingSerializer implements ExtensionSerializer,
23: ExtensionDeserializer, Serializable {
24:
25: /**
26: *
27: */
28: private static final long serialVersionUID = -7992466319464793594L;
29:
30: public void marshall(Class parentType, QName elementType,
31: ExtensibilityElement extension, PrintWriter pw,
32: Definition def, ExtensionRegistry extReg)
33: throws WSDLException {
34: BindingExtension binding = (BindingExtension) extension;
35: if (binding != null) {
36: String tagName = DOMUtils.getQualifiedValue(binding
37: .getElementType().getNamespaceURI(),
38: ConfigConstants.ELEM_BINDING, def);
39: pw.print(" <" + tagName);
40:
41: for (Object attrName : binding.getAttributes().keySet()) {
42: DOMUtils.printAttribute((String) attrName,
43: binding.getAttributes().getProperty(
44: (String) attrName), pw);
45: }
46: ;
47:
48: Boolean required = binding.getRequired();
49:
50: if (required != null) {
51: DOMUtils.printQualifiedAttribute(
52: Constants.Q_ATTR_REQUIRED, required.toString(),
53: def, pw);
54: }
55: pw.println("/>");
56: }
57:
58: }
59:
60: @SuppressWarnings("unchecked")
61: public ExtensibilityElement unmarshall(Class parentType,
62: QName elementType, Element el, Definition def,
63: ExtensionRegistry extReg) throws WSDLException {
64: BindingExtension config = (BindingExtension) extReg
65: .createExtension(parentType, elementType);
66:
67: Properties prop = new Properties();
68:
69: List<Node> attributes = DOMUtils.getAttributes(el);
70: for (Node node : attributes) {
71: prop.setProperty(node.getNodeName(), node.getNodeValue());
72: }
73: config.setAttributes(prop);
74: return config;
75: }
76:
77: }
|