Source Code Cross Referenced for Type.java in  » XML » saxonb » net » sf » saxon » type » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » XML » saxonb » net.sf.saxon.type 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sf.saxon.type;
002:
003:        import net.sf.saxon.om.Item;
004:        import net.sf.saxon.om.NamePool;
005:        import net.sf.saxon.om.NodeInfo;
006:        import net.sf.saxon.pattern.AnyNodeTest;
007:        import net.sf.saxon.pattern.NoNodeTest;
008:        import net.sf.saxon.pattern.NodeTest;
009:        import net.sf.saxon.pattern.NodeKindTest;
010:        import net.sf.saxon.style.StandardNames;
011:        import net.sf.saxon.value.AtomicValue;
012:
013:        import java.io.Serializable;
014:
015:        /**
016:         * This class contains static information about types and methods for constructing type codes.
017:         * The class is never instantiated.
018:         *
019:         */
020:
021:        public abstract class Type implements  Serializable {
022:
023:            // Note that the integer codes representing node kinds are the same as
024:            // the codes allocated in the DOM interface, while the codes for built-in
025:            // atomic type are fingerprints allocated in StandardNames. These two sets of
026:            // codes must not overlap!
027:
028:            // The constants that are defined as synonyms of constants in StandardNames
029:            // are purely for convenience (or for legacy), they will eventually be phased out.
030:
031:            /**
032:             * Type representing an element node - element()
033:             */
034:
035:            public static final short ELEMENT = 1;
036:            /**
037:             * Item type representing an attribute node - attribute()
038:             */
039:            public static final short ATTRIBUTE = 2;
040:            /**
041:             * Item type representing a text node - text()
042:             */
043:            public static final short TEXT = 3;
044:            /**
045:             * Item type representing a processing-instruction node
046:             */
047:            public static final short PROCESSING_INSTRUCTION = 7;
048:            /**
049:             * Item type representing a comment node
050:             */
051:            public static final short COMMENT = 8;
052:            /**
053:             * Item type representing a document node
054:             */
055:            public static final short DOCUMENT = 9;
056:            /**
057:             * Item type representing a namespace node
058:             */
059:            public static final short NAMESPACE = 13;
060:            /**
061:             * Dummy node kind used in the tiny tree to mark the end of the tree
062:             */
063:            public static final short STOPPER = 11;
064:            /**
065:             * Dummy node kind used in the tiny tree to contain a parent pointer
066:             */
067:            public static final short PARENT_POINTER = 12;
068:
069:            /**
070:             * An item type that matches any node
071:             */
072:
073:            public static final short NODE = 0;
074:
075:            public static final ItemType NODE_TYPE = AnyNodeTest.getInstance();
076:
077:            /**
078:             * An item type that matches any item
079:             */
080:
081:            public static final short ITEM = 88;
082:
083:            public static final ItemType ITEM_TYPE = AnyItemType.getInstance();
084:
085:            /**
086:             * A type that matches nothing
087:             */
088:
089:            public static final short MAX_NODE_TYPE = 13;
090:            /**
091:             * Item type that matches no items (corresponds to SequenceType empty())
092:             */
093:            public static final short EMPTY = 15; // a test for this type will never be satisfied
094:
095:            private Type() {
096:            }
097:
098:            /**
099:             * Test whether a given type is (some subtype of) node()
100:             *
101:             * @param type The type to be tested
102:             * @return true if the item type is node() or a subtype of node()
103:             */
104:
105:            public static boolean isNodeType(ItemType type) {
106:                return type instanceof  NodeTest;
107:            }
108:
109:            /**
110:             * Constant denoting any atomic type (the union of all primitive types and types
111:             * derived from primitive types by restriction or by union)
112:             */
113:
114:            //public static final int ATOMIC          = 90;
115:            public static final int ANY_ATOMIC = StandardNames.XDT_ANY_ATOMIC_TYPE;
116:
117:            /**
118:             * Constant denoting any numeric type (the union of float, double, and decimal)
119:             */
120:
121:            //public static final int NUMBER          = 91;
122:            public static final int NUMBER = StandardNames.XDT_NUMERIC;
123:
124:            /**
125:             * Constants representing primitive data types defined in Schema Part 2
126:             */
127:
128:            public static final int STRING = StandardNames.XS_STRING;
129:            /**
130:             * Item type representing the type xs:boolean
131:             */
132:            public static final int BOOLEAN = StandardNames.XS_BOOLEAN;
133:            /**
134:             * Item type representing the type xs:decimal
135:             */
136:            public static final int DECIMAL = StandardNames.XS_DECIMAL;
137:            /**
138:             * Item type representing the type xs:float
139:             */
140:            public static final int FLOAT = StandardNames.XS_FLOAT;
141:            /**
142:             * Item type representing the type xs:double
143:             */
144:            public static final int DOUBLE = StandardNames.XS_DOUBLE;
145:            /**
146:             * Item type representing the type xs:duration
147:             */
148:            public static final int DURATION = StandardNames.XS_DURATION;
149:            /**
150:             * Item type representing the type xs:dateTime
151:             */
152:            public static final int DATE_TIME = StandardNames.XS_DATE_TIME;
153:            /**
154:             * Item type representing the type xs:time
155:             */
156:            public static final int TIME = StandardNames.XS_TIME;
157:            /**
158:             * Item type representing the type xs:date
159:             */
160:            public static final int DATE = StandardNames.XS_DATE;
161:            /**
162:             * Item type representing the type xs:gYearMonth
163:             */
164:            public static final int G_YEAR_MONTH = StandardNames.XS_G_YEAR_MONTH;
165:            /**
166:             * Item type representing the type xs:gYear
167:             */
168:            public static final int G_YEAR = StandardNames.XS_G_YEAR;
169:            /**
170:             * Item type representing the type xs:monthDay
171:             */
172:            public static final int G_MONTH_DAY = StandardNames.XS_G_MONTH_DAY;
173:            /**
174:             * Item type representing the type xs:gDay
175:             */
176:            public static final int G_DAY = StandardNames.XS_G_DAY;
177:            /**
178:             * Item type representing the type xs:gMonth
179:             */
180:            public static final int G_MONTH = StandardNames.XS_G_MONTH;
181:            /**
182:             * Item type representing the type xs:hexBinary
183:             */
184:            public static final int HEX_BINARY = StandardNames.XS_HEX_BINARY;
185:            /**
186:             * Item type representing the type xs:base64Binary
187:             */
188:            public static final int BASE64_BINARY = StandardNames.XS_BASE64_BINARY;
189:            /**
190:             * Item type representing the type xs:anyURI
191:             */
192:            public static final int ANY_URI = StandardNames.XS_ANY_URI;
193:            /**
194:             * Item type representing the type xs:QName
195:             */
196:            public static final int QNAME = StandardNames.XS_QNAME;
197:            /**
198:             * Item type representing the type xs:NOTATION
199:             *
200:             */
201:            public static final int NOTATION = StandardNames.XS_NOTATION;
202:
203:            /**
204:             * Item type representing the type xdt:untypedAtomic
205:             * (the type of the content of a schema-less node)
206:             */
207:
208:            public static final int UNTYPED_ATOMIC = StandardNames.XDT_UNTYPED_ATOMIC;
209:
210:            public static final int ANY_SIMPLE_TYPE = StandardNames.XS_ANY_SIMPLE_TYPE;
211:
212:            /**
213:             * Constant representing the type of an external object (for use by extension functions)
214:             */
215:
216:            public static final int OBJECT = StandardNames.SAXON_JAVA_LANG_OBJECT;
217:
218:            /**
219:             * Item type representing the type xs:integer
220:             */
221:
222:            public static final int INTEGER = StandardNames.XS_INTEGER;
223:            /**
224:             * Item type representing the type xs:nonPositiveInteger
225:             */
226:            public static final int NON_POSITIVE_INTEGER = StandardNames.XS_NON_POSITIVE_INTEGER;
227:            /**
228:             * Item type representing the type xs:negativeInteger
229:             */
230:            public static final int NEGATIVE_INTEGER = StandardNames.XS_NEGATIVE_INTEGER;
231:            /**
232:             * Item type representing the type xs:long
233:             */
234:            public static final int LONG = StandardNames.XS_LONG;
235:            /**
236:             * Item type representing the type xs:int
237:             */
238:            public static final int INT = StandardNames.XS_INT;
239:            /**
240:             * Item type representing the type xs:short
241:             */
242:            public static final int SHORT = StandardNames.XS_SHORT;
243:            /**
244:             * Item type representing the type xs:byte
245:             */
246:            public static final int BYTE = StandardNames.XS_BYTE;
247:            /**
248:             * Item type representing the type xs:nonNegativeInteger
249:             */
250:            public static final int NON_NEGATIVE_INTEGER = StandardNames.XS_NON_NEGATIVE_INTEGER;
251:            /**
252:             * Item type representing the type xs:positiveInteger
253:             */
254:            public static final int POSITIVE_INTEGER = StandardNames.XS_POSITIVE_INTEGER;
255:            /**
256:             * Item type representing the type xs:unsignedLong
257:             */
258:            public static final int UNSIGNED_LONG = StandardNames.XS_UNSIGNED_LONG;
259:            /**
260:             * Item type representing the type xs:unsignedInt
261:             */
262:            public static final int UNSIGNED_INT = StandardNames.XS_UNSIGNED_INT;
263:            /**
264:             * Item type representing the type xs:unsignedShort
265:             */
266:            public static final int UNSIGNED_SHORT = StandardNames.XS_UNSIGNED_SHORT;
267:            /**
268:             * Item type representing the type xs:unsignedByte
269:             */
270:            public static final int UNSIGNED_BYTE = StandardNames.XS_UNSIGNED_BYTE;
271:
272:            /**
273:             * Item type representing the type xs:normalizedString
274:             */
275:            public static final int NORMALIZED_STRING = StandardNames.XS_NORMALIZED_STRING;
276:            /**
277:             * Item type representing the type xs:token
278:             */
279:            public static final int TOKEN = StandardNames.XS_TOKEN;
280:            /**
281:             * Item type representing the type xs:language
282:             */
283:            public static final int LANGUAGE = StandardNames.XS_LANGUAGE;
284:            /**
285:             * Item type representing the type xs:NMTOKEN
286:             */
287:            public static final int NMTOKEN = StandardNames.XS_NMTOKEN;
288:            /**
289:             * Content type representing the complex type xs:NMTOKENS
290:             */
291:            public static final int NMTOKENS = StandardNames.XS_NMTOKENS; // NB: list type
292:            /**
293:             * Item type representing the type xs:NAME
294:             */
295:            public static final int NAME = StandardNames.XS_NAME;
296:            /**
297:             * Item type representing the type xs:NCNAME
298:             */
299:            public static final int NCNAME = StandardNames.XS_NCNAME;
300:            /**
301:             * Item type representing the type xs:ID
302:             */
303:            public static final int ID = StandardNames.XS_ID;
304:            /**
305:             * Item type representing the type xs:IDREF
306:             */
307:            public static final int IDREF = StandardNames.XS_IDREF;
308:            /**
309:             * Content type representing the complex type xs:IDREFS
310:             */
311:            public static final int IDREFS = StandardNames.XS_IDREFS; // NB: list type
312:            /**
313:             *
314:             * Item type representing the type xs:ENTITY
315:             */
316:            public static final int ENTITY = StandardNames.XS_ENTITY;
317:
318:            /**
319:             *
320:             * Item type representing the type xdt:yearMonthDuration
321:             */
322:            public static final int YEAR_MONTH_DURATION = StandardNames.XDT_YEAR_MONTH_DURATION;
323:            /**
324:             *
325:             * Item type representing the type xdt:dayTimeDuration
326:             */
327:            public static final int DAY_TIME_DURATION = StandardNames.XDT_DAY_TIME_DURATION;
328:
329:            public static final BuiltInAtomicType UNTYPED_ATOMIC_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
330:                    .getSchemaType(StandardNames.XDT_UNTYPED_ATOMIC);
331:
332:            public static final BuiltInAtomicType ANY_ATOMIC_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
333:                    .getSchemaType(StandardNames.XDT_ANY_ATOMIC_TYPE);
334:
335:            public static final BuiltInAtomicType YEAR_MONTH_DURATION_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
336:                    .getSchemaType(StandardNames.XDT_YEAR_MONTH_DURATION);
337:
338:            public static final BuiltInAtomicType DAY_TIME_DURATION_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
339:                    .getSchemaType(StandardNames.XDT_DAY_TIME_DURATION);
340:
341:            public static final BuiltInAtomicType STRING_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
342:                    .getSchemaType(StandardNames.XS_STRING);
343:
344:            public static final BuiltInAtomicType BOOLEAN_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
345:                    .getSchemaType(StandardNames.XS_BOOLEAN);
346:
347:            public static final BuiltInAtomicType DECIMAL_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
348:                    .getSchemaType(StandardNames.XS_DECIMAL);
349:
350:            public static final BuiltInAtomicType FLOAT_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
351:                    .getSchemaType(StandardNames.XS_FLOAT);
352:
353:            public static final BuiltInAtomicType DOUBLE_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
354:                    .getSchemaType(StandardNames.XS_DOUBLE);
355:
356:            public static final BuiltInAtomicType DURATION_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
357:                    .getSchemaType(StandardNames.XS_DURATION);
358:
359:            public static final BuiltInAtomicType DATE_TIME_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
360:                    .getSchemaType(StandardNames.XS_DATE_TIME);
361:
362:            public static final BuiltInAtomicType TIME_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
363:                    .getSchemaType(StandardNames.XS_TIME);
364:
365:            public static final BuiltInAtomicType DATE_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
366:                    .getSchemaType(StandardNames.XS_DATE);
367:
368:            public static final BuiltInAtomicType G_YEAR_MONTH_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
369:                    .getSchemaType(StandardNames.XS_G_YEAR_MONTH);
370:
371:            public static final BuiltInAtomicType G_YEAR_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
372:                    .getSchemaType(StandardNames.XS_G_YEAR);
373:
374:            public static final BuiltInAtomicType G_MONTH_DAY_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
375:                    .getSchemaType(StandardNames.XS_G_MONTH_DAY);
376:
377:            public static final BuiltInAtomicType G_DAY_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
378:                    .getSchemaType(StandardNames.XS_G_DAY);
379:
380:            public static final BuiltInAtomicType G_MONTH_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
381:                    .getSchemaType(StandardNames.XS_G_MONTH);
382:
383:            public static final BuiltInAtomicType HEX_BINARY_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
384:                    .getSchemaType(StandardNames.XS_HEX_BINARY);
385:
386:            public static final BuiltInAtomicType BASE64_BINARY_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
387:                    .getSchemaType(StandardNames.XS_BASE64_BINARY);
388:
389:            public static final BuiltInAtomicType ANY_URI_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
390:                    .getSchemaType(StandardNames.XS_ANY_URI);
391:
392:            public static final BuiltInAtomicType QNAME_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
393:                    .getSchemaType(StandardNames.XS_QNAME);
394:
395:            public static final BuiltInAtomicType NOTATION_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
396:                    .getSchemaType(StandardNames.XS_NOTATION);
397:
398:            public static final BuiltInAtomicType INTEGER_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
399:                    .getSchemaType(StandardNames.XS_INTEGER);
400:
401:            public static final BuiltInAtomicType ID_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
402:                    .getSchemaType(StandardNames.XS_ID);
403:
404:            public static final BuiltInAtomicType NCNAME_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
405:                    .getSchemaType(StandardNames.XS_NCNAME);
406:
407:            public static final BuiltInAtomicType NUMBER_TYPE = (BuiltInAtomicType) BuiltInSchemaFactory
408:                    .getSchemaType(StandardNames.XDT_NUMERIC);
409:
410:            /**
411:             * Get the ItemType of an Item
412:             */
413:
414:            public static ItemType getItemType(Item item) {
415:                if (item instanceof  AtomicValue) {
416:                    return ((AtomicValue) item).getItemType(null);
417:                } else {
418:                    return NodeKindTest.makeNodeKindTest(((NodeInfo) item)
419:                            .getNodeKind());
420:                    // TODO: add a ContentTypeTest for the type annotation
421:                }
422:            }
423:
424:            /**
425:             * Output (for diagnostics) a representation of the type of an item. This
426:             * does not have to be the most specific type
427:             */
428:
429:            public static final String displayTypeName(Item item) {
430:                if (item instanceof  NodeInfo) {
431:                    NodeInfo node = (NodeInfo) item;
432:                    switch (node.getNodeKind()) {
433:                    case DOCUMENT:
434:                        return "document-node()";
435:                    case ELEMENT:
436:                        NamePool pool = node.getNamePool();
437:                        int annotation = node.getTypeAnnotation();
438:                        return "element("
439:                                + ((NodeInfo) item).getDisplayName()
440:                                + ", "
441:                                + (annotation == -1 ? "xdt:untyped)" : pool
442:                                        .getDisplayName(annotation) + ')');
443:                    case ATTRIBUTE:
444:                        NamePool pool2 = node.getNamePool();
445:                        int annotation2 = node.getTypeAnnotation()
446:                                & NamePool.FP_MASK;
447:                        return "attribute("
448:                                + ((NodeInfo) item).getDisplayName()
449:                                + ", "
450:                                + (annotation2 == -1 ? "xdt:untypedAtomic)"
451:                                        : pool2.getDisplayName(annotation2) + ')');
452:                    case TEXT:
453:                        return "text()";
454:                    case COMMENT:
455:                        return "comment()";
456:                    case PROCESSING_INSTRUCTION:
457:                        return "processing-instruction()";
458:                    case NAMESPACE:
459:                        return "namespace()";
460:                    default:
461:                        return "";
462:                    }
463:                } else {
464:                    return ((AtomicValue) item).getItemType(null).toString();
465:                }
466:            }
467:
468:            /**
469:             * Get the SimpleType object for a built-in simple type code
470:             * @return the SimpleType, or null if not found
471:             */
472:
473:            public static ItemType getBuiltInItemType(String namespace,
474:                    String localName) {
475:                SchemaType t = BuiltInSchemaFactory.getSchemaType(StandardNames
476:                        .getFingerprint(namespace, localName));
477:                if (t instanceof  ItemType) {
478:                    return (ItemType) t;
479:                } else {
480:                    return null;
481:                }
482:            }
483:
484:            /**
485:             * Get the relationship of two schema types to each other
486:             */
487:
488:            public static int schemaTypeRelationship(SchemaType s1,
489:                    SchemaType s2) {
490:                if (s1.isSameType(s2)) {
491:                    return TypeHierarchy.SAME_TYPE;
492:                }
493:                if (s1 instanceof  AnyType) {
494:                    return TypeHierarchy.SUBSUMES;
495:                }
496:                if (s2 instanceof  AnyType) {
497:                    return TypeHierarchy.SUBSUMED_BY;
498:                }
499:                SchemaType t1 = s1;
500:                while (true) {
501:                    t1 = t1.getBaseType();
502:                    if (t1 == null) {
503:                        break;
504:                    }
505:                    if (t1.isSameType(s2)) {
506:                        return TypeHierarchy.SUBSUMED_BY;
507:                    }
508:                }
509:                SchemaType t2 = s2;
510:                while (true) {
511:                    t2 = t2.getBaseType();
512:                    if (t2 == null) {
513:                        break;
514:                    }
515:                    if (t2.isSameType(s1)) {
516:                        return TypeHierarchy.SUBSUMES;
517:                    }
518:                }
519:                return TypeHierarchy.DISJOINT;
520:            }
521:
522:            /**
523:             * Get a type that is a common supertype of two given types
524:             *
525:             * @param t1 the first item type
526:             * @param t2 the second item type
527:             * @param th
528:             * @return the item type that is a supertype of both
529:             *     the supplied item types
530:             */
531:
532:            public static final ItemType getCommonSuperType(ItemType t1,
533:                    ItemType t2, TypeHierarchy th) {
534:                if (t1 instanceof  NoNodeTest) {
535:                    return t2;
536:                }
537:                if (t2 instanceof  NoNodeTest) {
538:                    return t1;
539:                }
540:                int r = th.relationship(t1, t2);
541:                if (r == TypeHierarchy.SAME_TYPE) {
542:                    return t1;
543:                } else if (r == TypeHierarchy.SUBSUMED_BY) {
544:                    return t2;
545:                } else if (r == TypeHierarchy.SUBSUMES) {
546:                    return t1;
547:                } else {
548:                    return getCommonSuperType(t2.getSuperType(th), t1, th);
549:                    // eventually we will hit a type that is a supertype of t2. We reverse
550:                    // the arguments so we go up each branch of the tree alternately.
551:                    // If we hit the root of the tree, one of the earlier conditions will be satisfied,
552:                    // so the recursion will stop.
553:                }
554:            }
555:
556:            /**
557:             * Determine whether this type is a primitive type. The primitive types are
558:             * the 19 primitive types of XML Schema, plus xs:integer, xdt:dayTimeDuration and xdt:yearMonthDuration;
559:             * xdt:untypedAtomic; the 7 node kinds; and all supertypes of these (item(), node(), xdt:anyAtomicType,
560:             * xdt:number, ...)
561:             * @param code the item type code to be tested
562:             * @return true if the type is considered primitive under the above rules
563:             */
564:            public static boolean isPrimitiveType(int code) {
565:                return code >= 0
566:                        && (code <= INTEGER || code == NUMBER
567:                                || code == UNTYPED_ATOMIC || code == ANY_ATOMIC
568:                                || code == DAY_TIME_DURATION
569:                                || code == YEAR_MONTH_DURATION || code == StandardNames.XS_ANY_SIMPLE_TYPE);
570:            }
571:
572:            /**
573:             * Determine whether two primitive atomic types are comparable
574:             * @param t1 the first type to compared.
575:             * This must be a primitive atomic type as defined by {@link ItemType#getPrimitiveType}
576:             * @param t2 the second type to compared.
577:             * This must be a primitive atomic type as defined by {@link ItemType#getPrimitiveType}
578:             * @return true if the types are comparable, as defined by the rules of the "eq" operator
579:             */
580:
581:            public static boolean isComparable(int t1, int t2) {
582:                if (t1 == ANY_ATOMIC || t2 == ANY_ATOMIC)
583:                    return true; // meaning we don't actually know at this stage
584:                if (t1 == UNTYPED_ATOMIC)
585:                    t1 = STRING;
586:                if (t2 == UNTYPED_ATOMIC)
587:                    t2 = STRING;
588:                if (t1 == ANY_URI)
589:                    t1 = STRING;
590:                if (t2 == ANY_URI)
591:                    t2 = STRING;
592:                if (t1 == INTEGER || t1 == DOUBLE || t1 == FLOAT
593:                        || t1 == DECIMAL)
594:                    t1 = NUMBER;
595:                if (t2 == INTEGER || t2 == DOUBLE || t2 == FLOAT
596:                        || t2 == DECIMAL)
597:                    t2 = NUMBER;
598:                return t1 == t2;
599:            }
600:
601:            /**
602:             * Determine whether a primitive type is ordered. Note that the rules for this differ
603:             * between XPath and XML Schema: these are the XPath rules.
604:             * @param type the primitive item type being tested
605:             * @return true if the types are potentially comparable. For abstract types (type=ATOMIC)
606:             * we give the benefit of the doubt and return true.
607:             */
608:
609:            public static boolean isOrdered(int type) {
610:                switch (type) {
611:                case ANY_ATOMIC:
612:                case INTEGER:
613:                case DOUBLE:
614:                case FLOAT:
615:                case DECIMAL:
616:                case NUMBER:
617:                case BOOLEAN:
618:                case STRING:
619:                case ANY_URI:
620:                case DATE_TIME:
621:                case DATE:
622:                case TIME:
623:                case DAY_TIME_DURATION:
624:                case YEAR_MONTH_DURATION:
625:                    return true;
626:                default:
627:                    return false;
628:                }
629:            }
630:
631:            /**
632:             * Test whether the supplied type, which must be a primitive type, is one of
633:             * the numeric primitive types
634:             * @param t the type being tested
635:             * @return true if the type is integer, double, float, decimal, or the abstract type "numeric"
636:             */
637:            public static boolean isNumericPrimitiveType(ItemType t) {
638:                if (t instanceof  AtomicType) {
639:                    int fp = ((AtomicType) t).getFingerprint();
640:                    return fp == INTEGER || fp == DOUBLE || fp == FLOAT
641:                            || fp == DECIMAL || fp == NUMBER;
642:                } else {
643:                    return false;
644:                }
645:            }
646:        }
647:
648:        //
649:        // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
650:        // you may not use this file except in compliance with the License. You may obtain a copy of the
651:        // License at http://www.mozilla.org/MPL/
652:        //
653:        // Software distributed under the License is distributed on an "AS IS" basis,
654:        // WITHOUT WARRANTY OF ANY KIND, either express or implied.
655:        // See the License for the specific language governing rights and limitations under the License.
656:        //
657:        // The Original Code is: all this file.
658:        //
659:        // The Initial Developer of the Original Code is Michael H. Kay
660:        //
661:        // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
662:        //
663:        // Contributor(s): none.
664:        //
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.