KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > wsdl > xml > PropertySerializer


1 package org.jbpm.bpel.wsdl.xml;
2
3 import java.io.PrintWriter JavaDoc;
4 import java.io.Serializable JavaDoc;
5
6 import javax.wsdl.Definition;
7 import javax.wsdl.WSDLException;
8 import javax.wsdl.extensions.ExtensibilityElement;
9 import javax.wsdl.extensions.ExtensionDeserializer;
10 import javax.wsdl.extensions.ExtensionRegistry;
11 import javax.wsdl.extensions.ExtensionSerializer;
12 import javax.xml.namespace.QName JavaDoc;
13
14 import org.w3c.dom.Element JavaDoc;
15
16 import com.ibm.wsdl.Constants;
17 import com.ibm.wsdl.util.xml.DOMUtils;
18
19 import org.jbpm.bpel.wsdl.def.Property;
20 import org.jbpm.bpel.xml.BpelConstants;
21 import org.jbpm.bpel.xml.util.NodeUtil;
22
23 /**
24  * Translates between <code>&lt;property/&gt;</code> XML elements and
25  * {@link Property} instances.
26  * @author Alejandro Guízar
27  * @version $Revision: 1.4 $ $Date: 2005/06/23 02:22:47 $
28  */

29 public class PropertySerializer implements ExtensionSerializer,
30   ExtensionDeserializer, Serializable JavaDoc {
31
32   private static final long serialVersionUID = 1L;
33
34   /**
35    * Deserializes a DOM element into a {@link Property} instance.
36    * @param parentType class object indicating where in the WSDL document
37    * this extensibility element was encountered
38    * @param elementType the qname of the extensibility element
39    * @param elem the extensibility element to deserialize.
40    * @param def the definition this extensibility element was encountered in.
41    * @param extReg the ExtensionRegistry to use (if needed again).
42    * @return the deserialized instance.
43    * @throws WSDLException if deserialization fails.
44    */

45   public ExtensibilityElement unmarshall(Class JavaDoc parentType, QName JavaDoc elementType,
46     Element elem, Definition def, ExtensionRegistry extReg) throws WSDLException {
47     Property property = (Property) extReg.createExtension(parentType, elementType);
48
49     // name attribute
50
String JavaDoc name = elem.getAttribute(WsdlConstants.ATTR_NAME);
51     property.setQName(new QName JavaDoc(def.getTargetNamespace(), name));
52
53     // type attribute
54
String JavaDoc type = elem.getAttribute(WsdlConstants.ATTR_TYPE);
55     property.setType(NodeUtil.getQName(type, elem));
56
57     // wsdl:required attribute
58
String JavaDoc required = DOMUtils.getAttributeNS(elem, Constants.NS_URI_WSDL,
59         Constants.ATTR_REQUIRED);
60     if (required != null) {
61       property.setRequired(Boolean.valueOf(required));
62     }
63
64     return property;
65   }
66
67   /**
68    * Serializes a {@link Property} instance into the given {@link PrintWriter}.
69    * @param parentType class object indicating where in the WSDL document
70    * this extensibility element was encountered
71    * @param elementType the qname of the extensibility element
72    * @param extension the instance to serialize.
73    * @param pw the stream to write in.
74    * @param def the definition this extensibility element was encountered in.
75    * @param extReg the ExtensionRegistry to use (if needed again).
76    * @throws WSDLException if serialization fails
77    */

78   public void marshall(Class JavaDoc parentType, QName JavaDoc elementType,
79     ExtensibilityElement extension, PrintWriter JavaDoc pw, Definition def,
80     ExtensionRegistry extReg) throws WSDLException {
81     if (extension == null)
82       return;
83
84     Property property = (Property) extension;
85
86     // open tag
87
String JavaDoc tagName = DOMUtils.getQualifiedValue(BpelConstants.NS_BPWS,
88         WsdlConstants.ELEM_PROPERTY, def);
89     pw.print(" <" + tagName);
90
91     // name attribute
92
DOMUtils.printAttribute(WsdlConstants.ATTR_NAME,
93       property.getQName().getLocalPart(), pw);
94
95     // type attribute
96
DOMUtils.printQualifiedAttribute(WsdlConstants.ATTR_TYPE,
97       property.getType(), def, pw);
98
99     // wsdl:required attribute
100
Boolean JavaDoc required = property.getRequired();
101     if (required != null) {
102       DOMUtils.printQualifiedAttribute(Constants.Q_ATTR_REQUIRED,
103         required.toString(), def, pw);
104     }
105
106     // close tag
107
pw.println("/>");
108   }
109 }
110
Popular Tags