KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > xquery > typing > QType


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  * Copyright (C) 2003 XQuark Group.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
19  * You can also get it at http://www.gnu.org/licenses/lgpl.html
20  *
21  * For more information on this software, see http://www.xquark.org.
22  */

23
24 package org.xquark.xquery.typing;
25
26 import java.util.List JavaDoc;
27
28 import org.xquark.schema.SimpleType;
29 import org.xquark.schema.Type;
30 import org.xquark.schema.datatypes.PrimitiveType;
31 import org.xquark.xquery.parser.XQueryExpression;
32
33 public abstract class QType implements QTypeVisitable, Cloneable JavaDoc {
34     private static final String JavaDoc RCSRevision = "$Revision: 1.10 $";
35     private static final String JavaDoc RCSName = "$Name: $";
36
37     // occurence types
38
public static final byte OCC_0_0 = 0;
39     public static final byte OCC_0_1 = 1;
40     public static final byte OCC_1_1 = 2;
41     public static final byte OCC_0_N = 3;
42     public static final byte OCC_1_N = 4;
43
44     // Qtype types
45
public static final byte ELEMENT = 1;
46     public static final byte ATOM = 2;
47     public static final byte ATTRIBUTE = 3;
48     public static final byte UNION = 4;
49     public static final byte SEQUENCE = 5;
50     public static final byte COMMENT = 6;
51     public static final byte PROCESSING = 7;
52     public static final byte CDATA = 8;
53     public static final byte DOCUMENT = 9;
54     public static final byte TEXT = 10;
55
56     // primitive XQuery Types
57

58     public static final byte PRIMITIVE_anySimpleType = 0;
59     public static final byte PRIMITIVE_string = 1;
60     public static final byte PRIMITIVE_float = 2;
61     public static final byte PRIMITIVE_double = 3;
62     public static final byte PRIMITIVE_decimal = 4;
63     public static final byte PRIMITIVE_duration = 5;
64     public static final byte PRIMITIVE_yearMonthDuration = 6;
65     public static final byte PRIMITIVE_dayTimeDuration = 7;
66     public static final byte PRIMITIVE_dateTime = 8;
67     public static final byte PRIMITIVE_time = 9;
68     public static final byte PRIMITIVE_date = 10;
69     public static final byte PRIMITIVE_gYearMonth = 11;
70     public static final byte PRIMITIVE_gYear = 12;
71     public static final byte PRIMITIVE_gMonthDay = 13;
72     public static final byte PRIMITIVE_gDay = 14;
73     public static final byte PRIMITIVE_gMonth = 15;
74     public static final byte PRIMITIVE_boolean = 16;
75     public static final byte PRIMITIVE_base64Binary = 17;
76     public static final byte PRIMITIVE_hexBinary = 18;
77     public static final byte PRIMITIVE_anyURI = 19;
78     public static final byte PRIMITIVE_Qname = 20;
79     public static final byte PRIMITIVE_NOTATION = 21;
80
81     /*
82     
83     aST = anySimpleType
84     aURI = anyURI
85     b64 = base64Binary
86     bool = boolean
87     dat = date
88     Day = gDay
89     dbl = double
90     dec = decimal
91     dT = dateTime
92     dTD = dayTimeDuration
93     dur = duration
94     flt = float
95     hxB = hexBinary
96     MD = gMonthDay
97     Mon = gMonth
98     NOT = NOTATION
99     QN = Qname
100     str = string
101     tim = time
102     YM = gYearMonth
103     yMD = yearMonthDuration
104     Yr = gYear
105     
106     S\T aST str flt dbl dec dur yMD dTD dT tim dat YM Yr MD Day Mon bool b64 hxB aURI QN NOT
107     aST Y Y M M M M M M M M M M M M M M M M M M N N
108     str Y Y M M M M M M M M M M M M M M M M M M N N
109     flt Y Y Y Y M N N N N N N N N N N N Y N N N N N
110     dbl Y Y Y Y M N N N N N N N N N N N Y N N N N N
111     dec Y Y Y Y Y N N N N N N N N N N N Y N N N N N
112     dur Y Y N N N Y Y Y N N N N N N N N N N N N N N
113     yMD Y Y N N N Y Y N N N N N N N N N N N N N N N
114     dTD Y Y N N N Y N Y N N N N N N N N N N N N N N
115     dT Y Y N N N N N N Y Y Y Y Y Y Y Y N N N N N N
116     tim Y Y N N N N N N Y Y N N N N N N N N N N N N
117     dat Y Y N N N N N N Y N Y Y Y Y Y Y N N N N N N
118     YM Y Y N N N N N N N N N Y N N N N N N N N N N
119     Yr Y Y N N N N N N N N N N Y N N N N N N N N N
120     MD Y Y N N N N N N N N N N N Y N N N N N N N N
121     Day Y Y N N N N N N N N N N N N Y N N N N N N N
122     Mon Y Y N N N N N N N N N N N N N Y N N N N N N
123     bool Y Y Y Y Y N N N N N N N N N N N Y N N N N N
124     b64 Y Y N N N N N N N N N N N N N N M Y N N N N
125     hxB Y Y M M M N N N N N N N N N N N M N Y N N N
126     aURI Y Y N N N N N N N N N N N N N N N N N Y N N
127     QN N N N N N N N N N N N N N N N N N N N N Y N
128     NOT N N N N N N N N N N N N N N N N N N N N N Y
129     */

130     // NOTE : Maybe is Yes with restrictions!
131
public static final boolean castTab[][] = { {
132             //aST str flt dbl dec dur yMD dTD dT tim dat YM Yr MD Day Mon bool b64 hxB aURI QN NOT
133
/*aST*/
134             true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, false }, {
135             /*str*/
136             true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, false }, {
137             /*flt*/
138             true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false }, {
139             /*dbl*/
140             true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false }, {
141             /*dec*/
142             true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false }, {
143             /*dur*/
144             true, true, false, false, false, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false }, {
145             /*yMD*/
146             true, true, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false }, {
147             /*dTD*/
148             true, true, false, false, false, true, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false }, {
149             /*dT*/
150             true, true, false, false, false, false, false, false, true, true, true, true, true, true, true, true, false, false, false, false, false, false }, {
151             /*tim*/
152             true, true, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false }, {
153             /*dat*/
154             true, true, false, false, false, false, false, false, true, false, true, true, true, true, true, true, false, false, false, false, false, false }, {
155             /*YM*/
156             true, true, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false }, {
157             /*Yr*/
158             true, true, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false }, {
159             /*MD*/
160             true, true, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false }, {
161             /*Day*/
162             true, true, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false }, {
163             /*Mon*/
164             true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false }, {
165             /*bool*/
166             true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false }, {
167             /*b64*/
168             true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false }, {
169             /*hxB*/
170             true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, true, false, true, false, false, false }, {
171             /*aURI*/
172             true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false }, {
173             /*QN*/
174             false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false }, {
175             /*NOT*/
176             false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true }
177     };
178
179     protected byte subclass = 0;
180     protected byte occurence = OCC_1_1;
181     // protected int min = 1;
182
// protected int max = 1;
183

184     public static byte computeOccurence(byte occ1, byte occ2) {
185         switch (occ1) {
186             case OCC_1_1 :
187                 return occ2;
188             case OCC_0_1 :
189                 switch (occ2) {
190                     case OCC_1_1 :
191                     case OCC_0_1 :
192                         return OCC_0_1;
193                     case OCC_1_N :
194                     case OCC_0_N :
195                         return OCC_0_N;
196                 }
197             case OCC_1_N :
198                 switch (occ2) {
199                     case OCC_1_1 :
200                     case OCC_1_N :
201                         return OCC_1_N;
202                     case OCC_0_1 :
203                     case OCC_0_N :
204                         return OCC_0_N;
205                 }
206             default:
207                 return occ1;
208         }
209     }
210     
211     public static byte getOccurence(int min, int max) {
212         if (min > 0) {
213             if (max > 1)
214                 return QType.OCC_1_N;
215             else
216                 return QType.OCC_1_1;
217         } else {
218             if (max > 1)
219                 return QType.OCC_0_N;
220             else
221                 return QType.OCC_0_1;
222         }
223     }
224
225     // methods on occurence
226
public byte getOccurence() {
227         return occurence;
228     }
229     public QType changeOccurence(byte occurence) {
230         QType qtype = null;
231         try {
232             qtype = (QType) clone();
233         } catch (CloneNotSupportedException JavaDoc cnse) {}
234         qtype.occurence = occurence;
235         return qtype;
236     }
237     public int getMaxOccurence() {
238         switch (occurence) {
239             case OCC_0_0 :
240                 return 0;
241             case OCC_1_1 :
242             case OCC_0_1 :
243                 return 1;
244             case OCC_0_N :
245             case OCC_1_N :
246                 return Integer.MAX_VALUE;
247         }
248         return -1;
249     }
250     public int getMinOccurence() {
251         switch (occurence) {
252             case OCC_0_N :
253             case OCC_0_1 :
254             case OCC_0_0 :
255                 return 0;
256             case OCC_1_1 :
257             case OCC_1_N :
258                 return 1;
259         }
260         return -1;
261     }
262
263     public byte getSubClass() {
264         return subclass;
265     }
266
267     // abstract public String toSimpleString();
268
// abstract public String toString();
269
// abstract public boolean equals(QType qtype);
270
//
271
public SimpleType getSimpleType() {
272         return null;
273     }
274     public Type getType() {
275         return null;
276     }
277     // public QType getQType() {
278
// return null;
279
// }
280
public List JavaDoc getList() {
281         return null;
282     }
283     public XQueryExpression getName() {
284         return null;
285     }
286     // public QType getCollectionType() {
287
// return null;
288
// }
289

290     abstract public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc;
291
292     // tells whether qtype is numeric ( DECIMAL, DOUBLE, FLOAT )
293
// QTypeAtom with type numeric
294
// QTypeAttribute with type numeric
295
// QTypeElement with type numeric
296
// QTypeCollection with type verifying isNumeric
297
// QTypeSequence with all types verifying isNumeric
298
// QTypeUnion with at leat one type verifying isNumeric
299
public boolean isNumeric() {
300         return false;
301     }
302
303     // tells whether qtype is boolean
304
// QTypeAtom with type boolean
305
// QTypeAttribute with type boolean
306
// QTypeElement with type boolean
307
// QTypeCollection with type verifying isBoolean
308
// QTypeSequence with all types verifying isBoolean
309
// QTypeUnion with at leat one type verifying isBoolean
310
public boolean isBoolean() {
311         return false;
312     }
313
314     // tells whether qtype is integer
315
// QTypeAtom with type integer
316
// QTypeAttribute with type integer
317
// QTypeElement with type integer
318
// QTypeCollection with type verifying isInteger
319
// QTypeSequence with all types verifying isInteger
320
// QTypeUnion with at leat one type verifying isInteger
321
public boolean isInteger() {
322         return false;
323     }
324
325     // tells whether qtype is string
326
// QTypeAtom with type string
327
// QTypeAttribute with type string
328
// QTypeElement with type string
329
// QTypeCollection with type verifying isString
330
// QTypeSequence with all types verifying isString
331
// QTypeUnion with at leat one type verifying isString
332
public boolean isString() {
333         return false;
334     }
335
336     // tells whether qtype is an atom
337
// QTypeAtom
338
// QTypeCollection with type verifying isAtom
339
// QTypeSequence with all types verifying isAtom
340
// QTypeUnion with at leat one type verifying isAtom
341
public boolean isAtom() {
342         return false;
343     }
344
345     // tells whether qtype can react to text()
346
// QTypeAttribute
347
// QTypeElement
348
// QTypeCollection with type verifying isText
349
// QTypeSequence with all types verifying isText
350
// QTypeUnion with at leat one type verifying isText
351
public boolean isText() {
352         return false;
353     }
354
355     // tells whether qtype is a date
356
// QTypeAtom with type date
357
// QTypeAttribute with type date
358
// QTypeElement with type date
359
// QTypeCollection with type verifying isDate
360
// QTypeSequence with all types verifying isDate
361
// QTypeUnion with at leat one type verifying isDate
362
public boolean isDate() {
363         return false;
364     }
365
366     // not implemented yet
367
public boolean isDuration() {
368         return false;
369     }
370
371     // tells whether qtype is an attribte
372
// QTypeAttribute
373
// QTypeCollection with type verifying isAttribute
374
// QTypeSequence with all types verifying isAttribute
375
// QTypeUnion with at leat one type verifying isAttribute
376
public boolean isAttribute() {
377         return false;
378     }
379     // tells whether qtype is only an attribte
380
// QTypeAttribute
381
// QTypeCollection with type verifying isAttribute
382
// QTypeSequence with all types verifying isAttribute
383
// QTypeUnion with all type verifying isAttribute
384
public boolean isOnlyAttribute() {
385         return isAttribute();
386     }
387
388     // tells whether qtype is a ID, IDREF or IDREFS type
389
// QTypeAttribute with special case
390
// QTypeCollection with type verifying isIDAttribute
391
// QTypeSequence with all types verifying isIDAttribute
392
// QTypeUnion with at leat one type verifying isIDAttribute
393
public boolean isIDAttribute() {
394         return false;
395     }
396
397     // tells whether qtype is a node
398
// QTypeAttribute
399
// QTypeCData
400
// QTypeComment
401
// QTypeElement
402
// QTypeProcessingInstruction
403
// QTypeCollection with type verifying isNode
404
// QTypeSequence with all types verifying isNode
405
// QTypeUnion with at leat one type verifying isNode
406
public boolean isNode() {
407         return false;
408     }
409
410     // tells whether qtype is a node with simple type
411
// QTypeAttribute
412
// QTypeElement with simple type (typed value)
413
// QTypeCollection with type verifying isSimpleTypeNode
414
// QTypeSequence with all types verifying isSimpleTypeNode
415
// QTypeUnion with at leat one type verifying isSimpleTypeNode
416
public boolean isSimpleTypeNode() {
417         return false;
418     }
419
420     // // tells whether qtype is a collection
421
// // QTypeCollection
422
// // QTypeUnion with at leat one type verifying isCollection
423
// public boolean isCollection() {
424
// return false;
425
// }
426

427     // tells whether qtype is a collection
428
// QTypeCollection
429
// QTypeSequence
430
// QTypeUnion with at leat one type verifying isMultiple
431
public boolean isMultiple() {
432         switch (getOccurence()) {
433             case OCC_0_0 :
434             case OCC_1_1 :
435             case OCC_0_1 :
436                 return false;
437             case OCC_0_N :
438             case OCC_1_N :
439                 return true;
440         }
441         return false;
442     }
443
444     // tells whether qtype is atomic
445
// QTypeAtom
446
// QTypeAttribute
447
// QTypeElement with TypedValue not null
448
// QTypeUnion with at leat one type verifying isAtomic
449
public boolean isAtomic() {
450         return false;
451     }
452
453     // tells whether qtype is mixed
454
// QTypeElement with mixed type (complex type mixed=
455
// QTypeCollection with type verifying isMixed
456
// QTypeSequence with all types verifying isMixed
457
// QTypeUnion with at leat one type verifying isMixed
458
public boolean isMixed() {
459         return false;
460     }
461
462     // tells whether qtype is element
463
// QTypeElement
464
// QTypeCollection with type verifying isElement
465
// QTypeSequence with all types verifying isElement
466
// QTypeUnion with at leat one type verifying isElement
467
public boolean isElement() {
468         return false;
469     }
470
471     // tells whether qtype is document
472
// QTypeDocument
473
// QTypeUnion with at leat one type verifying QTypeDocument
474
public boolean isDocument() {
475         return false;
476     }
477
478     // tells whether qtype is qname
479
// QTypeAtom with type qname
480
public boolean isQName() {
481         return false;
482     }
483
484     public QType applyDATAFunction() throws TypeException {
485         return null;
486     }
487
488     public boolean canBeComparedTo(QType compType) {
489         return false;
490     }
491
492     protected boolean compare(Type type1, Type type2) {
493         if (type1 == null || type2 == null)
494             return true;
495         if (type1 == null && type2 != null)
496             return false;
497         if (type2 == null && type1 != null)
498             return false;
499         if (type1 == null || type2 == null || (type1.getName() == null && type2.getName() != null) || (type1.getName() != null && type2.getName() == null))
500             return false;
501         return ((type1.getName() == null && type2.getName() == null) || (type1.getName() != null && type1.getName().equals(type2.getName()))) && ((type1.getNamespace() == null && type2.getNamespace() == null) || (type1.getNamespace() != null && type1.getNamespace().equals(type2.getNamespace())));
502     }
503
504
505     protected boolean isNumeric(Type type) {
506         SimpleType stype = type.getValueType();
507         if (stype == null) {
508             if (type.getName() != null && type.getName().equals(TypeVisitor.SC_ANYTYPE))
509                 return true;
510             return false;
511         }
512         switch (stype.getPrimitive().getType()) {
513             /*
514              case PrimitiveType.STRING :
515             case PrimitiveType.BOOLEAN :
516              */

517             case PrimitiveType.DECIMAL :
518             case PrimitiveType.DOUBLE :
519             case PrimitiveType.FLOAT :
520                 return true;
521                 /*
522                  case PrimitiveType.DURATION :
523                 case PrimitiveType.DATE_TIME :
524                 case PrimitiveType.TIME :
525                 case PrimitiveType.DATE :
526                 case PrimitiveType.GYEAR_MONTH :
527                 case PrimitiveType.GYEAR :
528                 case PrimitiveType.GMONTH_DAY :
529                 case PrimitiveType.GDAY :
530                 case PrimitiveType.GMONTH :
531                 case PrimitiveType.HEX_BINARY :
532                 case PrimitiveType.BASE64_BINARY :
533                 case PrimitiveType.ANY_URI :
534                 case PrimitiveType.QNAME :
535                 case PrimitiveType.NOTATION :
536                  
537                 case PrimitiveType.ID :
538                 case PrimitiveType.IDREF :
539                  
540                 case PrimitiveType.LIST :
541                 case PrimitiveType.UNION :
542                 case PrimitiveType.ANYSIMPLETYPE :
543                  */

544             default :
545                 break;
546         }
547         return false;
548     }
549
550     protected boolean isInteger(Type type) {
551         SimpleType stype = type.getValueType();
552         if (stype == null)
553             return false;
554         switch (stype.getPrimitive().getType()) {
555             /*
556              case PrimitiveType.STRING :
557             case PrimitiveType.BOOLEAN :
558              */

559             case PrimitiveType.DECIMAL :
560                 if (stype.getPrimitive().getFractionDigits() == 0)
561                     return true;
562                 /*
563                  case PrimitiveType.DOUBLE :
564                 case PrimitiveType.FLOAT : return true;
565                 case PrimitiveType.DURATION :
566                 case PrimitiveType.DATE_TIME :
567                 case PrimitiveType.TIME :
568                 case PrimitiveType.DATE :
569                 case PrimitiveType.GYEAR_MONTH :
570                 case PrimitiveType.GYEAR :
571                 case PrimitiveType.GMONTH_DAY :
572                 case PrimitiveType.GDAY :
573                 case PrimitiveType.GMONTH :
574                 case PrimitiveType.HEX_BINARY :
575                 case PrimitiveType.BASE64_BINARY :
576                 case PrimitiveType.ANY_URI :
577                 case PrimitiveType.QNAME :
578                 case PrimitiveType.NOTATION :
579                  
580                 case PrimitiveType.ID :
581                 case PrimitiveType.IDREF :
582                  
583                 case PrimitiveType.LIST :
584                 case PrimitiveType.UNION :
585                 case PrimitiveType.ANYSIMPLETYPE :
586                  */

587             default :
588                 break;
589         }
590         return false;
591     }
592
593     protected boolean isString(Type type) {
594         SimpleType stype = type.getValueType();
595         if (stype == null)
596             return false;
597         switch (stype.getPrimitive().getType()) {
598             case PrimitiveType.STRING :
599             case PrimitiveType.ANYSIMPLETYPE :
600                 return true;
601                 /*
602                  case PrimitiveType.BOOLEAN :
603                 case PrimitiveType.DECIMAL :
604                 case PrimitiveType.DOUBLE :
605                 case PrimitiveType.FLOAT :
606                 case PrimitiveType.DURATION :
607                 case PrimitiveType.DATE_TIME :
608                 case PrimitiveType.TIME :
609                 case PrimitiveType.DATE :
610                 case PrimitiveType.GYEAR_MONTH :
611                 case PrimitiveType.GYEAR :
612                 case PrimitiveType.GMONTH_DAY :
613                 case PrimitiveType.GDAY :
614                 case PrimitiveType.GMONTH :
615                 case PrimitiveType.HEX_BINARY :
616                 case PrimitiveType.BASE64_BINARY :
617                 case PrimitiveType.ANY_URI :
618                 case PrimitiveType.QNAME :
619                 case PrimitiveType.NOTATION :
620                  
621                 case PrimitiveType.ID :
622                 case PrimitiveType.IDREF :
623                  
624                 case PrimitiveType.LIST :
625                 case PrimitiveType.UNION :
626                 case PrimitiveType.ANYSIMPLETYPE :
627                  **/

628             default :
629                 break;
630         }
631         return false;
632     }
633
634     protected boolean isDate(Type type) {
635         SimpleType stype = type.getValueType();
636         if (stype == null)
637             return false;
638         switch (stype.getPrimitive().getType()) {
639             /*
640              case PrimitiveType.STRING :
641             case PrimitiveType.BOOLEAN :
642             case PrimitiveType.DECIMAL :
643             case PrimitiveType.DOUBLE :
644             case PrimitiveType.FLOAT :
645             case PrimitiveType.DURATION :
646              */

647             case PrimitiveType.DATE_TIME :
648                 // case PrimitiveType.TIME :
649
case PrimitiveType.DATE :
650                 return true;
651                 /*
652                  case PrimitiveType.GYEAR_MONTH :
653                 case PrimitiveType.GYEAR :
654                 case PrimitiveType.GMONTH_DAY :
655                 case PrimitiveType.GDAY :
656                 case PrimitiveType.GMONTH :
657                 case PrimitiveType.HEX_BINARY :
658                 case PrimitiveType.BASE64_BINARY :
659                 case PrimitiveType.ANY_URI :
660                 case PrimitiveType.QNAME :
661                 case PrimitiveType.NOTATION :
662                  
663                 case PrimitiveType.ID :
664                 case PrimitiveType.IDREF :
665                  
666                 case PrimitiveType.LIST :
667                 case PrimitiveType.UNION :
668                 case PrimitiveType.ANYSIMPLETYPE :
669                  */

670             default :
671                 break;
672         }
673         return false;
674     }
675
676     protected boolean isBoolean(Type type) {
677         SimpleType stype = type.getValueType();
678         if (stype == null)
679             return false;
680         switch (stype.getPrimitive().getType()) {
681             // case PrimitiveType.STRING :
682
case PrimitiveType.BOOLEAN :
683                 return true;
684                 /*
685                  case PrimitiveType.DECIMAL :
686                 case PrimitiveType.DOUBLE :
687                 case PrimitiveType.FLOAT :
688                 case PrimitiveType.DURATION :
689                 case PrimitiveType.DATE_TIME :
690                 case PrimitiveType.TIME :
691                 case PrimitiveType.DATE :
692                 case PrimitiveType.GYEAR_MONTH :
693                 case PrimitiveType.GYEAR :
694                 case PrimitiveType.GMONTH_DAY :
695                 case PrimitiveType.GDAY :
696                 case PrimitiveType.GMONTH :
697                 case PrimitiveType.HEX_BINARY :
698                 case PrimitiveType.BASE64_BINARY :
699                 case PrimitiveType.ANY_URI :
700                 case PrimitiveType.QNAME :
701                 case PrimitiveType.NOTATION :
702                  
703                 case PrimitiveType.ID :
704                 case PrimitiveType.IDREF :
705                  
706                 case PrimitiveType.LIST :
707                 case PrimitiveType.UNION :
708                 case PrimitiveType.ANYSIMPLETYPE :
709                  */

710             default :
711                 break;
712         }
713         return false;
714     }
715
716     protected boolean isQName(Type type) {
717         SimpleType stype = type.getValueType();
718         if (stype == null)
719             return false;
720         switch (stype.getPrimitive().getType()) {
721             case PrimitiveType.STRING :
722             /*
723             case PrimitiveType.BOOLEAN :
724             case PrimitiveType.DECIMAL :
725             case PrimitiveType.DOUBLE :
726             case PrimitiveType.FLOAT :
727             case PrimitiveType.DURATION :
728             case PrimitiveType.DATE_TIME :
729             case PrimitiveType.TIME :
730             case PrimitiveType.DATE :
731             case PrimitiveType.GYEAR_MONTH :
732             case PrimitiveType.GYEAR :
733             case PrimitiveType.GMONTH_DAY :
734             case PrimitiveType.GDAY :
735             case PrimitiveType.GMONTH :
736             case PrimitiveType.HEX_BINARY :
737             case PrimitiveType.BASE64_BINARY :
738             case PrimitiveType.ANY_URI :
739             */

740             case PrimitiveType.QNAME :
741                 return true;
742             /*
743             case PrimitiveType.NOTATION :
744              
745             case PrimitiveType.ID :
746             case PrimitiveType.IDREF :
747              
748             case PrimitiveType.LIST :
749             case PrimitiveType.UNION :
750             case PrimitiveType.ANYSIMPLETYPE :
751             */

752             default :
753                 break;
754         }
755         return false;
756     }
757     
758     protected boolean canBeCompared(int primitiveType1, int primitiveType2) {
759         if (primitiveType1 == PrimitiveType.ANYSIMPLETYPE || primitiveType2 == PrimitiveType.ANYSIMPLETYPE)
760             return true;
761         if (primitiveType1 == primitiveType2)
762             return true;
763         switch (primitiveType1) {
764             // case PrimitiveType.STRING :
765
// case PrimitiveType.BOOLEAN :
766
case PrimitiveType.DECIMAL :
767             case PrimitiveType.DOUBLE :
768             case PrimitiveType.FLOAT :
769                 if (primitiveType2 == PrimitiveType.DECIMAL)
770                     return true;
771                 if (primitiveType2 == PrimitiveType.DOUBLE)
772                     return true;
773                 if (primitiveType2 == PrimitiveType.FLOAT)
774                     return true;
775                 break;
776                 // case PrimitiveType.DURATION :
777
case PrimitiveType.DATE_TIME :
778             case PrimitiveType.TIME :
779             case PrimitiveType.DATE :
780             case PrimitiveType.GYEAR_MONTH :
781             case PrimitiveType.GYEAR :
782             case PrimitiveType.GMONTH_DAY :
783             case PrimitiveType.GDAY :
784             case PrimitiveType.GMONTH :
785                 if (primitiveType2 == PrimitiveType.DATE_TIME)
786                     return true;
787                 if (primitiveType2 == PrimitiveType.TIME)
788                     return true;
789                 if (primitiveType2 == PrimitiveType.DATE)
790                     return true;
791                 if (primitiveType2 == PrimitiveType.GYEAR_MONTH)
792                     return true;
793                 if (primitiveType2 == PrimitiveType.GYEAR)
794                     return true;
795                 if (primitiveType2 == PrimitiveType.GMONTH_DAY)
796                     return true;
797                 if (primitiveType2 == PrimitiveType.GDAY)
798                     return true;
799                 if (primitiveType2 == PrimitiveType.GMONTH)
800                     return true;
801                 break;
802                 // case PrimitiveType.HEX_BINARY :
803
// case PrimitiveType.BASE64_BINARY :
804
// case PrimitiveType.ANY_URI :
805
// case PrimitiveType.QNAME :
806
// case PrimitiveType.NOTATION :
807
// case PrimitiveType.ID :
808
// case PrimitiveType.IDREF :
809
// case PrimitiveType.LIST :
810
// case PrimitiveType.UNION :
811
// case PrimitiveType.ANYSIMPLETYPE :
812
default :
813                 break;
814         }
815         return false;
816     }
817
818     public boolean canBeCastedInto(int castType) {
819         return false;
820     }
821
822     public int getCastType() {
823         return -1;
824     }
825
826 }
827
Popular Tags