KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.axis.encoding;
18
19 import org.apache.axis.Constants;
20 import org.apache.axis.attachments.OctetStream;
21 import org.apache.axis.encoding.ser.ArrayDeserializerFactory;
22 import org.apache.axis.encoding.ser.ArraySerializerFactory;
23 import org.apache.axis.encoding.ser.Base64DeserializerFactory;
24 import org.apache.axis.encoding.ser.Base64SerializerFactory;
25 import org.apache.axis.encoding.ser.BeanDeserializerFactory;
26 import org.apache.axis.encoding.ser.BeanSerializerFactory;
27 import org.apache.axis.encoding.ser.DateDeserializerFactory;
28 import org.apache.axis.encoding.ser.DateSerializerFactory;
29 import org.apache.axis.encoding.ser.DocumentDeserializerFactory;
30 import org.apache.axis.encoding.ser.DocumentSerializerFactory;
31 import org.apache.axis.encoding.ser.ElementDeserializerFactory;
32 import org.apache.axis.encoding.ser.ElementSerializerFactory;
33 import org.apache.axis.encoding.ser.HexDeserializerFactory;
34 import org.apache.axis.encoding.ser.HexSerializerFactory;
35 import org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory;
36 import org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory;
37 import org.apache.axis.encoding.ser.MapDeserializerFactory;
38 import org.apache.axis.encoding.ser.MapSerializerFactory;
39 import org.apache.axis.encoding.ser.QNameDeserializerFactory;
40 import org.apache.axis.encoding.ser.QNameSerializerFactory;
41 import org.apache.axis.encoding.ser.SimpleDeserializerFactory;
42 import org.apache.axis.encoding.ser.SimpleSerializerFactory;
43 import org.apache.axis.encoding.ser.VectorDeserializerFactory;
44 import org.apache.axis.encoding.ser.VectorSerializerFactory;
45 import org.apache.axis.schema.SchemaVersion;
46 import org.apache.axis.types.HexBinary;
47 import org.apache.axis.utils.JavaUtils;
48 import org.apache.axis.utils.Messages;
49
50 import javax.xml.namespace.QName JavaDoc;
51 import javax.xml.rpc.JAXRPCException JavaDoc;
52 import javax.xml.rpc.encoding.DeserializerFactory JavaDoc;
53
54 /**
55  * This is the implementation of the axis Default TypeMapping (which extends
56  * the JAX-RPC TypeMapping interface) for SOAP 1.1.
57  *
58  * A TypeMapping contains tuples as follows:
59  * {Java type, SerializerFactory, DeserializerFactory, Type QName)
60  *
61  * In other words, it serves to map Java types to and from XML types using
62  * particular Serializers/Deserializers. Each TypeMapping is associated with
63  * one or more encodingStyle URIs.
64  *
65  * The wsdl in your web service will use a number of types. The tuple
66  * information for each of these will be accessed via the TypeMapping.
67  *
68  * This TypeMapping is the "default" one, which includes all the standard
69  * SOAP and schema XSD types. Individual TypeMappings (associated with
70  * AxisEngines and SOAPServices) will delegate to this one, so if you haven't
71  * overriden a default mapping we'll end up getting it from here.
72  *
73  * @author Rich Scheuerle (scheu@us.ibm.com)
74  */

