KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > axis > encoding > DefaultTypeMappingImpl


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001-2003 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 "Axis" 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. For more
52  * information on the Apache Software Foundation, please see
53  * <http://www.apache.org/>.
54  */

55
56 package org.jboss.axis.encoding;
57
58 import org.jboss.axis.Constants;
59 import org.jboss.axis.attachments.OctetStream;
60 import org.jboss.axis.encoding.ser.*;
61 import org.jboss.axis.schema.SchemaVersion;
62 import org.jboss.axis.types.HexBinary;
63 import org.jboss.axis.utils.JavaUtils;
64 import org.jboss.axis.utils.Messages;
65
66 import javax.xml.namespace.QName JavaDoc;
67 import javax.xml.rpc.JAXRPCException JavaDoc;
68 import javax.xml.rpc.encoding.DeserializerFactory JavaDoc;
69
70 /**
71  * This is the implementation of the axis Default TypeMapping (which extends
72  * the JAX-RPC TypeMapping interface) for SOAP 1.1.
73  * <p/>
74  * A TypeMapping contains tuples as follows:
75  * {Java type, SerializerFactory, DeserializerFactory, Type QName)
76  * <p/>
77  * In other words, it serves to map Java types to and from XML types using
78  * particular Serializers/Deserializers. Each TypeMapping is associated with
79  * one or more encodingStyle URIs.
80  * <p/>
81  * The wsdl in your web service will use a number of types. The tuple
82  * information for each of these will be accessed via the TypeMapping.
83  * <p/>
84  * This TypeMapping is the "default" one, which includes all the standard
85  * SOAP and schema XSD types. Individual TypeMappings (associated with
86  * AxisEngines and SOAPServices) will delegate to this one, so if you haven't
87  * overriden a default mapping we'll end up getting it from here.
88  *
89  * @author Rich Scheuerle (scheu@us.ibm.com)
90  */

