KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > wsif > wsdl > extensions > jms > JMSAddressSerializer


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2002 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "WSIF" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 2001, 2002, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package org.apache.wsif.wsdl.extensions.jms;
59
60 import java.io.Serializable JavaDoc;
61
62 import javax.wsdl.Definition;
63 import javax.wsdl.WSDLException;
64 import javax.wsdl.extensions.ExtensibilityElement;
65 import javax.wsdl.extensions.ExtensionDeserializer;
66 import javax.wsdl.extensions.ExtensionRegistry;
67 import javax.wsdl.extensions.ExtensionSerializer;
68 import javax.xml.namespace.QName JavaDoc;
69
70 import org.apache.wsif.logging.Trc;
71 import org.w3c.dom.Element JavaDoc;
72
73 import com.ibm.wsdl.Constants;
74 import com.ibm.wsdl.util.xml.DOMUtils;
75 import com.ibm.wsdl.util.xml.QNameUtils;
76
77 /**
78  * WSDL Jms extension
79  *
80  * @author <a HREF="mailto:ake@de.ibm.com">Hermann Akermann</a>
81  * @author Ant Elder <antelder@apache.org>
82  * @author Mark Whitlock <whitlock@apache.org>
83  */

84 public class JMSAddressSerializer
85     implements ExtensionSerializer, ExtensionDeserializer, Serializable JavaDoc {
86
87     private static final long serialVersionUID = 1L;
88
89     JMSPropertyValueSerializer jmsPropertyValueSerializer;
90
91     private JMSPropertyValueSerializer getJMSPropertyValueSerializer() {
92         if (jmsPropertyValueSerializer == null)
93             jmsPropertyValueSerializer = new JMSPropertyValueSerializer();
94         return jmsPropertyValueSerializer;
95     }
96
97     /**
98      * @see ExtensionSerializer#marshall(Class, QName, ExtensibilityElement, PrintWriter, Definition, ExtensionRegistry)
99      */

100     public void marshall(
101         Class JavaDoc parentType,
102         QName JavaDoc elementType,
103         javax.wsdl.extensions.ExtensibilityElement extension,
104         java.io.PrintWriter JavaDoc pw,
105         javax.wsdl.Definition def,
106         javax.wsdl.extensions.ExtensionRegistry extReg)
107         throws javax.wsdl.WSDLException {
108         Trc.entry(this, parentType, elementType, extension, pw, def, extReg);
109
110         JMSAddress jmsAddress = (JMSAddress) extension;
111         String JavaDoc tagName =
112             DOMUtils.getQualifiedValue(JMSConstants.NS_URI_JMS, "address", def);
113
114         if (jmsAddress != null) {
115             pw.print(" <" + tagName);
116
117             /**
118              * handle attributes
119              */

120             if (jmsAddress.getJmsVendorURI() != null) {
121                 DOMUtils.printAttribute(
122                     JMSConstants.ELEM_JMS_JMS_VENDOR_URI,
123                     jmsAddress.getJmsVendorURI(),
124                     pw);
125             }
126
127             if (jmsAddress.getInitCxtFact() != null) {
128                 DOMUtils.printAttribute(
129                     JMSConstants.ELEM_JMS_INIT_CXT_FACT,
130                     jmsAddress.getInitCxtFact(),
131                     pw);
132             }
133
134             if (jmsAddress.getJndiProvURL() != null) {
135                 DOMUtils.printAttribute(
136                     JMSConstants.ELEM_JMS_JNDI_PROV_URL,
137                     jmsAddress.getJndiProvURL(),
138                     pw);
139             }
140
141             if (jmsAddress.getDestStyle() != null) {
142                 DOMUtils.printAttribute(
143                     JMSConstants.ELEM_JMS_DEST_STYLE,
144                     jmsAddress.getDestStyle(),
145                     pw);
146             }
147
148             if (jmsAddress.getJndiConnFactName() != null) {
149                 DOMUtils.printAttribute(
150                     JMSConstants.ELEM_JMS_JNDI_CONN_FACT_NAME,
151                     jmsAddress.getJndiConnFactName(),
152                     pw);
153             }
154
155             if (jmsAddress.getJndiDestName() != null) {
156                 DOMUtils.printAttribute(
157                     JMSConstants.ELEM_JMS_JNDI_DEST_NAME,
158                     jmsAddress.getJndiDestName(),
159                     pw);
160             }
161
162             if (jmsAddress.getJmsProvDestName() != null) {
163                 DOMUtils.printAttribute(
164                     JMSConstants.ELEM_JMS_JMS_PROV_DEST_NAME,
165                     jmsAddress.getJmsProvDestName(),
166                     pw);
167             }
168
169             if (jmsAddress.getJmsImplSpecURI() != null) {
170                 DOMUtils.printAttribute(
171                     JMSConstants.ELEM_JMS_JMS_IMPL_SPEC_URI,
172                     jmsAddress.getJmsImplSpecURI(),
173                     pw);
174             }
175
176             pw.println(">");
177
178             // Handle JMSPropertyValues
179
java.util.Iterator JavaDoc i = jmsAddress.getJMSPropertyValues().iterator();
180
181             while (i.hasNext()) {
182                 JMSPropertyValue ee = (JMSPropertyValue) i.next();
183                 getJMSPropertyValueSerializer().marshall(
184                     JMSAddress.class,
185                     JMSConstants.Q_ELEM_JMS_PROPERTY_VALUE,
186                     ee,
187                     pw,
188                     def,
189                     extReg);
190             }
191
192             Boolean JavaDoc required = extension.getRequired();
193             if (required != null) {
194                 DOMUtils.printQualifiedAttribute(
195                     Constants.Q_ATTR_REQUIRED,
196                     required.toString(),
197                     def,
198                     pw);
199             }
200
201             pw.println("</" + tagName + ">");
202         }
203         Trc.exit();
204     }
205
206     /**
207      * Registers the serializer.
208      */

209     public void registerSerializer(ExtensionRegistry registry) {
210         Trc.entry(this, registry);
211
212         registry.registerSerializer(
213             javax.wsdl.Port.class,
214             JMSConstants.Q_ELEM_JMS_ADDRESS,
215             this);
216         registry.registerDeserializer(
217             javax.wsdl.Port.class,
218             JMSConstants.Q_ELEM_JMS_ADDRESS,
219             this);
220         registry.mapExtensionTypes(
221             javax.wsdl.Port.class,
222             JMSConstants.Q_ELEM_JMS_ADDRESS,
223             JMSAddress.class);
224         Trc.exit();
225     }
226
227     /**
228      * @see ExtensionDeserializer#unmarshall(Class, QName, Element, Definition, ExtensionRegistry)
229      */

230     public ExtensibilityElement unmarshall(
231         Class JavaDoc parentType,
232         QName JavaDoc elementType,
233         Element el,
234         Definition def,
235         ExtensionRegistry extReg)
236         throws WSDLException {
237         Trc.entry(this, parentType, elementType, el, def, extReg);
238
239         JMSAddress jmsAddress =
240             (JMSAddress) extReg.createExtension(parentType, elementType);
241
242         /**
243         * handle address attributes
244         */

245         String JavaDoc jmsVendorURI =
246             DOMUtils.getAttribute(el, JMSConstants.ELEM_JMS_JMS_VENDOR_URI);
247         if (jmsVendorURI != null) {
248             jmsAddress.setJmsVendorURI(jmsVendorURI);
249         }
250
251         String JavaDoc jmsImplSpecURI =
252             DOMUtils.getAttribute(el, JMSConstants.ELEM_JMS_JMS_IMPL_SPEC_URI);
253         if (jmsImplSpecURI != null) {
254             jmsAddress.setJmsImplSpecURI(jmsImplSpecURI);
255         }
256
257         String JavaDoc initCxtFact =
258             DOMUtils.getAttribute(el, JMSConstants.ELEM_JMS_INIT_CXT_FACT);
259         if (initCxtFact != null) {
260             jmsAddress.setInitCxtFact(initCxtFact);
261         }
262
263         String JavaDoc jndiProvURL =
264             DOMUtils.getAttribute(el, JMSConstants.ELEM_JMS_JNDI_PROV_URL);
265         if (jndiProvURL != null) {
266             jmsAddress.setJndiProvURL(jndiProvURL);
267         }
268
269         String JavaDoc destStyle =
270             DOMUtils.getAttribute(el, JMSConstants.ELEM_JMS_DEST_STYLE);
271         if (destStyle != null) {
272             jmsAddress.setDestStyle(destStyle);
273         }
274
275         String JavaDoc jndiConnFactName =
276             DOMUtils.getAttribute(
277                 el,
278                 JMSConstants.ELEM_JMS_JNDI_CONN_FACT_NAME);
279         if (jndiConnFactName != null) {
280             jmsAddress.setJndiConnFactName(jndiConnFactName);
281         }
282
283         String JavaDoc jndiDestName =
284             DOMUtils.getAttribute(el, JMSConstants.ELEM_JMS_JNDI_DEST_NAME);
285         if (jndiDestName != null) {
286             jmsAddress.setJndiDestName(jndiDestName);
287         }
288
289         String JavaDoc jmsProvDestName =
290             DOMUtils.getAttribute(el, JMSConstants.ELEM_JMS_JMS_PROV_DEST_NAME);
291         if (jmsProvDestName != null) {
292             jmsAddress.setJmsProvDestName(jmsProvDestName);
293         }
294
295         // Handle JMSPropertyValues
296
Element tempEl = DOMUtils.getFirstChildElement(el);
297
298         while (tempEl != null) {
299             if (QNameUtils
300                 .matches(JMSConstants.Q_ELEM_JMS_PROPERTY_VALUE, tempEl)) {
301                 jmsAddress.addJMSPropertyValue(
302                     (JMSPropertyValue) getJMSPropertyValueSerializer()
303                         .unmarshall(
304                         JMSAddress.class,
305                         JMSConstants.Q_ELEM_JMS_PROPERTY_VALUE,
306                         tempEl,
307                         def,
308                         extReg));
309             }
310
311             tempEl = DOMUtils.getNextSiblingElement(tempEl);
312         }
313
314         Trc.exit(jmsAddress);
315         return jmsAddress;
316     }
317 }
Popular Tags