KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > xb > binding > SimpleTypeBindings


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.xb.binding;
23
24 import org.jboss.logging.Logger;
25 import org.jboss.util.Base64;
26
27 import javax.xml.namespace.QName JavaDoc;
28 import javax.xml.namespace.NamespaceContext JavaDoc;
29 import java.io.ByteArrayOutputStream JavaDoc;
30 import java.io.Serializable JavaDoc;
31 import java.math.BigDecimal JavaDoc;
32 import java.math.BigInteger JavaDoc;
33 import java.net.URISyntaxException JavaDoc;
34 import java.text.DecimalFormat JavaDoc;
35 import java.text.ParseException JavaDoc;
36 import java.util.Calendar JavaDoc;
37 import java.util.StringTokenizer JavaDoc;
38 import java.util.TimeZone JavaDoc;
39 import java.util.List JavaDoc;
40 import java.util.ArrayList JavaDoc;
41
42
43 /**
44  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
45  * @author Thomas.Diesler@jboss.org
46  * @version <tt>$Revision: 1958 $</tt>
47  */

48 public final class SimpleTypeBindings
49    implements Serializable JavaDoc
50 {
51    static final long serialVersionUID = 4372272109355825813L;
52
53    public static final String JavaDoc XS_ANYSIMPLETYPE_NAME = "anySimpleType";
54
55    //
56
// primitive datatypes
57
//
58
public static final String JavaDoc XS_STRING_NAME = "string";
59    public static final String JavaDoc XS_BOOLEAN_NAME = "boolean";
60    public static final String JavaDoc XS_DECIMAL_NAME = "decimal";
61    public static final String JavaDoc XS_FLOAT_NAME = "float";
62    public static final String JavaDoc XS_DOUBLE_NAME = "double";
63    public static final String JavaDoc XS_DURATION_NAME = "duration";
64    public static final String JavaDoc XS_DATETIME_NAME = "dateTime";
65    public static final String JavaDoc XS_TIME_NAME = "time";
66    public static final String JavaDoc XS_DATE_NAME = "date";
67    public static final String JavaDoc XS_GYEARMONTH_NAME = "gYearMonth";
68    public static final String JavaDoc XS_GYEAR_NAME = "gYear";
69    public static final String JavaDoc XS_GMONTHDAY_NAME = "gMonthDay";
70    public static final String JavaDoc XS_GDAY_NAME = "gDay";
71    public static final String JavaDoc XS_GMONTH_NAME = "gMonth";
72    public static final String JavaDoc XS_HEXBINARY_NAME = "hexBinary";
73    public static final String JavaDoc XS_BASE64BINARY_NAME = "base64Binary";
74    public static final String JavaDoc XS_ANYURI_NAME = "anyURI";
75    public static final String JavaDoc XS_QNAME_NAME = "QName";
76    public static final String JavaDoc XS_NOTATION_NAME = "NOTATION";
77
78    //
79
// derived datatypes
80
//
81

82    public static final String JavaDoc XS_NORMALIZEDSTRING_NAME = "normalizedString";
83    public static final String JavaDoc XS_TOKEN_NAME = "token";
84    public static final String JavaDoc XS_LANGUAGE_NAME = "language";
85    public static final String JavaDoc XS_NMTOKEN_NAME = "NMTOKEN";
86    public static final String JavaDoc XS_NMTOKENS_NAME = "NMTOKENS";
87    public static final String JavaDoc XS_NAME_NAME = "Name";
88    public static final String JavaDoc XS_NCNAME_NAME = "NCName";
89    public static final String JavaDoc XS_ID_NAME = "ID";
90    public static final String JavaDoc XS_IDREF_NAME = "IDREF";
91    public static final String JavaDoc XS_IDREFS_NAME = "IDREFS";
92    public static final String JavaDoc XS_ENTITY_NAME = "ENTITY";
93    public static final String JavaDoc XS_ENTITIES_NAME = "ENTITIES";
94    public static final String JavaDoc XS_INTEGER_NAME = "integer";
95    public static final String JavaDoc XS_NONPOSITIVEINTEGER_NAME = "nonPositiveInteger";
96    public static final String JavaDoc XS_NEGATIVEINTEGER_NAME = "negativeInteger";
97    public static final String JavaDoc XS_LONG_NAME = "long";
98    public static final String JavaDoc XS_INT_NAME = "int";
99    public static final String JavaDoc XS_SHORT_NAME = "short";
100    public static final String JavaDoc XS_BYTE_NAME = "byte";
101    public static final String JavaDoc XS_NONNEGATIVEINTEGER_NAME = "nonNegativeInteger";
102    public static final String JavaDoc XS_UNSIGNEDLONG_NAME = "unsignedLong";
103    public static final String JavaDoc XS_UNSIGNEDINT_NAME = "unsignedInt";
104    public static final String JavaDoc XS_UNSIGNEDSHORT_NAME = "unsignedShort";
105    public static final String JavaDoc XS_UNSIGNEDBYTE_NAME = "unsignedByte";
106    public static final String JavaDoc XS_POSITIVEINTEGER_NAME = "positiveInteger";
107
108    public static final int XS_INT = XS_INT_NAME.hashCode();
109    public static final int XS_LONG = XS_LONG_NAME.hashCode();
110    public static final int XS_SHORT = XS_SHORT_NAME.hashCode();
111    public static final int XS_FLOAT = XS_FLOAT_NAME.hashCode();
112    public static final int XS_DOUBLE = XS_DOUBLE_NAME.hashCode();
113    public static final int XS_BOOLEAN = XS_BOOLEAN_NAME.hashCode();
114    public static final int XS_BYTE = XS_BYTE_NAME.hashCode();
115    public static final int XS_STRING = XS_STRING_NAME.hashCode();
116    public static final int XS_INTEGER = XS_INTEGER_NAME.hashCode();
117    public static final int XS_DECIMAL = XS_DECIMAL_NAME.hashCode();
118    public static final int XS_DATETIME = XS_DATETIME_NAME.hashCode();
119    public static final int XS_QNAME = XS_QNAME_NAME.hashCode();
120    public static final int XS_ANYURI = XS_ANYURI_NAME.hashCode();
121    public static final int XS_UNSIGNEDLONG = XS_UNSIGNEDLONG_NAME.hashCode();
122    public static final int XS_UNSIGNEDINT = XS_UNSIGNEDINT_NAME.hashCode();
123    public static final int XS_UNSIGNEDSHORT = XS_UNSIGNEDSHORT_NAME.hashCode();
124    public static final int XS_UNSIGNEDBYTE = XS_UNSIGNEDBYTE_NAME.hashCode();
125    public static final int XS_DATE = XS_DATE_NAME.hashCode();
126    public static final int XS_TIME = XS_TIME_NAME.hashCode();
127    public static final int XS_BASE64BINARY = XS_BASE64BINARY_NAME.hashCode();
128    public static final int XS_HEXBINARY = XS_HEXBINARY_NAME.hashCode();
129    public static final int XS_ANYSIMPLETYPE = XS_ANYSIMPLETYPE_NAME.hashCode();
130    public static final int XS_DURATION = XS_DURATION_NAME.hashCode();
131    public static final int XS_GYEARMONTH = XS_GYEARMONTH_NAME.hashCode();
132    public static final int XS_GYEAR = XS_GYEAR_NAME.hashCode();
133    public static final int XS_GMONTHDAY = XS_GMONTHDAY_NAME.hashCode();
134    public static final int XS_GMONTH = XS_GMONTH_NAME.hashCode();
135    public static final int XS_GDAY = XS_GDAY_NAME.hashCode();
136    public static final int XS_NORMALIZEDSTRING = XS_NORMALIZEDSTRING_NAME.hashCode();
137    public static final int XS_TOKEN = XS_TOKEN_NAME.hashCode();
138    public static final int XS_LANGUAGE = XS_LANGUAGE_NAME.hashCode();
139    public static final int XS_NAME = XS_NAME_NAME.hashCode();
140    public static final int XS_NCNAME = XS_NCNAME_NAME.hashCode();
141    public static final int XS_ID = XS_ID_NAME.hashCode();
142    public static final int XS_NMTOKEN = XS_NMTOKEN_NAME.hashCode();
143    public static final int XS_NMTOKENS = XS_NMTOKENS_NAME.hashCode();
144    public static final int XS_NONPOSITIVEINTEGER = XS_NONPOSITIVEINTEGER_NAME.hashCode();
145    public static final int XS_NEGATIVEINTEGER = XS_NEGATIVEINTEGER_NAME.hashCode();
146    public static final int XS_NONNEGATIVEINTEGER = XS_NONNEGATIVEINTEGER_NAME.hashCode();
147    public static final int XS_POSITIVEINTEGER = XS_POSITIVEINTEGER_NAME.hashCode();
148    public static final int XS_NOTATION = XS_NOTATION_NAME.hashCode();
149    public static final int XS_IDREF = XS_IDREF_NAME.hashCode();
150    public static final int XS_IDREFS = XS_IDREFS_NAME.hashCode();
151    public static final int XS_ENTITY = XS_ENTITY_NAME.hashCode();
152    public static final int XS_ENTITIES = XS_ENTITIES_NAME.hashCode();
153
154    public static final TypeBinding STRING = new TypeBinding()
155    {
156       public Object JavaDoc unmarshal(String JavaDoc value)
157       {
158          return value;
159       }
160
161       public String JavaDoc marshal(Object JavaDoc value)
162       {
163          return (String JavaDoc)value;
164       }
165    };
166
167    public static final TypeBinding INT = new TypeBinding()
168    {
169       public Object JavaDoc unmarshal(String JavaDoc value)
170       {
171          return Integer.valueOf(value);
172       }
173
174       public String JavaDoc marshal(Object JavaDoc value)
175       {
176          return String.valueOf(value);
177       }
178    };
179
180    public static final TypeBinding LONG = new TypeBinding()
181    {
182       public Object JavaDoc unmarshal(String JavaDoc value)
183       {
184          return Long.valueOf(value);
185       }
186
187       public String JavaDoc marshal(Object JavaDoc value)
188       {
189          return String.valueOf(value);
190       }
191    };
192
193    public static final TypeBinding DOUBLE = new TypeBinding()
194    {
195       public Object JavaDoc unmarshal(String JavaDoc value)
196       {
197          return Double.valueOf(value);
198       }
199
200       public String JavaDoc marshal(Object JavaDoc value)
201       {
202          return String.valueOf(value);
203       }
204    };
205
206    public static final TypeBinding FLOAT = new TypeBinding()
207    {
208       public Object JavaDoc unmarshal(String JavaDoc value)
209       {
210          return Float.valueOf(value);
211       }
212
213       public String JavaDoc marshal(Object JavaDoc value)
214       {
215          return String.valueOf(value);
216       }
217    };
218
219    public static final TypeBinding SHORT = new TypeBinding()
220    {
221       public Object JavaDoc unmarshal(String JavaDoc value)
222       {
223          return Short.valueOf(value);
224       }
225
226       public String JavaDoc marshal(Object JavaDoc value)
227       {
228          return String.valueOf(value);
229       }
230    };
231
232    public static final TypeBinding BYTE = new TypeBinding()
233    {
234       public Object JavaDoc unmarshal(String JavaDoc value)
235       {
236          return Byte.valueOf(value);
237       }
238
239       public String JavaDoc marshal(Object JavaDoc value)
240       {
241          return String.valueOf(value);
242       }
243    };
244
245    public static final TypeBinding CHAR = new TypeBinding()
246    {
247       public Object JavaDoc unmarshal(String JavaDoc value)
248       {
249          return value == null ? null : new Character JavaDoc(value.charAt(0));
250       }
251
252       public String JavaDoc marshal(Object JavaDoc value)
253       {
254          return String.valueOf(value);
255       }
256    };
257
258    public static final TypeBinding JAVA_UTIL_DATE = new TypeBinding()
259    {
260       public Object JavaDoc unmarshal(String JavaDoc value)
261       {
262          return unmarshalDate(value).getTime();
263       }
264
265       public String JavaDoc marshal(Object JavaDoc value)
266       {
267          Calendar JavaDoc c = Calendar.getInstance();
268          c.setTime((java.util.Date JavaDoc)value);
269          return marshalDate(c);
270       }
271    };
272
273    // check for uniqueness of hashCode's
274
static
275    {
276       int[] codes = new int[45];
277       String JavaDoc[] names = new String JavaDoc[codes.length];
278       int i = 0;
279
280       names[i] = XS_INT_NAME;
281       codes[i++] = XS_INT;
282
283       names[i] = XS_LONG_NAME;
284       codes[i++] = XS_LONG;
285
286       names[i] = XS_SHORT_NAME;
287       codes[i++] = XS_SHORT;
288
289       names[i] = XS_FLOAT_NAME;
290       codes[i++] = XS_FLOAT;
291
292       names[i] = XS_DOUBLE_NAME;
293       codes[i++] = XS_DOUBLE;
294
295       names[i] = XS_BOOLEAN_NAME;
296       codes[i++] = XS_BOOLEAN;
297
298       names[i] = XS_BYTE_NAME;
299       codes[i++] = XS_BYTE;
300
301       names[i] = XS_STRING_NAME;
302       codes[i++] = XS_STRING;
303
304       names[i] = XS_INTEGER_NAME;
305       codes[i++] = XS_INTEGER;
306
307       names[i] = XS_DECIMAL_NAME;
308       codes[i++] = XS_DECIMAL;
309
310       names[i] = XS_DATETIME_NAME;
311       codes[i++] = XS_DATETIME;
312
313       names[i] = XS_QNAME_NAME;
314       codes[i++] = XS_QNAME;
315
316       names[i] = XS_ANYURI_NAME;
317       codes[i++] = XS_ANYURI;
318
319       names[i] = XS_UNSIGNEDINT_NAME;
320       codes[i++] = XS_UNSIGNEDINT;
321
322       names[i] = XS_UNSIGNEDSHORT_NAME;
323       codes[i++] = XS_UNSIGNEDSHORT;
324
325       names[i] = XS_UNSIGNEDBYTE_NAME;
326       codes[i++] = XS_UNSIGNEDBYTE;
327
328       names[i] = XS_DATE_NAME;
329       codes[i++] = XS_DATE;
330
331       names[i] = XS_TIME_NAME;
332       codes[i++] = XS_TIME;
333
334       names[i] = XS_BASE64BINARY_NAME;
335       codes[i++] = XS_BASE64BINARY;
336
337       names[i] = XS_HEXBINARY_NAME;
338       codes[i++] = XS_HEXBINARY;
339
340       names[i] = XS_ANYSIMPLETYPE_NAME;
341       codes[i++] = XS_ANYSIMPLETYPE;
342
343       names[i] = XS_DURATION_NAME;
344       codes[i++] = XS_DURATION;
345
346       names[i] = XS_GYEARMONTH_NAME;
347       codes[i++] = XS_GYEARMONTH;
348
349       names[i] = XS_GYEAR_NAME;
350       codes[i++] = XS_GYEAR;
351
352       names[i] = XS_GMONTHDAY_NAME;
353       codes[i++] = XS_GMONTHDAY;
354
355       names[i] = XS_GMONTH_NAME;
356       codes[i++] = XS_GMONTH;
357
358       names[i] = XS_GDAY_NAME;
359       codes[i++] = XS_GDAY;
360
361       names[i] = XS_NORMALIZEDSTRING_NAME;
362       codes[i++] = XS_NORMALIZEDSTRING;
363
364       names[i] = XS_TOKEN_NAME;
365       codes[i++] = XS_TOKEN;
366
367       names[i] = XS_LANGUAGE_NAME;
368       codes[i++] = XS_LANGUAGE;
369
370       names[i] = XS_NAME_NAME;
371       codes[i++] = XS_NAME;
372
373       names[i] = XS_NCNAME_NAME;
374       codes[i++] = XS_NCNAME;
375
376       names[i] = XS_ID_NAME;
377       codes[i++] = XS_ID;
378
379       names[i] = XS_NMTOKEN_NAME;
380       codes[i++] = XS_NMTOKEN;
381
382       names[i] = XS_NMTOKENS_NAME;
383       codes[i++] = XS_NMTOKENS;
384
385       names[i] = XS_NONPOSITIVEINTEGER_NAME;
386       codes[i++] = XS_NONPOSITIVEINTEGER;
387
388       names[i] = XS_NONNEGATIVEINTEGER_NAME;
389       codes[i++] = XS_NONNEGATIVEINTEGER;
390
391       names[i] = XS_POSITIVEINTEGER_NAME;
392       codes[i++] = XS_POSITIVEINTEGER;
393
394       names[i] = XS_NEGATIVEINTEGER_NAME;
395       codes[i++] = XS_NEGATIVEINTEGER;
396
397       names[i] = XS_UNSIGNEDLONG_NAME;
398       codes[i++] = XS_UNSIGNEDLONG;
399
400       names[i] = XS_NOTATION_NAME;
401       codes[i++] = XS_NOTATION;
402
403       names[i] = XS_IDREF_NAME;
404       codes[i++] = XS_IDREF;
405
406       names[i] = XS_IDREFS_NAME;
407       codes[i++] = XS_IDREFS;
408
409       names[i] = XS_ENTITY_NAME;
410       codes[i++] = XS_ENTITY;
411
412       names[i] = XS_ENTITIES_NAME;
413       codes[i++] = XS_ENTITIES;
414
415       Logger log = Logger.getLogger(SimpleTypeBindings.class);
416       boolean allAreUnique = true;
417       for(int outer = 0; outer < names.length; ++outer)
418       {
419          int outerCode = codes[outer];
420          String JavaDoc outerName = names[outer];
421
422          for(int inner = outer + 1; inner < names.length; ++inner)
423          {
424             int innerCode = codes[inner];
425             String JavaDoc innerName = names[inner];
426
427             if(outerCode == innerCode)
428             {
429                log.error("Types have the same hash code " + outerCode + ": " + outerName + " and " + innerName);
430                allAreUnique = false;
431             }
432          }
433       }
434
435       if(!allAreUnique)
436       {
437          throw new IllegalStateException JavaDoc("Not all the schema types have unique hash codes! See log for more details.");
438       }
439    }
440
441    public static Class JavaDoc classForType(String JavaDoc xsdType, boolean nillable)
442    {
443       Class JavaDoc result;
444       int typeCode = xsdType.hashCode();
445       if(typeCode == XS_INT)
446       {
447          result = nillable ? Integer JavaDoc.class : int.class;
448       }
449       else if(typeCode == XS_LONG)
450       {
451          result = nillable ? Long JavaDoc.class : long.class;
452       }
453       else if(typeCode == XS_SHORT)
454       {
455          result = nillable ? Short JavaDoc.class : short.class;
456       }
457       else if(typeCode == XS_BYTE)
458       {
459          result = nillable ? Byte JavaDoc.class : byte.class;
460       }
461       else if(typeCode == XS_FLOAT)
462       {
463          result = nillable ? Float JavaDoc.class : float.class;
464       }
465       else if(typeCode == XS_DOUBLE)
466       {
467          result = nillable ? Double JavaDoc.class : double.class;
468       }
469       else if(typeCode == XS_BOOLEAN)
470       {
471          result = nillable ? Boolean JavaDoc.class : boolean.class;
472       }
473       else if(typeCode == XS_STRING)
474       {
475          result = String JavaDoc.class;
476       }
477       else if(typeCode == XS_INTEGER)
478       {
479          result = BigInteger JavaDoc.class;
480       }
481       else if(typeCode == XS_DECIMAL)
482       {
483          result = BigDecimal JavaDoc.class;
484       }
485       else if(typeCode == XS_DATETIME)
486       {
487          result = java.util.Calendar JavaDoc.class;
488       }
489       else if(typeCode == XS_QNAME)
490       {
491          result = QName JavaDoc.class;
492       }
493       else if(typeCode == XS_ANYURI)
494       {
495          // anyUri is by default bound to java.net.URI for now. The following is the warning from JAXB2.0:
496
//
497
// Design Note � xs:anyURI is not bound to java.net.URI by default since not all
498
// possible values of xs:anyURI can be passed to the java.net.URI constructor. Using
499
// a global JAXB customization described in Section 7.9, �<javaType>
500
// Declaration", a JAXB user can override the default mapping to map xs:anyURI to
501
// java.net.URI.
502
//
503
result = java.net.URI JavaDoc.class;
504       }
505       else if(typeCode == XS_UNSIGNEDLONG)
506       {
507          result = BigInteger JavaDoc.class;
508       }
509       else if(typeCode == XS_UNSIGNEDINT)
510       {
511          result = nillable ? Long JavaDoc.class : long.class;
512       }
513       else if(typeCode == XS_UNSIGNEDSHORT)
514       {
515          result = nillable ? Integer JavaDoc.class : int.class;
516       }
517       else if(typeCode == XS_UNSIGNEDBYTE)
518       {
519          result = nillable ? Short JavaDoc.class : short.class;
520       }
521       else if(typeCode == XS_DATE)
522       {
523          result = Calendar JavaDoc.class;
524       }
525       else if(typeCode == XS_TIME)
526       {
527          result = Calendar JavaDoc.class;
528       }
529       else if(typeCode == XS_BASE64BINARY)
530       {
531          result = byte[].class;
532       }
533       else if(typeCode == XS_HEXBINARY)
534       {
535          result = byte[].class;
536       }
537       else if(typeCode == XS_ANYSIMPLETYPE)
538       {
539          result = String JavaDoc.class;
540       }
541       else if(typeCode == XS_DURATION)
542       {
543          // todo XS_DURATION
544
throw new IllegalStateException JavaDoc("Recognized but not supported xsdType: " + XS_DURATION_NAME);
545       }
546       else if(typeCode == XS_GYEARMONTH)
547       {
548          result = Calendar JavaDoc.class;
549       }
550       else if(typeCode == XS_GYEAR)
551       {
552          result = Calendar JavaDoc.class;
553       }
554       else if(typeCode == XS_GMONTHDAY)
555       {
556          result = Calendar JavaDoc.class;
557       }
558       else if(typeCode == XS_GMONTH)
559       {
560          result = Calendar JavaDoc.class;
561       }
562       else if(typeCode == XS_GDAY)
563       {
564          result = Calendar JavaDoc.class;
565       }
566       else if(typeCode == XS_NORMALIZEDSTRING)
567       {
568          result = String JavaDoc.class;
569       }
570       else if(typeCode == XS_TOKEN)
571       {
572          result = String JavaDoc.class;
573       }
574       else if(typeCode == XS_LANGUAGE)
575       {
576          result = String JavaDoc.class;
577       }
578       else if(typeCode == XS_NAME)
579       {
580          result = String JavaDoc.class;
581       }
582       else if(typeCode == XS_NCNAME)
583       {
584          result = String JavaDoc.class;
585       }
586       else if(typeCode == XS_ID)
587       {
588          result = String JavaDoc.class;
589       }
590       else if(typeCode == XS_NMTOKEN)
591       {
592          result = String JavaDoc.class;
593       }
594       else if(typeCode == XS_NMTOKENS)
595       {
596          result = String JavaDoc[].class;
597       }
598       else if(typeCode == XS_NONPOSITIVEINTEGER)
599       {
600          result = BigInteger JavaDoc.class;
601       }
602       else if(typeCode == XS_NEGATIVEINTEGER)
603       {
604          result = BigInteger JavaDoc.class;
605       }
606       else if(typeCode == XS_NONNEGATIVEINTEGER)
607       {
608          result = BigInteger JavaDoc.class;
609       }
610       else if(typeCode == XS_POSITIVEINTEGER)
611       {
612          result = BigInteger JavaDoc.class;
613       }
614       else if(typeCode == XS_NOTATION)
615       {
616          result = String JavaDoc.class;
617       }
618       else if(typeCode == XS_IDREF)
619       {
620          result = String JavaDoc.class;
621       }
622       else if(typeCode == XS_IDREFS)
623       {
624          result = String JavaDoc[].class;
625       }
626       else if(typeCode == XS_ENTITY)
627       {
628          result = String JavaDoc.class;
629       }
630       else if(typeCode == XS_ENTITIES)
631       {
632          result = String JavaDoc[].class;
633       }
634       else
635       {
636          throw new IllegalStateException JavaDoc("Not supported xsdType: " + xsdType + ", hashCode=" + xsdType.hashCode());
637       }
638       return result;
639    }
640
641    public static Object JavaDoc unmarshal(String JavaDoc xsdType, String JavaDoc value, NamespaceContext JavaDoc nsCtx)
642    {
643       if (xsdType == null)
644          throw new IllegalArgumentException JavaDoc("Schema type cannot be null");
645       if (value == null)
646          throw new IllegalArgumentException JavaDoc("Value string cannot be null");
647
648       int typeCode = xsdType.hashCode();
649       Object JavaDoc result;
650       if(typeCode == XS_INT)
651       {
652          result = Integer.valueOf(value);
653       }
654       else if(typeCode == XS_LONG)
655       {
656          result = Long.valueOf(value);
657       }
658       else if(typeCode == XS_SHORT)
659       {
660          result = Short.valueOf(value);
661       }
662       else if(typeCode == XS_BYTE)
663       {
664          result = Byte.valueOf(value);
665       }
666       else if(typeCode == XS_FLOAT)
667       {
668          if("INF".equals(value))
669          {
670             result = new Float JavaDoc(Float.POSITIVE_INFINITY);
671          }
672          else if("-INF".equals(value))
673          {
674             result = new Float JavaDoc(Float.NEGATIVE_INFINITY);
675          }
676          else
677          {
678             result = Float.valueOf(value);
679          }
680       }
681       else if(typeCode == XS_DOUBLE)
682       {
683          if("INF".equals(value))
684          {
685             result = new Double JavaDoc(Double.POSITIVE_INFINITY);
686          }
687          else if("-INF".equals(value))
688          {
689             result = new Double JavaDoc(Double.NEGATIVE_INFINITY);
690          }
691          else
692          {
693             result = Double.valueOf(value);
694          }
695       }
696       else if(typeCode == XS_BOOLEAN)
697       {
698          if(value.length() == 1)
699          {
700             switch(value.charAt(0))
701             {
702                case '1':
703                   result = Boolean.TRUE;
704                   break;
705                case '0':
706                   result = Boolean.FALSE;
707                   break;
708                default:
709                   throw new JBossXBValueFormatException("An instance of a datatype that is defined as ?boolean? can have the following legal literals" +
710                      " {true, false, 1, 0}. But got: " + value
711                   );
712             }
713          }
714          else
715          {
716             result = Boolean.valueOf(value);
717          }
718       }
719       else if(typeCode == XS_STRING)
720       {
721          result = value;
722       }
723       else if(typeCode == XS_INTEGER)
724       {
725          result = new BigInteger JavaDoc(value);
726       }
727       else if(typeCode == XS_DECIMAL)
728       {
729          result = new BigDecimal JavaDoc(value);
730       }
731       else if(typeCode == XS_DATETIME)
732       {
733          result = unmarshalDateTime(value);
734       }
735       else if(typeCode == XS_QNAME)
736       {
737          result = unmarshalQName(value, nsCtx);
738       }
739       else if(typeCode == XS_ANYURI)
740       {
741          // anyUri is by default bound to java.net.URI for now. The following is the warning from JAXB2.0:
742
//
743
// Design Note � xs:anyURI is not bound to java.net.URI by default since not all
744
// possible values of xs:anyURI can be passed to the java.net.URI constructor. Using
745
// a global JAXB customization described in Section 7.9, �<javaType>
746
// Declaration", a JAXB user can override the default mapping to map xs:anyURI to
747
// java.net.URI.
748
//
749
try
750          {
751             result = new java.net.URI JavaDoc(value);
752          }
753          catch(URISyntaxException JavaDoc e)
754          {
755             throw new JBossXBValueFormatException("Failed to unmarshal anyURI value " + value, e);
756          }
757       }
758       else if(typeCode == XS_UNSIGNEDLONG)
759       {
760          BigInteger JavaDoc d = new BigInteger JavaDoc(value);
761          if(d.doubleValue() < 0 || d.doubleValue() > 18446744073709551615D)
762          {
763             throw new JBossXBValueFormatException("Invalid unsignedLong value: " + value);
764          }
765          result = d;
766       }
767       else if(typeCode == XS_UNSIGNEDINT)
768       {
769          long l = Long.parseLong(value);
770          if(l < 0 || l > 4294967295L)
771          {
772             throw new JBossXBValueFormatException("Invalid unsignedInt value: " + value);
773          }
774          result = new Long JavaDoc(l);
775       }
776       else if(typeCode == XS_UNSIGNEDSHORT)
777       {
778          int i = Integer.parseInt(value);
779          if(i < 0 || i > 65535)
780          {
781