91 public class DefaultTypeMappingImpl extends TypeMappingImpl
92 {
93
94    private static DefaultTypeMappingImpl tm = null;
95    private boolean doneInit = false; // have we completed initalization
96

97    /**
98     * Obtain the singleton default typemapping.
99     */

100    public static synchronized TypeMapping getSingleton()
101    {
102       if (tm == null)
103       {
104          tm = new DefaultTypeMappingImpl();
105       }
106       return tm;
107    }
108
109    protected DefaultTypeMappingImpl()
110    {
111       this(false);
112    }
113
114    protected DefaultTypeMappingImpl(boolean encoded)
115    {
116       super(null);
117       delegate = null;
118
119       // Notes:
120
// 1) The registration statements are order dependent. The last one
121
// wins. So if two javaTypes of String are registered, the
122
// ser factory for the last one registered will be chosen. Likewise
123
// if two javaTypes for XSD_DATE are registered, the deserializer
124
// factory for the last one registered will be chosen.
125
// Corollary: Please be very careful with the order. The
126
// runtime, Java2WSDL and WSDL2Java emitters all
127
// use this code to get type mapping information.
128
// 2) Even if the SOAP 1.1 format is used over the wire, an
129
// attempt is made to receive SOAP 1.2 format from the wire.
130
// This is the reason why the soap encoded primitives are
131
// registered without serializers.
132

133       // Since the last-registered type wins, I want to add the mime
134
// String FIRST.
135
if (JavaUtils.isAttachmentSupported())
136       {
137          myRegister(Constants.MIME_PLAINTEXT, java.lang.String JavaDoc.class,
138                  new JAFDataHandlerSerializerFactory(java.lang.String JavaDoc.class,
139                          Constants.MIME_PLAINTEXT),
140                  new JAFDataHandlerDeserializerFactory(java.lang.String JavaDoc.class,
141                          Constants.MIME_PLAINTEXT));
142
143          // Force mapping of String->xsd:hexBinary to map to an attachment since
144
// jaxrpc-1.1 does not allow the mapping. This allows a wsdl declared
145
// mimetype of text/plain to function.
146
myRegister(Constants.XSD_HEXBIN, java.lang.String JavaDoc.class,
147                  new JAFDataHandlerSerializerFactory(java.lang.String JavaDoc.class,
148                          Constants.MIME_PLAINTEXT),
149                  new JAFDataHandlerDeserializerFactory(java.lang.String JavaDoc.class,
150                          Constants.MIME_PLAINTEXT));
151       }
152
153       if (!encoded)
154       {
155          registerSOAPTypes();
156       }
157
158       // HexBinary binary data needs to use the hex binary serializer/deserializer
159
myRegister(Constants.XSD_HEXBIN, HexBinary.class,
160               new HexSerializerFactory(HexBinary.class, Constants.XSD_HEXBIN),
161               new HexDeserializerFactory(HexBinary.class, Constants.XSD_HEXBIN));
162       myRegister(Constants.XSD_HEXBIN, byte[].class,
163               new HexSerializerFactory(byte[].class, Constants.XSD_HEXBIN),
164               new HexDeserializerFactory(byte[].class, Constants.XSD_HEXBIN));
165
166       // SOAP 1.1
167
// byte[] -ser-> XSD_BASE64
168
// XSD_BASE64 -deser-> byte[]
169
// SOAP_BASE64 -deser->byte[]
170
//
171
// Special case:
172
// If serialization is requested for xsd:byte with byte[],
173
// the array serializer is used. If deserialization
174
// is specifically requested for xsd:byte with byte[], the
175
// simple deserializer is used. This is necessary
176
// to support the serialization/deserialization
177
// of <element name="a" type="xsd:byte" maxOccurs="unbounded" />
178
// as discrete bytes without interference with XSD_BASE64.
179
myRegister(Constants.XSD_BYTE, byte[].class,
180               new ArraySerializerFactory(),
181               null);
182
183       myRegister(Constants.XSD_BASE64, byte[].class,
184               new Base64SerializerFactory(byte[].class,
185                       Constants.XSD_BASE64),
186               new Base64DeserializerFactory(byte[].class,
187                       Constants.XSD_BASE64));
188       /*
189       // This JSR 101 change occurred right before v1.0.
190       // This mapping is not roundtrippable, and breaks the roundtrip
191       // testcase, so it is commented out for now.
192       // SOAP 1.1
193       // byte[] -ser-> XSD_BASE64
194       // Byte[] -ser-> XSD_BASE64
195       // XSD_BASE64 -deser-> byte[]
196       // SOAP_BASE64 -deser->byte[]
197       //
198       // NOTE: If the following code is enabled, the
199       // commented out code "//type == Byte[].class ||"
200       // code in org.jboss.axis.wsdl.fromJava.Types also needs to be enabled.
201
202       myRegister(Constants.SOAP_BASE64, byte[].class,
203                  new Base64SerializerFactory(byte[].class,
204                                              Constants.SOAP_BASE64 ),
205                  new Base64DeserializerFactory(byte[].class,
206                                                Constants.SOAP_BASE64),
207                  true);
208       myRegister(Constants.XSD_BASE64, Byte[].class,
209                  new Base64SerializerFactory(Byte[].class,
210                                              Constants.XSD_BASE64 ),
211                  new Base64DeserializerFactory(Byte[].class,
212                                          Constants.XSD_BASE64),true);
213       myRegister(Constants.XSD_BASE64, byte[].class,
214                  new Base64SerializerFactory(byte[].class,
215                                              Constants.XSD_BASE64 ),
216                  new Base64DeserializerFactory(byte[].class,
217                                          Constants.XSD_BASE64),true);
218       */

219
220       // Add anySimpleType as java.lang.String, do this *before* sxd:string
221
// TDI 19-Jun-2004
222
myRegisterSimple(Constants.XSD_ANYSIMPLETYPE, java.lang.String JavaDoc.class);
223
224       myRegister(Constants.XSD_UNSIGNEDLONG, java.math.BigInteger JavaDoc.class,
225               new SimpleSerializerFactory(java.math.BigInteger JavaDoc.class, Constants.XSD_UNSIGNEDLONG),
226               new SimpleDeserializerFactory(java.math.BigInteger JavaDoc.class, Constants.XSD_UNSIGNEDLONG));
227
228       myRegister(Constants.XSD_UNSIGNEDINT, java.lang.Long JavaDoc.class,
229               new SimpleSerializerFactory(java.lang.Long JavaDoc.class, Constants.XSD_UNSIGNEDINT),
230               new SimpleDeserializerFactory(java.lang.Long JavaDoc.class, Constants.XSD_UNSIGNEDINT));
231
232       myRegister(Constants.XSD_UNSIGNEDSHORT, java.lang.Integer JavaDoc.class,
233               new SimpleSerializerFactory(java.lang.Integer JavaDoc.class, Constants.XSD_UNSIGNEDSHORT),
234               new SimpleDeserializerFactory(java.lang.Integer JavaDoc.class, Constants.XSD_UNSIGNEDSHORT));
235
236       myRegister(Constants.XSD_UNSIGNEDBYTE, java.lang.Short JavaDoc.class,
237               new SimpleSerializerFactory(java.lang.Short JavaDoc.class, Constants.XSD_UNSIGNEDBYTE),
238               new SimpleDeserializerFactory(java.lang.Short JavaDoc.class, Constants.XSD_UNSIGNEDBYTE));
239
240       myRegister(Constants.XSD_NONNEGATIVEINTEGER, java.math.BigInteger JavaDoc.class,
241               new SimpleSerializerFactory(java.math.BigInteger JavaDoc.class, Constants.XSD_NONNEGATIVEINTEGER),
242               new SimpleDeserializerFactory(java.math.BigInteger JavaDoc.class, Constants.XSD_NONNEGATIVEINTEGER));
243
244       myRegister(Constants.XSD_NEGATIVEINTEGER, java.math.BigInteger JavaDoc.class,
245               new SimpleSerializerFactory(java.math.BigInteger JavaDoc.class, Constants.XSD_NEGATIVEINTEGER),
246               new SimpleDeserializerFactory(java.math.BigInteger JavaDoc.class, Constants.XSD_NEGATIVEINTEGER));
247
248       myRegister(Constants.XSD_POSITIVEINTEGER, java.math.BigInteger JavaDoc.class,
249               new SimpleSerializerFactory(java.math.BigInteger JavaDoc.class, Constants.XSD_POSITIVEINTEGER),
250               new SimpleDeserializerFactory(java.math.BigInteger JavaDoc.class, Constants.XSD_POSITIVEINTEGER));
251
252       myRegister(Constants.XSD_NONPOSITIVEINTEGER, java.math.BigInteger JavaDoc.class,
253               new SimpleSerializerFactory(java.math.BigInteger JavaDoc.class, Constants.XSD_NONPOSITIVEINTEGER),
254               new SimpleDeserializerFactory(java.math.BigInteger JavaDoc.class, Constants.XSD_NONPOSITIVEINTEGER));
255
256       // Note, the java.net.URI class is not part of JDK-1.3
257
Class JavaDoc uriClass = null;
258       try
259       {
260          uriClass = Class.forName("java.net.URI");
261          myRegisterSimple(Constants.XSD_ANYURI, uriClass);
262       }
263       catch (ClassNotFoundException JavaDoc ignore)
264       {
265          // Add anyURI as java.lang.String, do this *before* xsd:string
266
myRegisterSimple(Constants.XSD_ANYURI, java.lang.String JavaDoc.class);
267       }
268
269       // If SOAP 1.1 over the wire, map wrapper classes to XSD primitives.
270
myRegisterSimple(Constants.XSD_STRING, java.lang.String JavaDoc.class);
271       myRegisterSimple(Constants.XSD_BOOLEAN, java.lang.Boolean JavaDoc.class);
272       myRegisterSimple(Constants.XSD_DOUBLE, java.lang.Double JavaDoc.class);
273       myRegisterSimple(Constants.XSD_FLOAT, java.lang.Float JavaDoc.class);
274       myRegisterSimple(Constants.XSD_INT, java.lang.Integer JavaDoc.class);
275       myRegisterSimple(Constants.XSD_INTEGER, java.math.BigInteger JavaDoc.class);
276       myRegisterSimple(Constants.XSD_DECIMAL, java.math.BigDecimal JavaDoc.class);
277       myRegisterSimple(Constants.XSD_LONG, java.lang.Long JavaDoc.class);
278       myRegisterSimple(Constants.XSD_SHORT, java.lang.Short JavaDoc.class);
279       myRegisterSimple(Constants.XSD_BYTE, java.lang.Byte JavaDoc.class);
280
281       // The XSD Primitives are mapped to java primitives.
282
myRegisterSimple(Constants.XSD_BOOLEAN, boolean.class);
283       myRegisterSimple(Constants.XSD_DOUBLE, double.class);
284       myRegisterSimple(Constants.XSD_FLOAT, float.class);
285       myRegisterSimple(Constants.XSD_INT, int.class);
286       myRegisterSimple(Constants.XSD_LONG, long.class);
287       myRegisterSimple(Constants.XSD_SHORT, short.class);
288       myRegisterSimple(Constants.XSD_BYTE, byte.class);
289
290       // Map QNAME to the jax rpc QName class
291
myRegister(Constants.XSD_QNAME,
292               javax.xml.namespace.QName JavaDoc.class,
293               new QNameSerializerFactory(javax.xml.namespace.QName JavaDoc.class, Constants.XSD_QNAME),
294               new QNameDeserializerFactory(javax.xml.namespace.QName JavaDoc.class, Constants.XSD_QNAME));
295
296       // The closest match for anytype is Object
297
myRegister(Constants.XSD_ANYTYPE, java.lang.Object JavaDoc.class, null, null);
298
299       // Mapping for xsd:date. Map to Axis type Time
300
myRegister(Constants.XSD_DATE, org.jboss.axis.types.Time.class,
301               new SimpleSerializerFactory(org.jboss.axis.types.Time.class, Constants.XSD_DATE),
302               new SimpleDeserializerFactory(org.jboss.axis.types.Time.class, Constants.XSD_DATE));
303
304       // See the SchemaVersion classes for where the registration of
305
// dateTime (for 2001) and timeInstant (for 1999 & 2000) happen.
306
myRegister(Constants.XSD_DATE, java.sql.Date JavaDoc.class,
307               new DateSerializerFactory(java.sql.Date JavaDoc.class, Constants.XSD_DATE),
308               new DateDeserializerFactory(java.sql.Date JavaDoc.class, Constants.XSD_DATE));
309
310       myRegister(Constants.XSD_DATE, java.util.Date JavaDoc.class,
311               new DateSerializerFactory(java.util.Date JavaDoc.class, Constants.XSD_DATE),
312               new DateDeserializerFactory(java.util.Date JavaDoc.class, Constants.XSD_DATE));
313
314       myRegister(Constants.XSD_DATE, java.util.Calendar JavaDoc.class,
315               new DateSerializerFactory(java.util.Calendar JavaDoc.class, Constants.XSD_DATE),
316               new DateDeserializerFactory(java.util.Calendar JavaDoc.class, Constants.XSD_DATE));
317
318       // Mapping for xsd:dateTime. Map to Axis type Time
319
myRegister(Constants.XSD_DATETIME, org.jboss.axis.types.Time.class,
320               new SimpleSerializerFactory(org.jboss.axis.types.Time.class, Constants.XSD_DATETIME),
321               new SimpleDeserializerFactory(org.jboss.axis.types.Time.class, Constants.XSD_DATETIME));
322
323       // Mapping for xsd:time. Map to Axis type Time
324
myRegister(Constants.XSD_TIME, org.jboss.axis.types.Time.class,
325               new SimpleSerializerFactory(org.jboss.axis.types.Time.class, Constants.XSD_TIME),
326               new SimpleDeserializerFactory(org.jboss.axis.types.Time.class, Constants.XSD_TIME));
327
328       // These are the g* types (gYearMonth, etc) which map to Axis types
329
myRegister(Constants.XSD_YEARMONTH, org.jboss.axis.types.YearMonth.class,
330               new SimpleSerializerFactory(org.jboss.axis.types.YearMonth.class,
331                       Constants.XSD_YEARMONTH),
332               new SimpleDeserializerFactory(org.jboss.axis.types.YearMonth.class,
333                       Constants.XSD_YEARMONTH));
334       myRegister(Constants.XSD_YEAR, org.jboss.axis.types.Year.class,
335               new SimpleSerializerFactory(org.jboss.axis.types.Year.class,
336                       Constants.XSD_YEAR),
337               new SimpleDeserializerFactory(org.jboss.axis.types.Year.class,
338                       Constants.XSD_YEAR));
339       myRegister(Constants.XSD_MONTH, org.jboss.axis.types.Month.class,
340               new SimpleSerializerFactory(org.jboss.axis.types.Month.class,
341                       Constants.XSD_MONTH),
342               new SimpleDeserializerFactory(org.jboss.axis.types.Month.class,
343                       Constants.XSD_MONTH));
344       myRegister(Constants.XSD_DAY, org.jboss.axis.types.Day.class,
345               new SimpleSerializerFactory(org.jboss.axis.types.Day.class,
346                       Constants.XSD_DAY),
347               new SimpleDeserializerFactory(org.jboss.axis.types.Day.class,
348                       Constants.XSD_DAY));
349       myRegister(Constants.XSD_MONTHDAY, org.jboss.axis.types.MonthDay.class,
350               new SimpleSerializerFactory(org.jboss.axis.types.MonthDay.class,
351                       Constants.XSD_MONTHDAY),
352               new SimpleDeserializerFactory(org.jboss.axis.types.MonthDay.class,
353                       Constants.XSD_MONTHDAY));
354
355       // Serialize all extensions of Map to SOAP_MAP
356
// The SOAP_MAP will be deserialized into a HashMap by default.
357
myRegister(Constants.SOAP_MAP, java.util.HashMap JavaDoc.class,
358               new MapSerializerFactory(java.util.Map JavaDoc.class,
359                       Constants.SOAP_MAP),
360               new MapDeserializerFactory(java.util.HashMap JavaDoc.class,
361                       Constants.SOAP_MAP));
362       myRegister(Constants.SOAP_MAP, java.util.Hashtable JavaDoc.class,
363               new MapSerializerFactory(java.util.Hashtable JavaDoc.class,
364                       Constants.SOAP_MAP),
365               null // Make sure not to override the deser mapping
366
);
367       myRegister(Constants.SOAP_MAP, java.util.Map JavaDoc.class,
368               new MapSerializerFactory(java.util.Map JavaDoc.class,
369                       Constants.SOAP_MAP),
370               null // Make sure not to override the deser mapping
371
);
372
373       // Use the Element Serializeration for elements
374
myRegister(Constants.SOAP_ELEMENT, org.w3c.dom.Element JavaDoc.class,
375               new ElementSerializerFactory(),
376               new ElementDeserializerFactory());
377
378       // Use the Document Serializeration for Document's
379
myRegister(Constants.SOAP_DOCUMENT, org.w3c.dom.Document JavaDoc.class,
380               new DocumentSerializerFactory(),
381               new DocumentDeserializerFactory());
382
383       myRegister(Constants.SOAP_VECTOR, java.util.Vector JavaDoc.class,
384               new VectorSerializerFactory(java.util.Vector JavaDoc.class,
385                       Constants.SOAP_VECTOR),
386               new VectorDeserializerFactory(java.util.Vector JavaDoc.class,
387                       Constants.SOAP_VECTOR));
388
389       // Register all the supported MIME types
390
// (note that MIME_PLAINTEXT was registered near the top)
391
if (JavaUtils.isAttachmentSupported())
392       {
393          myRegister(Constants.MIME_IMAGE, java.awt.Image JavaDoc.class,
394                  new JAFDataHandlerSerializerFactory(java.awt.Image JavaDoc.class,
395                          Constants.MIME_IMAGE),
396                  new JAFDataHandlerDeserializerFactory(java.awt.Image JavaDoc.class,
397                          Constants.MIME_IMAGE));
398          myRegister(Constants.MIME_MULTIPART, javax.mail.internet.MimeMultipart JavaDoc.class,
399                  new JAFDataHandlerSerializerFactory(javax.mail.internet.MimeMultipart JavaDoc.class,
400                          Constants.MIME_MULTIPART),
401                  new JAFDataHandlerDeserializerFactory(javax.mail.internet.MimeMultipart JavaDoc.class,
402                          Constants.MIME_MULTIPART));
403          myRegister(Constants.MIME_SOURCE, javax.xml.transform.Source JavaDoc.class,
404                  new JAFDataHandlerSerializerFactory(javax.xml.transform.Source JavaDoc.class,
405                          Constants.MIME_SOURCE),
406                  new JAFDataHandlerDeserializerFactory(javax.xml.transform.Source JavaDoc.class,
407                          Constants.MIME_SOURCE));
408          myRegister(Constants.MIME_OCTETSTREAM, OctetStream.class,
409                  new JAFDataHandlerSerializerFactory(OctetStream.class,
410                          Constants.MIME_OCTETSTREAM),
411                  new JAFDataHandlerDeserializerFactory(OctetStream.class,
412                          Constants.MIME_OCTETSTREAM));
413          myRegister(Constants.MIME_DATA_HANDLER, javax.activation.DataHandler JavaDoc.class,
414                  new JAFDataHandlerSerializerFactory(),
415                  new JAFDataHandlerDeserializerFactory());
416       }
417
418       // xsd:token
419
myRegister(Constants.XSD_TOKEN, org.jboss.axis.types.Token.class,
420               new SimpleSerializerFactory(org.jboss.axis.types.Token.class,
421                       Constants.XSD_TOKEN),
422               new SimpleDeserializerFactory(org.jboss.axis.types.Token.class,
423                       Constants.XSD_TOKEN));
424
425       // a xsd:normalizedString
426
myRegister(Constants.XSD_NORMALIZEDSTRING, org.jboss.axis.types.NormalizedString.class,
427               new SimpleSerializerFactory(org.jboss.axis.types.NormalizedString.class,
428                       Constants.XSD_NORMALIZEDSTRING),
429               new SimpleDeserializerFactory(org.jboss.axis.types.NormalizedString.class,
430                       Constants.XSD_NORMALIZEDSTRING));
431
432       // a xsd:Name
433
myRegister(Constants.XSD_NAME, org.jboss.axis.types.Name.class,
434               new SimpleSerializerFactory(org.jboss.axis.types.Name.class,
435                       Constants.XSD_NAME),
436               new SimpleDeserializerFactory(org.jboss.axis.types.Name.class,
437                       Constants.XSD_NAME));
438
439       // a xsd:NCName
440
myRegister(Constants.XSD_NCNAME, org.jboss.axis.types.NCName.class,
441               new SimpleSerializerFactory(org.jboss.axis.types.NCName.class,
442                       Constants.XSD_NCNAME),
443               new SimpleDeserializerFactory(org.jboss.axis.types.NCName.class,
444                       Constants.XSD_NCNAME));
445
446       // a xsd:ID
447
myRegister(Constants.XSD_ID, org.jboss.axis.types.Id.class,
448               new SimpleSerializerFactory(org.jboss.axis.types.Id.class,
449                       Constants.XSD_ID),
450               new SimpleDeserializerFactory(org.jboss.axis.types.Id.class,
451                       Constants.XSD_ID));
452
453       // a xsd:language
454
myRegister(Constants.XSD_LANGUAGE, org.jboss.axis.types.Language.class,
455               new SimpleSerializerFactory(org.jboss.axis.types.Language.class,
456                       Constants.XSD_LANGUAGE),
457               new SimpleDeserializerFactory(org.jboss.axis.types.Language.class,
458                       Constants.XSD_LANGUAGE));
459
460       // a xml:lang
461
myRegister(Constants.XML_LANG, org.jboss.axis.types.Language.class,
462               new SimpleSerializerFactory(org.jboss.axis.types.Language.class,
463                       Constants.XML_LANG),
464               new SimpleDeserializerFactory(org.jboss.axis.types.Language.class,
465                       Constants.XML_LANG));
466
467       // a xsd:NmToken
468
myRegister(Constants.XSD_NMTOKEN, org.jboss.axis.types.NMToken.class,
469               new SimpleSerializerFactory(org.jboss.axis.types.NMToken.class,
470                       Constants.XSD_NMTOKEN),
471               new SimpleDeserializerFactory(org.jboss.axis.types.NMToken.class,
472                       Constants.XSD_NMTOKEN));
473
474       // a xsd:NmTokens
475
myRegister(Constants.XSD_NMTOKENS, org.jboss.axis.types.NMTokens.class,
476               new SimpleSerializerFactory(org.jboss.axis.types.NMTokens.class,
477                       Constants.XSD_NMTOKENS),
478               new SimpleDeserializerFactory(org.jboss.axis.types.NMTokens.class,
479                       Constants.XSD_NMTOKENS));
480
481       // a xsd:NOTATION
482
myRegister(Constants.XSD_NOTATION, org.jboss.axis.types.Notation.class,
483               new BeanSerializerFactory(org.jboss.axis.types.Notation.class,
484                       Constants.XSD_NOTATION),
485               new BeanDeserializerFactory(org.jboss.axis.types.Notation.class,
486                       Constants.XSD_NOTATION));
487
488       // a xsd:XSD_ENTITY
489
myRegister(Constants.XSD_ENTITY, org.jboss.axis.types.Entity.class,
490               new SimpleSerializerFactory(org.jboss.axis.types.Entity.class,
491                       Constants.XSD_ENTITY),
492               new SimpleDeserializerFactory(org.jboss.axis.types.Entity.class,
493                       Constants.XSD_ENTITY));
494
495       // a xsd:XSD_ENTITIES
496
myRegister(Constants.XSD_ENTITIES, org.jboss.axis.types.Entities.class,
497               new SimpleSerializerFactory(org.jboss.axis.types.Entities.class,
498                       Constants.XSD_ENTITIES),
499               new SimpleDeserializerFactory(org.jboss.axis.types.Entities.class,
500                       Constants.XSD_ENTITIES));
501
502       // a xsd:XSD_IDREF
503
myRegister(Constants.XSD_IDREF, org.jboss.axis.types.IDRef.class,
504               new SimpleSerializerFactory(org.jboss.axis.types.IDRef.class,
505                       Constants.XSD_IDREF),
506               new SimpleDeserializerFactory(org.jboss.axis.types.IDRef.class,
507                       Constants.XSD_IDREF));
508
509       // a xsd:XSD_XSD_IDREFS
510
myRegister(Constants.XSD_IDREFS, org.jboss.axis.types.IDRefs.class,
511               new SimpleSerializerFactory(org.jboss.axis.types.IDRefs.class,
512                       Constants.XSD_IDREFS),
513               new SimpleDeserializerFactory(org.jboss.axis.types.IDRefs.class,
514                       Constants.XSD_IDREFS));
515
516       // a xsd:Duration
517
myRegister(Constants.XSD_DURATION, org.jboss.axis.types.Duration.class,
518               new SimpleSerializerFactory(org.jboss.axis.types.Duration.class,
519                       Constants.XSD_DURATION),
520               new SimpleDeserializerFactory(org.jboss.axis.types.Duration.class,
521                       Constants.XSD_DURATION));
522
523       // a xsd:anyURI
524
myRegister(Constants.XSD_ANYURI, org.jboss.axis.types.URI.class,
525               new SimpleSerializerFactory(org.jboss.axis.types.URI.class, Constants.XSD_ANYURI),
526               new SimpleDeserializerFactory(org.jboss.axis.types.URI.class, Constants.XSD_ANYURI));
527
528       // a xsd:schema
529
myRegister(Constants.XSD_SCHEMA, org.jboss.axis.types.Schema.class,
530               new BeanSerializerFactory(org.jboss.axis.types.Schema.class,
531                       Constants.XSD_SCHEMA),
532               new BeanDeserializerFactory(org.jboss.axis.types.Schema.class,
533                       Constants.XSD_SCHEMA));
534
535       // TODO: move it to the DefaultSOAPEncodingTypeMappingImpl class
536
myRegister(Constants.SOAP_ARRAY12, java.util.Collection JavaDoc.class,
537               new ArraySerializerFactory(),
538               new ArrayDeserializerFactory());
539       // TODO: move it to the DefaultSOAPEncodingTypeMappingImpl class
540
myRegister(Constants.SOAP_ARRAY12, java.util.ArrayList JavaDoc.class,
541               new ArraySerializerFactory(),
542               new ArrayDeserializerFactory());
543
544       myRegister(Constants.SOAP_ARRAY12, Object JavaDoc[].class,
545               new ArraySerializerFactory(),
546               new ArrayDeserializerFactory());
547
548       myRegister(Constants.SOAP_ARRAY, java.util.ArrayList JavaDoc.class,
549               new ArraySerializerFactory(),
550               new ArrayDeserializerFactory());
551       // All array objects automatically get associated with the SOAP_ARRAY.
552
// There is no way to do this with a hash table,
553
// so it is done directly in getTypeQName.
554
// Internally the runtime uses ArrayList objects to hold arrays...
555
// which is the reason that ArrayList is associated with SOAP_ARRAY.
556
// In addition, handle all objects that implement the List interface
557
// as a SOAP_ARRAY
558
myRegister(Constants.SOAP_ARRAY, java.util.Collection JavaDoc.class,
559               new ArraySerializerFactory(),
560               new ArrayDeserializerFactory());
561
562       myRegister(Constants.SOAP_ARRAY, Object JavaDoc[].class,
563               new ArraySerializerFactory(),
564               new ArrayDeserializerFactory());
565
566       //
567
// Now register the schema specific types
568
//
569
SchemaVersion.SCHEMA_1999.registerSchemaSpecificTypes(this);
570       SchemaVersion.SCHEMA_2000.registerSchemaSpecificTypes(this);
571       SchemaVersion.SCHEMA_2001.registerSchemaSpecificTypes(this);
572
573       if (encoded)
574       {
575          registerSOAPTypes();
576       }
577
578       doneInit = true;
579    }
580
581    /**
582     * Register the SOAP encoding data types. This is split out into a
583     * method so it can happen either before or after the XSD mappings.
584     */

585    private void registerSOAPTypes()
586    {
587       // SOAP Encoded strings are treated as primitives.
588
// Everything else is not.
589
myRegisterSimple(Constants.SOAP_STRING, java.lang.String JavaDoc.class);
590       myRegisterSimple(Constants.SOAP_BOOLEAN, java.lang.Boolean JavaDoc.class);
591       myRegisterSimple(Constants.SOAP_DOUBLE, java.lang.Double JavaDoc.class);
592       myRegisterSimple(Constants.SOAP_FLOAT, java.lang.Float JavaDoc.class);
593       myRegisterSimple(Constants.SOAP_INT, java.lang.Integer JavaDoc.class);
594       myRegisterSimple(Constants.SOAP_INTEGER, java.math.BigInteger JavaDoc.class);
595       myRegisterSimple(Constants.SOAP_DECIMAL, java.math.BigDecimal JavaDoc.class);
596       myRegisterSimple(Constants.SOAP_LONG, java.lang.Long JavaDoc.class);
597       myRegisterSimple(Constants.SOAP_SHORT, java.lang.Short JavaDoc.class);
598       myRegisterSimple(Constants.SOAP_BYTE, java.lang.Byte JavaDoc.class);
599       myRegister(Constants.SOAP_BASE64, byte[].class,
600               new Base64SerializerFactory(byte[].class,
601                       Constants.SOAP_BASE64),
602               new Base64DeserializerFactory(byte[].class,
603                       Constants.SOAP_BASE64));
604       myRegister(Constants.SOAP_BASE64BINARY, byte[].class,
605               new Base64SerializerFactory(byte[].class,
606                       Constants.SOAP_BASE64),
607               new Base64DeserializerFactory(byte[].class,
608                       Constants.SOAP_BASE64));
609    }
610
611    /**
612     * Register a "simple" type mapping - in other words, a
613     *
614     * @param xmlType
615     * @param javaType
616     */

617    protected void myRegisterSimple(QName JavaDoc xmlType, Class JavaDoc javaType)
618    {
619       SerializerFactory sf = new SimpleSerializerFactory(javaType, xmlType);
620       DeserializerFactory df = null;
621       if (javaType != java.lang.Object JavaDoc.class)
622       {
623          df = new SimpleDeserializerFactory(javaType, xmlType);
624       }
625
626       myRegister(xmlType, javaType, sf, df);
627    }
628
629    /**
630     * Construct TypeMapping for all the [xmlType, javaType] for all of the
631     * known xmlType namespaces. This is the shotgun approach, which works
632     * in 99% of the cases. The other cases that are Schema version specific
633     * (i.e. timeInstant vs. dateTime) are handled by the SchemaVersion
634     * Interface registerSchemaSpecificTypes().
635     *
636     * @param xmlType is the QName type
637     * @param javaType is the java type
638     * @param sf is the ser factory (if null, the simple factory is used)
639     * @param df is the deser factory (if null, the simple factory is used)
640     */

641    protected void myRegister(QName JavaDoc xmlType, Class JavaDoc javaType,
642                              SerializerFactory sf, DeserializerFactory df)
643    {
644       // Register all known flavors of the namespace.
645
try
646       {
647          if (xmlType.getNamespaceURI().equals(Constants.URI_DEFAULT_SCHEMA_XSD))
648          {
649             for (int i = 0; i < Constants.URIS_SCHEMA_XSD.length; i++)
650             {
651                QName JavaDoc qName = new QName JavaDoc(Constants.URIS_SCHEMA_XSD[i],
652                        xmlType.getLocalPart());
653                super.internalRegister(javaType, qName, sf, df);
654             }
655          }
656          else if (xmlType.getNamespaceURI().equals(Constants.URI_DEFAULT_SOAP_ENC))
657          {
658             for (int i = 0; i < Constants.URIS_SOAP_ENC.length; i++)
659             {
660                QName JavaDoc qName = new QName JavaDoc(Constants.URIS_SOAP_ENC[i],
661                        xmlType.getLocalPart());
662                super.internalRegister(javaType, qName, sf, df);
663             }
664          }
665          // Register with the specified xmlType.
666
// This is the prefered mapping and the last registed one wins
667
super.internalRegister(javaType, xmlType, sf, df);
668       }
669       catch (JAXRPCException JavaDoc e)
670       {
671       }
672    }
673
674    // Don't allow anyone to muck with the default type mapping because
675
// it is a singleton used for the whole system.
676
public void register(Class JavaDoc javaType, QName JavaDoc xmlType,
677                         javax.xml.rpc.encoding.SerializerFactory JavaDoc sf,
678                         javax.xml.rpc.encoding.DeserializerFactory JavaDoc dsf)
679            throws JAXRPCException JavaDoc
680    {
681
682       // Don't allow anyone but init to modify us.
683
if (doneInit)
684       {
685          throw new JAXRPCException JavaDoc(Messages.getMessage("fixedTypeMapping"));
686       }
687       else
688       {
689          super.register(javaType, xmlType, sf, dsf);
690       }
691    }
692
693    public void removeSerializer(Class JavaDoc javaType, QName JavaDoc xmlType)
694            throws JAXRPCException JavaDoc
695    {
696       throw new JAXRPCException JavaDoc(Messages.getMessage("fixedTypeMapping"));
697    }
698
699    public void removeDeserializer(Class JavaDoc javaType, QName JavaDoc xmlType)
700            throws JAXRPCException JavaDoc
701    {
702       throw new JAXRPCException JavaDoc(Messages.getMessage("fixedTypeMapping"));
703    }
704
705    public void setSupportedEncodings(String JavaDoc[] namespaceURIs)
706    {
707    }
708 }
709
Popular Tags