75 public class DefaultTypeMappingImpl extends TypeMappingImpl {
76
77     private static DefaultTypeMappingImpl tm = null;
78     private boolean inInitMappings = false;
79
80     /**
81      * Obtain the singleton default typemapping.
82      */

83     public static synchronized TypeMappingDelegate getSingletonDelegate() {
84         if (tm == null) {
85             tm = new DefaultTypeMappingImpl();
86         }
87         return new TypeMappingDelegate(tm);
88     }
89
90     protected DefaultTypeMappingImpl() {
91         initMappings();
92     }
93
94     protected DefaultTypeMappingImpl(boolean noMappings) {
95         if (!noMappings) {
96             initMappings();
97         }
98     }
99
100     protected void initMappings() {
101         inInitMappings = true;
102
103         // Notes:
104
// 1) The registration statements are order dependent. The last one
105
// wins. So if two javaTypes of String are registered, the
106
// ser factory for the last one registered will be chosen. Likewise
107
// if two javaTypes for XSD_DATE are registered, the deserializer
108
// factory for the last one registered will be chosen.
109
// Corollary: Please be very careful with the order. The
110
// runtime, Java2WSDL and WSDL2Java emitters all
111
// use this code to get type mapping information.
112
// 2) Even if the SOAP 1.1 format is used over the wire, an
113
// attempt is made to receive SOAP 1.2 format from the wire.
114
// This is the reason why the soap encoded primitives are
115
// registered without serializers.
116

117         // Since the last-registered type wins, I want to add the mime
118
// String FIRST.
119
if (JavaUtils.isAttachmentSupported()) {
120             myRegister(Constants.MIME_PLAINTEXT, java.lang.String JavaDoc.class,
121                     new JAFDataHandlerSerializerFactory(
122                             java.lang.String JavaDoc.class,
123                             Constants.MIME_PLAINTEXT),
124                     new JAFDataHandlerDeserializerFactory(
125                             java.lang.String JavaDoc.class,
126                             Constants.MIME_PLAINTEXT));
127         }
128
129         // HexBinary binary data needs to use the hex binary serializer/deserializer
130
myRegister(Constants.XSD_HEXBIN, HexBinary.class,
131                    new HexSerializerFactory(
132                         HexBinary.class, Constants.XSD_HEXBIN),
133                    new HexDeserializerFactory(
134                         HexBinary.class, Constants.XSD_HEXBIN));
135         myRegister(Constants.XSD_HEXBIN, byte[].class,
136                    new HexSerializerFactory(
137                         byte[].class, Constants.XSD_HEXBIN),
138                    new HexDeserializerFactory(
139                         byte[].class, Constants.XSD_HEXBIN));
140
141         // SOAP 1.1
142
// byte[] -ser-> XSD_BASE64
143
// XSD_BASE64 -deser-> byte[]
144
// SOAP_BASE64 -deser->byte[]
145
//
146
// Special case:
147
// If serialization is requested for xsd:byte with byte[],
148
// the array serializer is used. If deserialization
149
// is specifically requested for xsd:byte with byte[], the
150
// simple deserializer is used. This is necessary
151
// to support the serialization/deserialization
152
// of <element name="a" type="xsd:byte" maxOccurs="unbounded" />
153
// as discrete bytes without interference with XSD_BASE64.
154
myRegister(Constants.XSD_BYTE, byte[].class,
155                    new ArraySerializerFactory(),
156                    null
157         );
158
159         myRegister(Constants.XSD_BASE64, byte[].class,
160                    new Base64SerializerFactory(byte[].class,
161                                                Constants.XSD_BASE64 ),
162                    new Base64DeserializerFactory(byte[].class,
163                                            Constants.XSD_BASE64));
164
165         // anySimpleType is mapped to java.lang.String according to JAX-RPC 1.1 spec.
166
myRegisterSimple(Constants.XSD_ANYSIMPLETYPE, java.lang.String JavaDoc.class);
167         
168         // If SOAP 1.1 over the wire, map wrapper classes to XSD primitives.
169
myRegisterSimple(Constants.XSD_STRING, java.lang.String JavaDoc.class);
170         myRegisterSimple(Constants.XSD_BOOLEAN, java.lang.Boolean JavaDoc.class);
171         myRegisterSimple(Constants.XSD_DOUBLE, java.lang.Double JavaDoc.class);
172         myRegisterSimple(Constants.XSD_FLOAT, java.lang.Float JavaDoc.class);
173         myRegisterSimple(Constants.XSD_INT, java.lang.Integer JavaDoc.class);
174         myRegisterSimple(Constants.XSD_INTEGER, java.math.BigInteger JavaDoc.class
175         );
176         myRegisterSimple(Constants.XSD_DECIMAL, java.math.BigDecimal JavaDoc.class
177         );
178         myRegisterSimple(Constants.XSD_LONG, java.lang.Long JavaDoc.class);
179         myRegisterSimple(Constants.XSD_SHORT, java.lang.Short JavaDoc.class);
180         myRegisterSimple(Constants.XSD_BYTE, java.lang.Byte JavaDoc.class);
181
182         // The XSD Primitives are mapped to java primitives.
183
myRegisterSimple(Constants.XSD_BOOLEAN, boolean.class);
184         myRegisterSimple(Constants.XSD_DOUBLE, double.class);
185         myRegisterSimple(Constants.XSD_FLOAT, float.class);
186         myRegisterSimple(Constants.XSD_INT, int.class);
187         myRegisterSimple(Constants.XSD_LONG, long.class);
188         myRegisterSimple(Constants.XSD_SHORT, short.class);
189         myRegisterSimple(Constants.XSD_BYTE, byte.class);
190
191         // Map QNAME to the jax rpc QName class
192
myRegister(Constants.XSD_QNAME,
193               javax.xml.namespace.QName JavaDoc.class,
194               new QNameSerializerFactory(javax.xml.namespace.QName JavaDoc.class,
195                                         Constants.XSD_QNAME),
196               new QNameDeserializerFactory(javax.xml.namespace.QName JavaDoc.class,
197                                         Constants.XSD_QNAME)
198         );
199
200         // The closest match for anytype is Object
201
myRegister(Constants.XSD_ANYTYPE, java.lang.Object JavaDoc.class,
202                    null, null);
203
204         // See the SchemaVersion classes for where the registration of
205
// dateTime (for 2001) and timeInstant (for 1999 & 2000) happen.
206
myRegister(Constants.XSD_DATE, java.sql.Date JavaDoc.class,
207                    new DateSerializerFactory(java.sql.Date JavaDoc.class,
208                                              Constants.XSD_DATE),
209                    new DateDeserializerFactory(java.sql.Date JavaDoc.class,
210                                                Constants.XSD_DATE)
211         );
212
213         // See the SchemaVersion classes for where the registration of
214
// dateTime (for 2001) and timeInstant (for 1999 & 2000) happen.
215
myRegister(Constants.XSD_DATE, java.util.Date JavaDoc.class,
216                    new DateSerializerFactory(java.util.Date JavaDoc.class,
217                                              Constants.XSD_DATE),
218                    new DateDeserializerFactory(java.util.Date JavaDoc.class,
219                                                Constants.XSD_DATE)
220         );
221
222         // Mapping for xsd:time. Map to Axis type Time
223
myRegister(Constants.XSD_TIME, org.apache.axis.types.Time.class,
224                    new SimpleSerializerFactory(org.apache.axis.types.Time.class,
225                                              Constants.XSD_TIME),
226                    new SimpleDeserializerFactory(org.apache.axis.types.Time.class,
227                                                Constants.XSD_TIME)
228         );
229         // These are the g* types (gYearMonth, etc) which map to Axis types
230
myRegister(Constants.XSD_YEARMONTH, org.apache.axis.types.YearMonth.class,
231                    new SimpleSerializerFactory(org.apache.axis.types.YearMonth.class,
232                                              Constants.XSD_YEARMONTH),
233                    new SimpleDeserializerFactory(org.apache.axis.types.YearMonth.class,
234                                              Constants.XSD_YEARMONTH)
235         );
236         myRegister(Constants.XSD_YEAR, org.apache.axis.types.Year.class,
237                    new SimpleSerializerFactory(org.apache.axis.types.Year.class,
238                                              Constants.XSD_YEAR),
239                    new SimpleDeserializerFactory(org.apache.axis.types.Year.class,
240                                              Constants.XSD_YEAR)
241         );
242         myRegister(Constants.XSD_MONTH, org.apache.axis.types.Month.class,
243                    new SimpleSerializerFactory(org.apache.axis.types.Month.class,
244                                              Constants.XSD_MONTH),
245                    new SimpleDeserializerFactory(org.apache.axis.types.Month.class,
246                                              Constants.XSD_MONTH)
247         );
248         myRegister(Constants.XSD_DAY, org.apache.axis.types.Day.class,
249                    new SimpleSerializerFactory(org.apache.axis.types.Day.class,
250                                              Constants.XSD_DAY),
251                    new SimpleDeserializerFactory(org.apache.axis.types.Day.class,
252                                              Constants.XSD_DAY)
253         );
254         myRegister(Constants.XSD_MONTHDAY, org.apache.axis.types.MonthDay.class,
255                    new SimpleSerializerFactory(org.apache.axis.types.MonthDay.class,
256                                              Constants.XSD_MONTHDAY),
257                    new SimpleDeserializerFactory(org.apache.axis.types.MonthDay.class,
258                                              Constants.XSD_MONTHDAY)
259         );
260
261         // Serialize all extensions of Map to SOAP_MAP
262
// Order counts here, HashMap should be last.
263
myRegister(Constants.SOAP_MAP, java.util.Hashtable JavaDoc.class,
264                    new MapSerializerFactory(java.util.Hashtable JavaDoc.class,
265                                             Constants.SOAP_MAP),
266                    null // Make sure not to override the deser mapping
267
);
268         myRegister(Constants.SOAP_MAP, java.util.Map JavaDoc.class,
269                    new MapSerializerFactory(java.util.Map JavaDoc.class,
270                                             Constants.SOAP_MAP),
271                    null // Make sure not to override the deser mapping
272
);
273         // The SOAP_MAP will be deserialized into a HashMap by default.
274
myRegister(Constants.SOAP_MAP, java.util.HashMap JavaDoc.class,
275                    new MapSerializerFactory(java.util.Map JavaDoc.class,
276                                             Constants.SOAP_MAP),
277                    new MapDeserializerFactory(java.util.HashMap JavaDoc.class,
278                                               Constants.SOAP_MAP)
279         );
280
281         // Use the Element Serializeration for elements
282
myRegister(Constants.SOAP_ELEMENT, org.w3c.dom.Element JavaDoc.class,
283                    new ElementSerializerFactory(),
284                    new ElementDeserializerFactory());
285
286         // Use the Document Serializeration for Document's
287
myRegister(Constants.SOAP_DOCUMENT, org.w3c.dom.Document JavaDoc.class,
288                    new DocumentSerializerFactory(),
289                    new DocumentDeserializerFactory());
290
291         myRegister(Constants.SOAP_VECTOR, java.util.Vector JavaDoc.class,
292                    new VectorSerializerFactory(java.util.Vector JavaDoc.class,
293                                                Constants.SOAP_VECTOR),
294                    new VectorDeserializerFactory(java.util.Vector JavaDoc.class,
295                                                  Constants.SOAP_VECTOR)
296         );
297
298         // Register all the supported MIME types
299
// (note that MIME_PLAINTEXT was registered near the top)
300
if (JavaUtils.isAttachmentSupported()) {
301             myRegister(Constants.MIME_IMAGE, java.awt.Image JavaDoc.class,
302                     new JAFDataHandlerSerializerFactory(
303                             java.awt.Image JavaDoc.class,
304                             Constants.MIME_IMAGE),
305                     new JAFDataHandlerDeserializerFactory(
306                             java.awt.Image JavaDoc.class,
307                             Constants.MIME_IMAGE));
308             myRegister(Constants.MIME_MULTIPART, javax.mail.internet.MimeMultipart JavaDoc.class,
309                     new JAFDataHandlerSerializerFactory(
310                             javax.mail.internet.MimeMultipart JavaDoc.class,
311                             Constants.MIME_MULTIPART),
312                     new JAFDataHandlerDeserializerFactory(
313                             javax.mail.internet.MimeMultipart JavaDoc.class,
314                             Constants.MIME_MULTIPART));
315             myRegister(Constants.MIME_SOURCE, javax.xml.transform.Source JavaDoc.class,
316                     new JAFDataHandlerSerializerFactory(
317                             javax.xml.transform.Source JavaDoc.class,
318                             Constants.MIME_SOURCE),
319                     new JAFDataHandlerDeserializerFactory(
320                             javax.xml.transform.Source JavaDoc.class,
321                             Constants.MIME_SOURCE));
322             myRegister(Constants.MIME_OCTETSTREAM, OctetStream.class,
323                     new JAFDataHandlerSerializerFactory(
324                             OctetStream.class,
325                             Constants.MIME_OCTETSTREAM),
326                     new JAFDataHandlerDeserializerFactory(
327                             OctetStream.class,
328                             Constants.MIME_OCTETSTREAM));
329             myRegister(Constants.MIME_DATA_HANDLER, javax.activation.DataHandler JavaDoc.class,
330                     new JAFDataHandlerSerializerFactory(),
331                     new JAFDataHandlerDeserializerFactory());
332         }
333
334         // xsd:token
335
myRegister(Constants.XSD_TOKEN, org.apache.axis.types.Token.class,
336                    new SimpleSerializerFactory(org.apache.axis.types.Token.class,
337                                              Constants.XSD_TOKEN),
338                    new SimpleDeserializerFactory(org.apache.axis.types.Token.class,
339                                              Constants.XSD_TOKEN)
340         );
341
342         // a xsd:normalizedString
343
myRegister(Constants.XSD_NORMALIZEDSTRING, org.apache.axis.types.NormalizedString.class,
344                    new SimpleSerializerFactory(org.apache.axis.types.NormalizedString.class,
345                                              Constants.XSD_NORMALIZEDSTRING),
346                    new SimpleDeserializerFactory(org.apache.axis.types.NormalizedString.class,
347                                              Constants.XSD_NORMALIZEDSTRING)
348         );
349
350         // a xsd:unsignedLong
351
myRegister(Constants.XSD_UNSIGNEDLONG, org.apache.axis.types.UnsignedLong.class,
352              new SimpleSerializerFactory(org.apache.axis.types.UnsignedLong.class,
353                                                   Constants.XSD_UNSIGNEDLONG),
354              new SimpleDeserializerFactory(org.apache.axis.types.UnsignedLong.class,
355                                            Constants.XSD_UNSIGNEDLONG)
356         );
357
358         // a xsd:unsignedInt
359
myRegister(Constants.XSD_UNSIGNEDINT, org.apache.axis.types.UnsignedInt.class,
360              new SimpleSerializerFactory(org.apache.axis.types.UnsignedInt.class,
361                                                   Constants.XSD_UNSIGNEDINT),
362              new SimpleDeserializerFactory(org.apache.axis.types.UnsignedInt.class,
363                                            Constants.XSD_UNSIGNEDINT)
364         );
365
366         // a xsd:unsignedShort
367
myRegister(Constants.XSD_UNSIGNEDSHORT, org.apache.axis.types.UnsignedShort.class,
368              new SimpleSerializerFactory(org.apache.axis.types.UnsignedShort.class,
369                                                   Constants.XSD_UNSIGNEDSHORT),
370              new SimpleDeserializerFactory(org.apache.axis.types.UnsignedShort.class,
371                                            Constants.XSD_UNSIGNEDSHORT)
372         );
373
374         // a xsd:unsignedByte
375
myRegister(Constants.XSD_UNSIGNEDBYTE, org.apache.axis.types.UnsignedByte.class,
376                    new SimpleSerializerFactory(org.apache.axis.types.UnsignedByte.class,
377                                              Constants.XSD_UNSIGNEDBYTE),
378                    new SimpleDeserializerFactory(org.apache.axis.types.UnsignedByte.class,
379                                              Constants.XSD_UNSIGNEDBYTE)
380         );
381
382         // a xsd:nonNegativeInteger
383
myRegister(Constants.XSD_NONNEGATIVEINTEGER, org.apache.axis.types.NonNegativeInteger.class,
384              new SimpleSerializerFactory(org.apache.axis.types.NonNegativeInteger.class,
385                                                   Constants.XSD_NONNEGATIVEINTEGER),
386              new SimpleDeserializerFactory(org.apache.axis.types.NonNegativeInteger.class,
387                                            Constants.XSD_NONNEGATIVEINTEGER)
388         );
389
390         // a xsd:negativeInteger
391
myRegister(Constants.XSD_NEGATIVEINTEGER, org.apache.axis.types.NegativeInteger.class,
392              new SimpleSerializerFactory(org.apache.axis.types.NegativeInteger.class,
393                                                   Constants.XSD_NEGATIVEINTEGER),
394              new SimpleDeserializerFactory(org.apache.axis.types.NegativeInteger.class,
395                                            Constants.XSD_NEGATIVEINTEGER)
396         );
397
398         // a xsd:positiveInteger
399
myRegister(Constants.XSD_POSITIVEINTEGER, org.apache.axis.types.PositiveInteger.class,
400              new SimpleSerializerFactory(org.apache.axis.types.PositiveInteger.class,
401                                                   Constants.XSD_POSITIVEINTEGER),
402              new SimpleDeserializerFactory(org.apache.axis.types.PositiveInteger.class,
403                                            Constants.XSD_POSITIVEINTEGER)
404         );
405
406         // a xsd:nonPositiveInteger
407
myRegister(Constants.XSD_NONPOSITIVEINTEGER, org.apache.axis.types.NonPositiveInteger.class,
408              new SimpleSerializerFactory(org.apache.axis.types.NonPositiveInteger.class,
409                                                   Constants.XSD_NONPOSITIVEINTEGER),
410              new SimpleDeserializerFactory(org.apache.axis.types.NonPositiveInteger.class,
411                                            Constants.XSD_NONPOSITIVEINTEGER)
412         );
413
414         // a xsd:Name
415
myRegister(Constants.XSD_NAME, org.apache.axis.types.Name.class,
416                    new SimpleSerializerFactory(org.apache.axis.types.Name.class,
417                                              Constants.XSD_NAME),
418                    new SimpleDeserializerFactory(org.apache.axis.types.Name.class,
419                                              Constants.XSD_NAME)
420         );
421
422         // a xsd:NCName
423
myRegister(Constants.XSD_NCNAME, org.apache.axis.types.NCName.class,
424                    new SimpleSerializerFactory(org.apache.axis.types.NCName.class,
425                                              Constants.XSD_NCNAME),
426                    new SimpleDeserializerFactory(org.apache.axis.types.NCName.class,
427                                              Constants.XSD_NCNAME)
428         );
429
430          // a xsd:ID
431
myRegister(Constants.XSD_ID, org.apache.axis.types.Id.class,
432                    new SimpleSerializerFactory(org.apache.axis.types.Id.class,
433                                              Constants.XSD_ID),
434                    new SimpleDeserializerFactory(org.apache.axis.types.Id.class,
435                                              Constants.XSD_ID)
436         );
437
438         // a xml:lang
439
myRegister(Constants.XML_LANG, org.apache.axis.types.Language.class,
440                    new SimpleSerializerFactory(org.apache.axis.types.Language.class,
441                                              Constants.XML_LANG),
442                    new SimpleDeserializerFactory(org.apache.axis.types.Language.class,
443                                              Constants.XML_LANG)
444         );
445         
446         // a xsd:language
447
myRegister(Constants.XSD_LANGUAGE, org.apache.axis.types.Language.class,
448                    new SimpleSerializerFactory(org.apache.axis.types.Language.class,
449                                              Constants.XSD_LANGUAGE),
450                    new SimpleDeserializerFactory(org.apache.axis.types.Language.class,
451                                              Constants.XSD_LANGUAGE)
452         );
453
454         // a xsd:NmToken
455
myRegister(Constants.XSD_NMTOKEN, org.apache.axis.types.NMToken.class,
456                    new SimpleSerializerFactory(org.apache.axis.types.NMToken.class,
457                                              Constants.XSD_NMTOKEN),
458                    new SimpleDeserializerFactory(org.apache.axis.types.NMToken.class,
459                                              Constants.XSD_NMTOKEN)
460         );
461
462         // a xsd:NmTokens
463
myRegister(Constants.XSD_NMTOKENS, org.apache.axis.types.NMTokens.class,
464                    new SimpleSerializerFactory(org.apache.axis.types.NMTokens.class,
465                                              Constants.XSD_NMTOKENS),
466                    new SimpleDeserializerFactory(org.apache.axis.types.NMTokens.class,
467                                              Constants.XSD_NMTOKENS)
468         );
469
470         // a xsd:NOTATION
471
myRegister(Constants.XSD_NOTATION, org.apache.axis.types.Notation.class,
472                    new BeanSerializerFactory(org.apache.axis.types.Notation.class,
473                                              Constants.XSD_NOTATION),
474                    new BeanDeserializerFactory(org.apache.axis.types.Notation.class,
475                                              Constants.XSD_NOTATION)
476         );
477
478         // a xsd:XSD_ENTITY
479
myRegister(Constants.XSD_ENTITY, org.apache.axis.types.Entity.class,
480                    new SimpleSerializerFactory(org.apache.axis.types.Entity.class,
481                                              Constants.XSD_ENTITY),
482                    new SimpleDeserializerFactory(org.apache.axis.types.Entity.class,
483                                              Constants.XSD_ENTITY)
484         );
485
486         // a xsd:XSD_ENTITIES
487
myRegister(Constants.XSD_ENTITIES, org.apache.axis.types.Entities.class,
488                    new SimpleSerializerFactory(org.apache.axis.types.Entities.class,
489                                              Constants.XSD_ENTITIES),
490                    new SimpleDeserializerFactory(org.apache.axis.types.Entities.class,
491                                              Constants.XSD_ENTITIES)
492         );
493
494         // a xsd:XSD_IDREF
495
myRegister(Constants.XSD_IDREF, org.apache.axis.types.IDRef.class,
496                    new SimpleSerializerFactory(org.apache.axis.types.IDRef.class,
497                                              Constants.XSD_IDREF),
498                    new SimpleDeserializerFactory(org.apache.axis.types.IDRef.class,
499                                              Constants.XSD_IDREF)
500         );
501
502         // a xsd:XSD_XSD_IDREFS
503
myRegister(Constants.XSD_IDREFS, org.apache.axis.types.IDRefs.class,
504                    new SimpleSerializerFactory(org.apache.axis.types.IDRefs.class,
505                                              Constants.XSD_IDREFS),
506                    new SimpleDeserializerFactory(org.apache.axis.types.IDRefs.class,
507                                              Constants.XSD_IDREFS)
508         );
509         
510         // a xsd:Duration
511
myRegister(Constants.XSD_DURATION, org.apache.axis.types.Duration.class,
512                    new SimpleSerializerFactory(org.apache.axis.types.Duration.class,
513                                              Constants.XSD_DURATION),
514                    new SimpleDeserializerFactory(org.apache.axis.types.Duration.class,
515                                              Constants.XSD_DURATION)
516         );
517         
518         // a xsd:anyURI
519
myRegister(Constants.XSD_ANYURI, org.apache.axis.types.URI.class,
520                    new SimpleSerializerFactory(org.apache.axis.types.URI.class,
521                                              Constants.XSD_ANYURI),
522                    new SimpleDeserializerFactory(org.apache.axis.types.URI.class,
523                                              Constants.XSD_ANYURI)
524         );
525
526         // a xsd:schema
527
myRegister(Constants.XSD_SCHEMA, org.apache.axis.types.Schema.class,
528                    new BeanSerializerFactory(org.apache.axis.types.Schema.class,
529                                              Constants.XSD_SCHEMA),
530                    new BeanDeserializerFactory(org.apache.axis.types.Schema.class,
531                                              Constants.XSD_SCHEMA)
532         );
533         
534         // Need this at the default TypeMapping level so that we can correctly
535
// obtain the ArraySerializer when in doc/lit mode and only have a
536
// Java class available (no XML type metadata) - see TypeMappingImpl
537
// (getSerializer())
538
myRegister(Constants.SOAP_ARRAY, java.util.ArrayList JavaDoc.class,
539                    new ArraySerializerFactory(),
540                    new ArrayDeserializerFactory()
541         );
542
543         //
544
// Now register the schema specific types
545
//
546
SchemaVersion.SCHEMA_1999.registerSchemaSpecificTypes(this);
547         SchemaVersion.SCHEMA_2000.registerSchemaSpecificTypes(this);
548         SchemaVersion.SCHEMA_2001.registerSchemaSpecificTypes(this);
549
550         inInitMappings = false;
551     }
552
553     /**
554      * Register a "simple" type mapping - in other words, a
555      * @param xmlType
556      * @param javaType
557      */

558     protected void myRegisterSimple(QName JavaDoc xmlType, Class JavaDoc javaType) {
559         SerializerFactory sf = new SimpleSerializerFactory(javaType, xmlType);
560         DeserializerFactory df = null;
561         if (javaType != java.lang.Object JavaDoc.class) {
562             df = new SimpleDeserializerFactory(javaType, xmlType);
563         }
564         
565         myRegister(xmlType, javaType, sf, df);
566     }
567
568     /**
569      * Construct TypeMapping for all the [xmlType, javaType] for all of the
570      * known xmlType namespaces. This is the shotgun approach, which works
571      * in 99% of the cases. The other cases that are Schema version specific
572      * (i.e. timeInstant vs. dateTime) are handled by the SchemaVersion
573      * Interface registerSchemaSpecificTypes().
574      *
575      * @param xmlType is the QName type
576      * @param javaType is the java type
577      * @param sf is the ser factory (if null, the simple factory is used)
578      * @param df is the deser factory (if null, the simple factory is used)
579      */

580     protected void myRegister(QName JavaDoc xmlType, Class JavaDoc javaType,
581                               SerializerFactory sf, DeserializerFactory df) {
582         // Register all known flavors of the namespace.
583
try {
584             if (xmlType.getNamespaceURI().equals(
585                     Constants.URI_DEFAULT_SCHEMA_XSD)) {
586                 for (int i=0; i < Constants.URIS_SCHEMA_XSD.length; i++) {
587                     QName JavaDoc qName = new QName JavaDoc(Constants.URIS_SCHEMA_XSD[i],
588                                             xmlType.getLocalPart());
589                     super.internalRegister(javaType, qName, sf, df);
590                 }
591             }
592             else if (xmlType.getNamespaceURI().equals(
593                     Constants.URI_DEFAULT_SOAP_ENC)) {
594                 for (int i=0; i < Constants.URIS_SOAP_ENC.length; i++) {
595                     QName JavaDoc qName = new QName JavaDoc(Constants.URIS_SOAP_ENC[i],
596                                             xmlType.getLocalPart());
597                     super.internalRegister(javaType, qName, sf, df);
598                 }
599             } else {
600                 // Register with the specified xmlType.
601
// This is the prefered mapping and the last registed one wins
602
super.internalRegister(javaType, xmlType, sf, df);
603             }
604         } catch (JAXRPCException JavaDoc e) { }
605     }
606
607     // Don't allow anyone to muck with the default type mapping because
608
// it is a singleton used for the whole system.
609
public void register(Class JavaDoc javaType, QName JavaDoc xmlType,
610                          javax.xml.rpc.encoding.SerializerFactory JavaDoc sf,
611                          javax.xml.rpc.encoding.DeserializerFactory JavaDoc dsf)
612         throws JAXRPCException JavaDoc {
613         super.register(javaType, xmlType, sf, dsf);
614     }
615     public void removeSerializer(Class JavaDoc javaType, QName JavaDoc xmlType)
616         throws JAXRPCException JavaDoc {
617         throw new JAXRPCException JavaDoc(Messages.getMessage("fixedTypeMapping"));
618     }
619     public void removeDeserializer(Class JavaDoc javaType, QName JavaDoc xmlType)
620         throws JAXRPCException JavaDoc {
621         throw new JAXRPCException JavaDoc(Messages.getMessage("fixedTypeMapping"));
622     }
623     public void setSupportedEncodings(String JavaDoc[] namespaceURIs) {
624     }
625 }
626
Popular Tags