KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > wsif > providers > soap > apachesoap > WSIFSOAPMappingRegistry


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.providers.soap.apachesoap;
59
60 import java.math.BigDecimal JavaDoc;
61
62 import org.apache.soap.Constants;
63 import org.apache.soap.encoding.SOAPMappingRegistry;
64 import org.apache.soap.util.xml.Deserializer;
65 import org.apache.soap.util.xml.QName;
66 import org.apache.soap.util.xml.Serializer;
67 import org.apache.wsif.WSIFConstants;
68 import org.apache.wsif.logging.Trc;
69
70 /**
71  * An extension of SOAPMappingRegistry which can handle SOAP-ENC simple types
72  * @author Owen Burroughs <owenb@apache.org>
73  */

74 public class WSIFSOAPMappingRegistry extends SOAPMappingRegistry {
75
76     /**
77      * Constructor for WSIFSOAPMappingRegistry
78      */

79     public WSIFSOAPMappingRegistry() {
80         super();
81         Trc.entry(this);
82         Trc.exit();
83     }
84
85     /**
86      * Constructor for WSIFSOAPMappingRegistry
87      * @param registry The parent SOAP mapping registry
88      */

89     public WSIFSOAPMappingRegistry(SOAPMappingRegistry registry) {
90         super(registry);
91         Trc.entry(this, registry);
92         Trc.exit();
93     }
94
95     /**
96      * Constructor for WSIFSOAPMappingRegistry
97      * @param registry The parent SOAP mapping registry
98      * @param schemaURI The namespace URI of XSD to be used for serializers.
99      */

100     public WSIFSOAPMappingRegistry(
101         SOAPMappingRegistry registry,
102         String JavaDoc schemaURI) {
103         super(registry, schemaURI);
104         Trc.entry(this, registry, schemaURI);
105         Trc.exit();
106     }
107
108     /**
109      * Get the serializer for the specified class and encoding
110      * @param javaType The class to serialize
111      * @param encodingStyleURI The namespace of the encoding
112      * @return The serializer if found or null otherwise
113      */

114     protected Serializer querySerializer_(
115         Class JavaDoc javaType,
116         String JavaDoc encodingStyleURI) {
117         Trc.entry(this, javaType, encodingStyleURI);
118         Serializer ser = super.querySerializer_(javaType, encodingStyleURI);
119         Trc.exit(ser);
120         return ser;
121     }
122
123     /**
124      * Get the deserializer for the specified element and encoding
125      * @param elementType The element to deserialize
126      * @param encodingStyleURI The namespace of the encoding
127      * @return The deserializer if found or null otherwise
128      */

129     protected Deserializer queryDeserializer_(
130         QName elementType,
131         String JavaDoc encodingStyleURI) {
132         Trc.entry(this, elementType, encodingStyleURI);
133         Deserializer deser = null;
134         if (elementType != null
135             && elementType.getNamespaceURI().equals(
136                 WSIFConstants.NS_URI_SOAP_ENC)) {
137             QName qn = getEquivalentXSDSimpleType(elementType);
138             if (qn != null) {
139                 deser = super.queryDeserializer_(qn, encodingStyleURI);
140             }
141         }
142         if (deser == null) {
143             deser = super.queryDeserializer_(elementType, encodingStyleURI);
144         }
145         Trc.exit(deser);
146         return deser;
147     }
148
149     /**
150      * Find the element type that is mapped to the given Java class
151      * @param javaType The Java class
152      * @param encodingStyleURI The namespace of the encoding
153      * @return The corresponding element type or null is no mapping found
154      */

155     protected QName queryElementType_(
156         Class JavaDoc javaType,
157         String JavaDoc encodingStyleURI) {
158         return super.queryElementType_(javaType, encodingStyleURI);
159     }
160
161     /**
162      * Find the Java class that is mapped to the given element type
163      * @param elementType The element type
164      * @param encodingStyleURI The namespace of the encoding
165      * @return The corresponding Java class or null is no mapping found
166      */

167     protected Class JavaDoc queryJavaType_(
168         QName elementType,
169         String JavaDoc encodingStyleURI) {
170         Class JavaDoc cls = null;
171         if (elementType != null
172             && elementType.getNamespaceURI().equals(
173                 WSIFConstants.NS_URI_SOAP_ENC)) {
174             cls = resolveSOAPENCSimpleType(elementType);
175         }
176         if (cls == null) {
177             return super.queryJavaType_(elementType, encodingStyleURI);
178         }
179         return cls;
180     }
181     
182     private QName getEquivalentXSDSimpleType(QName elementType) {
183         if (elementType == null
184             || !elementType.getNamespaceURI().equals(
185                 WSIFConstants.NS_URI_SOAP_ENC)) {
186             return null;
187         }
188         
189         String JavaDoc lp = elementType.getLocalPart();
190         if (lp == null) {
191             return null;
192         }
193         
194         if (lp.equals("string")) {
195             return new QName(WSIFConstants.NS_URI_2001_SCHEMA_XSD, "string");
196         } else if (lp.equals("boolean")) {
197             return new QName(WSIFConstants.NS_URI_2001_SCHEMA_XSD, "boolean");
198         } else if (lp.equals("float")) {
199             return new QName(WSIFConstants.NS_URI_2001_SCHEMA_XSD, "float");
200         } else if (lp.equals("double")) {
201             return new QName(WSIFConstants.NS_URI_2001_SCHEMA_XSD, "double");
202         } else if (lp.equals("decimal")) {
203             return new QName(WSIFConstants.NS_URI_2001_SCHEMA_XSD, "decimal");
204         } else if (lp.equals("int")) {
205             return new QName(WSIFConstants.NS_URI_2001_SCHEMA_XSD, "int");
206         } else if (lp.equals("short")) {
207             return new QName(WSIFConstants.NS_URI_2001_SCHEMA_XSD, "short");
208         } else if (lp.equals("byte")) {
209             return new QName(WSIFConstants.NS_URI_2001_SCHEMA_XSD, "byte");
210         } else if (lp.equals("base64")) {
211             return new QName(WSIFConstants.NS_URI_2001_SCHEMA_XSD, "base64Binary");
212         } else {
213             return null;
214         }
215     }
216     
217     private Class JavaDoc resolveSOAPENCSimpleType(QName elementType) {
218         if (elementType == null
219             || !elementType.getNamespaceURI().equals(
220                 WSIFConstants.NS_URI_SOAP_ENC)) {
221             return null;
222         }
223         
224         String JavaDoc lp = elementType.getLocalPart();
225         if (lp == null) {
226             return null;
227         }
228         
229         if (lp.equals("string")) {
230             return String JavaDoc.class;
231         } else if (lp.equals("boolean")) {
232             return Boolean JavaDoc.class;
233         } else if (lp.equals("float")) {
234             return Float JavaDoc.class;
235         } else if (lp.equals("double")) {
236             return Double JavaDoc.class;
237         } else if (lp.equals("decimal")) {
238             return BigDecimal JavaDoc.class;
239         } else if (lp.equals("int")) {
240             return Integer JavaDoc.class;
241         } else if (lp.equals("short")) {
242             return Short JavaDoc.class;
243         } else if (lp.equals("byte")) {
244             return Byte JavaDoc.class;
245         } else if (lp.equals("base64")) {
246             return byte[].class;
247         } else {
248             return null;
249         }
250     }
251 }
Popular Tags