KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > wsif > wsdl > extensions > java > JavaBindingSerializer


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.java;
59
60 import java.io.Serializable JavaDoc;
61
62 import javax.wsdl.extensions.ExtensionDeserializer;
63 import javax.wsdl.extensions.ExtensionRegistry;
64 import javax.wsdl.extensions.ExtensionSerializer;
65 import javax.xml.namespace.QName JavaDoc;
66
67 import org.apache.wsif.logging.Trc;
68
69 import com.ibm.wsdl.Constants;
70 import com.ibm.wsdl.util.StringUtils;
71 import com.ibm.wsdl.util.xml.DOMUtils;
72
73 /**
74  * @author Gerhard Pfau <gpfau@de.ibm.com>
75  * @author Owen Burroughs <owenb@apache.org>
76  * @author Ant Elder <antelder@apache.org>
77  * @author Jeremy Hughes <hughesj@apache.org>
78  * @author Mark Whitlock <whitlock@apache.org>
79  */

80 public class JavaBindingSerializer
81     implements ExtensionSerializer, ExtensionDeserializer, Serializable JavaDoc {
82
83     private static final long serialVersionUID = 1L;
84         
85     public void marshall(
86         Class JavaDoc parentType,
87         QName JavaDoc elementType,
88         javax.wsdl.extensions.ExtensibilityElement extension,
89         java.io.PrintWriter JavaDoc pw,
90         javax.wsdl.Definition def,
91         javax.wsdl.extensions.ExtensionRegistry extReg)
92         throws javax.wsdl.WSDLException {
93         Trc.entry(this, parentType, elementType, extension, pw, def, extReg);
94
95         // CHANGE HERE: Adjust with unmarshall() !!!
96

97         if (extension == null) {
98             Trc.exit();
99             return;
100         }
101
102         if (extension instanceof JavaBinding) {
103             JavaBinding javaBinding = (JavaBinding) extension;
104             pw.print(" <java:binding");
105
106             Boolean JavaDoc required = extension.getRequired();
107             if (required != null) {
108                 DOMUtils.printQualifiedAttribute(
109                     Constants.Q_ATTR_REQUIRED,
110                     required.toString(),
111                     def,
112                     pw);
113             }
114
115             pw.println("/>");
116         } else if (extension instanceof JavaOperation) {
117             JavaOperation javaOperation = (JavaOperation) extension;
118             pw.print(" <java:operation");
119
120             if (javaOperation.getMethodName() != null) {
121                 DOMUtils.printAttribute("methodName", javaOperation.getMethodName(), pw);
122             }
123
124             if (javaOperation.getMethodType() != null) {
125                 DOMUtils.printAttribute("methodType", javaOperation.getMethodType(), pw);
126             }
127
128             if (javaOperation.getParameterOrder() != null) {
129                 DOMUtils.printAttribute(
130                     "parameterOrder",
131                     StringUtils.getNMTokens(javaOperation.getParameterOrder()),
132                     pw);
133             }
134
135             if (javaOperation.getReturnPart() != null) {
136                 DOMUtils.printAttribute("returnPart", javaOperation.getReturnPart(), pw);
137             }
138
139             Boolean JavaDoc required = extension.getRequired();
140             if (required != null) {
141                 DOMUtils.printQualifiedAttribute(
142                     Constants.Q_ATTR_REQUIRED,
143                     required.toString(),
144                     def,
145                     pw);
146             }
147
148             pw.println("/>");
149         } else if (extension instanceof JavaAddress) {
150             JavaAddress javaAddress = (JavaAddress) extension;
151             pw.print(" <java:address");
152
153             if (javaAddress.getClassName() != null) {
154                 DOMUtils.printAttribute("className", javaAddress.getClassName(), pw);
155             }
156
157             if (javaAddress.getClassPath() != null) {
158                 DOMUtils.printAttribute("classPath", javaAddress.getClassPath(), pw);
159             }
160
161             if (javaAddress.getClassLoader() != null) {
162                 DOMUtils.printAttribute("classLoader", javaAddress.getClassLoader(), pw);
163             }
164
165             Boolean JavaDoc required = extension.getRequired();
166             if (required != null) {
167                 DOMUtils.printQualifiedAttribute(
168                     Constants.Q_ATTR_REQUIRED,
169                     required.toString(),
170                     def,
171                     pw);
172             }
173
174             pw.println("/>");
175         }
176         Trc.exit();
177     }
178
179     /**
180      * Registers the serializer.
181      */

182     public void registerSerializer(ExtensionRegistry registry) {
183         Trc.entry(this, registry);
184         // binding
185
registry.registerSerializer(
186             javax.wsdl.Binding.class,
187             JavaBindingConstants.Q_ELEM_JAVA_BINDING,
188             this);
189         registry.registerDeserializer(
190             javax.wsdl.Binding.class,
191             JavaBindingConstants.Q_ELEM_JAVA_BINDING,
192             this);
193         registry.mapExtensionTypes(
194             javax.wsdl.Binding.class,
195             JavaBindingConstants.Q_ELEM_JAVA_BINDING,
196             JavaBinding.class);
197
198         // operation
199
registry.registerSerializer(
200             javax.wsdl.BindingOperation.class,
201             JavaBindingConstants.Q_ELEM_JAVA_OPERATION,
202             this);
203         registry.registerDeserializer(
204             javax.wsdl.BindingOperation.class,
205             JavaBindingConstants.Q_ELEM_JAVA_OPERATION,
206             this);
207         registry.mapExtensionTypes(
208             javax.wsdl.BindingOperation.class,
209             JavaBindingConstants.Q_ELEM_JAVA_OPERATION,
210             JavaOperation.class);
211         // address
212
registry.registerSerializer(
213             javax.wsdl.Port.class,
214             JavaBindingConstants.Q_ELEM_JAVA_ADDRESS,
215             this);
216         registry.registerDeserializer(
217             javax.wsdl.Port.class,
218             JavaBindingConstants.Q_ELEM_JAVA_ADDRESS,
219             this);
220         registry.mapExtensionTypes(
221             javax.wsdl.Port.class,
222             JavaBindingConstants.Q_ELEM_JAVA_ADDRESS,
223             JavaAddress.class);
224         Trc.exit();
225     }
226
227     public javax.wsdl.extensions.ExtensibilityElement unmarshall(
228         Class JavaDoc parentType,
229         javax.xml.namespace.QName JavaDoc elementType,
230         org.w3c.dom.Element JavaDoc el,
231         javax.wsdl.Definition def,
232         javax.wsdl.extensions.ExtensionRegistry extReg)
233         throws javax.wsdl.WSDLException {
234         Trc.entry(this, parentType, elementType, el, def, extReg);
235
236         // CHANGE HERE: Use only one temp string ...
237

238         javax.wsdl.extensions.ExtensibilityElement returnValue = null;
239
240         if (JavaBindingConstants.Q_ELEM_JAVA_BINDING.equals(elementType)) {
241             JavaBinding javaBinding = new JavaBinding();
242             Trc.exit(javaBinding);
243             return javaBinding;
244         } else if (JavaBindingConstants.Q_ELEM_JAVA_OPERATION.equals(elementType)) {
245             JavaOperation javaOperation = new JavaOperation();
246
247             String JavaDoc methodName = DOMUtils.getAttribute(el, "methodName");
248             //String requiredStr = DOMUtils.getAttributeNS(el, Constants.NS_URI_WSDL, Constants.ATTR_REQUIRED);
249
if (methodName != null) {
250                 javaOperation.setMethodName(methodName);
251             }
252
253             String JavaDoc methodType = DOMUtils.getAttribute(el, "methodType");
254             if (methodType != null) {
255                 javaOperation.setMethodType(methodType);
256             }
257
258             String JavaDoc parameterOrder = DOMUtils.getAttribute(el, "parameterOrder");
259             if (parameterOrder != null) {
260                 javaOperation.setParameterOrder(parameterOrder);
261             }
262
263             String JavaDoc returnPart = DOMUtils.getAttribute(el, "returnPart");
264             if (returnPart != null) {
265                 javaOperation.setReturnPart(returnPart);
266             }
267             Trc.exit(javaOperation);
268             return javaOperation;
269         } else if (JavaBindingConstants.Q_ELEM_JAVA_ADDRESS.equals(elementType)) {
270             JavaAddress javaAddress = new JavaAddress();
271
272             String JavaDoc className = DOMUtils.getAttribute(el, "className");
273             if (className != null) {
274                 javaAddress.setClassName(className);
275             }
276
277             String JavaDoc classPath = DOMUtils.getAttribute(el, "classPath");
278             if (classPath != null) {
279                 javaAddress.setClassPath(classPath);
280             }
281
282             String JavaDoc classLoader = DOMUtils.getAttribute(el, "classLoader");
283             if (classLoader != null) {
284                 javaAddress.setClassLoader(classLoader);
285             }
286             Trc.exit(javaAddress);
287             return javaAddress;
288         }
289         Trc.exit(returnValue);
290         return returnValue;
291     }
292 }
Popular Tags