KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > wsif > wsdl > extensions > ejb > EJBBindingSerializer


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.ejb;
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 Ant Elder <antelder@apache.org>
76  * @author Owen Burroughs <owenb@pache.org>
77  * @author Mark Whitlock <whitlock@apache.org>
78  */

79 public class EJBBindingSerializer
80         implements ExtensionSerializer, ExtensionDeserializer, Serializable JavaDoc {
81
82     private static final long serialVersionUID = 1L;
83             
84     public void marshall(
85         Class JavaDoc parentType,
86         QName JavaDoc elementType,
87         javax.wsdl.extensions.ExtensibilityElement extension,
88         java.io.PrintWriter JavaDoc pw,
89         javax.wsdl.Definition def,
90         javax.wsdl.extensions.ExtensionRegistry extReg)
91         throws javax.wsdl.WSDLException {
92         Trc.entry(this, parentType, elementType, extension, pw, def, extReg);
93         if (extension == null) {
94             Trc.exit();
95             return;
96         }
97
98         if (extension instanceof EJBBinding) {
99             EJBBinding ejbBinding = (EJBBinding) extension;
100             pw.print(" <ejb:binding");
101
102             Boolean JavaDoc required = extension.getRequired();
103             if (required != null) {
104                 DOMUtils.printQualifiedAttribute(
105                     Constants.Q_ATTR_REQUIRED,
106                     required.toString(),
107                     def,
108                     pw);
109             }
110
111             pw.println("/>");
112         } else if (extension instanceof EJBOperation) {
113             EJBOperation ejbOperation = (EJBOperation) extension;
114             pw.print(" <ejb:operation");
115
116             if (ejbOperation.getMethodName() != null) {
117                 DOMUtils.printAttribute("methodName", ejbOperation.getMethodName(), pw);
118             }
119
120             if (ejbOperation.getEjbInterface() != null) {
121                 DOMUtils.printAttribute("interface", ejbOperation.getEjbInterface(), pw);
122             }
123
124             if (ejbOperation.getParameterOrder() != null) {
125                 DOMUtils.printAttribute(
126                     "parameterOrder",
127                     StringUtils.getNMTokens(ejbOperation.getParameterOrder()),
128                     pw);
129             }
130
131             if (ejbOperation.getReturnPart() != null) {
132                 DOMUtils.printAttribute("returnPart", ejbOperation.getReturnPart(), pw);
133             }
134
135             Boolean JavaDoc required = extension.getRequired();
136             if (required != null) {
137                 DOMUtils.printQualifiedAttribute(
138                     Constants.Q_ATTR_REQUIRED,
139                     required.toString(),
140                     def,
141                     pw);
142             }
143
144             pw.println("/>");
145         } else if (extension instanceof EJBAddress) {
146             EJBAddress ejbAddress = (EJBAddress) extension;
147             pw.print(" <ejb:address");
148
149             if (ejbAddress.getClassName() != null) {
150                 DOMUtils.printAttribute("className", ejbAddress.getClassName(), pw);
151             }
152
153             if (ejbAddress.getArchive() != null) {
154                 DOMUtils.printAttribute("archive", ejbAddress.getArchive(), pw);
155             }
156
157             if (ejbAddress.getClassLoader() != null) {
158                 DOMUtils.printAttribute("classLoader", ejbAddress.getClassLoader(), pw);
159             }
160
161             if (ejbAddress.getJndiName() != null) {
162                 DOMUtils.printAttribute("jndiName", ejbAddress.getJndiName(), pw);
163             }
164
165             if (ejbAddress.getJndiProviderURL() != null) {
166                 DOMUtils.printAttribute("jndiProviderURL", ejbAddress.getJndiProviderURL(), pw);
167             }
168
169             if (ejbAddress.getInitialContextFactory() != null) {
170                 DOMUtils.printAttribute(
171                     "initialContextFactory",
172                     ejbAddress.getInitialContextFactory(),
173                     pw);
174             }
175
176             Boolean JavaDoc required = extension.getRequired();
177             if (required != null) {
178                 DOMUtils.printQualifiedAttribute(
179                     Constants.Q_ATTR_REQUIRED,
180                     required.toString(),
181                     def,
182                     pw);
183             }
184
185             pw.println("/>");
186         }
187         Trc.exit();
188     }
189     
190     /**
191      * Registers the serializer.
192      */

193     public void registerSerializer(ExtensionRegistry registry) {
194         Trc.entry(this, registry);
195         // binding
196
registry.registerSerializer(
197             javax.wsdl.Binding.class,
198             EJBBindingConstants.Q_ELEM_EJB_BINDING,
199             this);
200         registry.registerDeserializer(
201             javax.wsdl.Binding.class,
202             EJBBindingConstants.Q_ELEM_EJB_BINDING,
203             this);
204         registry.mapExtensionTypes(
205             javax.wsdl.Binding.class,
206             EJBBindingConstants.Q_ELEM_EJB_BINDING,
207             EJBBinding.class);
208
209         // operation
210
registry.registerSerializer(
211             javax.wsdl.BindingOperation.class,
212             EJBBindingConstants.Q_ELEM_EJB_OPERATION,
213             this);
214         registry.registerDeserializer(
215             javax.wsdl.BindingOperation.class,
216             EJBBindingConstants.Q_ELEM_EJB_OPERATION,
217             this);
218         registry.mapExtensionTypes(
219             javax.wsdl.BindingOperation.class,
220             EJBBindingConstants.Q_ELEM_EJB_OPERATION,
221             EJBOperation.class);
222
223         // address
224
registry.registerSerializer(
225             javax.wsdl.Port.class,
226             EJBBindingConstants.Q_ELEM_EJB_ADDRESS,
227             this);
228         registry.registerDeserializer(
229             javax.wsdl.Port.class,
230             EJBBindingConstants.Q_ELEM_EJB_ADDRESS,
231             this);
232         registry.mapExtensionTypes(
233             javax.wsdl.Port.class,
234             EJBBindingConstants.Q_ELEM_EJB_ADDRESS,
235             EJBAddress.class);
236         Trc.exit();
237     }
238     
239     public javax.wsdl.extensions.ExtensibilityElement unmarshall(
240         Class JavaDoc parentType,
241         javax.xml.namespace.QName JavaDoc elementType,
242         org.w3c.dom.Element JavaDoc el,
243         javax.wsdl.Definition def,
244         javax.wsdl.extensions.ExtensionRegistry extReg)
245         throws javax.wsdl.WSDLException {
246         Trc.entry(this, parentType, elementType, el, def, extReg);
247
248         javax.wsdl.extensions.ExtensibilityElement returnValue = null;
249
250         if (EJBBindingConstants.Q_ELEM_EJB_BINDING.equals(elementType)) {
251             EJBBinding ejbBinding = new EJBBinding();
252             Trc.exit(ejbBinding);
253             return ejbBinding;
254         } else if (EJBBindingConstants.Q_ELEM_EJB_OPERATION.equals(elementType)) {
255             EJBOperation ejbOperation = new EJBOperation();
256
257             String JavaDoc methodName = DOMUtils.getAttribute(el, "methodName");
258
259             if (methodName != null) {
260                 ejbOperation.setMethodName(methodName);
261             }
262
263             String JavaDoc ejbInterface = DOMUtils.getAttribute(el, "interface");
264             if (ejbInterface != null) {
265                 ejbOperation.setEjbInterface(ejbInterface);
266             }
267
268             String JavaDoc parameterOrder = DOMUtils.getAttribute(el, "parameterOrder");
269             if (parameterOrder != null) {
270                 ejbOperation.setParameterOrder(parameterOrder);
271             }
272
273             String JavaDoc returnPart = DOMUtils.getAttribute(el, "returnPart");
274             if (returnPart != null) {
275                 ejbOperation.setReturnPart(returnPart);
276             }
277             Trc.exit(ejbOperation);
278             return ejbOperation;
279         } else if (EJBBindingConstants.Q_ELEM_EJB_ADDRESS.equals(elementType)) {
280             EJBAddress ejbAddress = new EJBAddress();
281
282             String JavaDoc className = DOMUtils.getAttribute(el, "className");
283             if (className != null) {
284                 ejbAddress.setClassName(className);
285             }
286
287             String JavaDoc archive = DOMUtils.getAttribute(el, "archive");
288             if (archive != null) {
289                 ejbAddress.setArchive(archive);
290             }
291
292             String JavaDoc classLoader = DOMUtils.getAttribute(el, "classLoader");
293             if (classLoader != null) {
294                 ejbAddress.setClassLoader(classLoader);
295             }
296
297             String JavaDoc jndiName = DOMUtils.getAttribute(el, "jndiName");
298             if (jndiName != null) {
299                 ejbAddress.setJndiName(jndiName);
300             }
301
302             String JavaDoc jndiProviderURL = DOMUtils.getAttribute(el, "jndiProviderURL");
303             if (jndiProviderURL != null) {
304                 ejbAddress.setJndiProviderURL(jndiProviderURL);
305             }
306
307             String JavaDoc icf = DOMUtils.getAttribute(el, "initialContextFactory");
308             if (icf != null) {
309                 ejbAddress.setInitialContextFactory(icf);
310             }
311             Trc.exit(ejbAddress);
312             return ejbAddress;
313         }
314         Trc.exit(returnValue);
315         return returnValue;
316     }
317 }
Popular Tags