01: package org.objectweb.celtix.tools.extensions.jms;
02:
03: import java.io.*;
04: import java.lang.reflect.*;
05:
06: import javax.wsdl.Definition;
07: import javax.wsdl.WSDLException;
08: import javax.wsdl.extensions.ExtensibilityElement;
09: import javax.wsdl.extensions.ExtensionDeserializer;
10: import javax.wsdl.extensions.ExtensionRegistry;
11: import javax.wsdl.extensions.ExtensionSerializer;
12: import javax.xml.namespace.QName;
13: import org.w3c.dom.*;
14:
15: import org.objectweb.celtix.helpers.XMLUtils;
16: import org.objectweb.celtix.tools.common.ToolConstants;
17:
18: public class JMSAddressSerializer implements ExtensionSerializer,
19: ExtensionDeserializer, Serializable {
20: public static final long serialVersionUID = 1;
21: XMLUtils xmlUtils = new XMLUtils();
22:
23: public void marshall(Class parentType, QName elementType,
24: ExtensibilityElement extension, PrintWriter pw,
25: Definition def, ExtensionRegistry extReg)
26: throws WSDLException {
27:
28: JMSAddress jmsAddress = (JMSAddress) extension;
29: StringBuffer sb = new StringBuffer(300);
30: sb.append(" <" + xmlUtils.writeQName(def, elementType) + " ");
31: sb.append(jmsAddress.getAttrXMLString());
32: sb.append("/>");
33: pw.print(sb.toString());
34: pw.println();
35: }
36:
37: public ExtensibilityElement unmarshall(Class parentType,
38: QName elementType, Element el, Definition def,
39: ExtensionRegistry extReg) throws WSDLException {
40:
41: JMSAddress jmsAddress = (JMSAddress) extReg.createExtension(
42: parentType, elementType);
43: jmsAddress.setElementType(elementType);
44: jmsAddress.setElement(el);
45: jmsAddress.setDocumentBaseURI(def.getDocumentBaseURI());
46:
47: JMSAddressParser parser = new JMSAddressParser();
48: parser.parseElement(jmsAddress, el);
49:
50: if (jmsAddress.getAddress() == null
51: || jmsAddress.getAddress().trim().length() == 0) {
52: if (def.getNamespaces() != null) {
53: jmsAddress.setAddress((String) def.getNamespaces().get(
54: "jms"));
55: } else {
56: jmsAddress.setAddress(ToolConstants.NS_JMS_ADDRESS);
57: }
58: }
59: return jmsAddress;
60: }
61: }
|