Package net.sf.saxon.type
Class Type
java.lang.Object
net.sf.saxon.type.Type
This class contains static information about types and methods for constructing type codes.
The class is never instantiated.
The constant integers used for type names in earlier versions of this class have been replaced
by constants in StandardNames
. The constants representing AtomicType
objects are now
available through the BuiltInAtomicType
class.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final short
Item type representing an attribute node - attribute()static final short
Item type representing a comment nodestatic final short
Item type representing a document nodestatic final short
Type representing an element node - element()static final short
A type number for function()static final short
An item type that matches any itemstatic final ItemType
static final short
Item type representing a namespace nodestatic final short
An item type that matches any nodestatic final ItemType
static final short
Dummy node kind used in the tiny tree to contain a parent pointerstatic final short
Item type representing a processing-instruction nodestatic final short
Dummy node kind used in the tiny tree to mark the end of the treestatic final short
Item type representing a text node - text()static final short
Node kind used in the tiny tree to represent an element node having simple text contentstatic final short
Item type representing a text node stored in the tiny tree as compressed whitespace -
Method Summary
Modifier and TypeMethodDescriptionstatic String
displayTypeName
(Item item) Output (for diagnostics) a representation of the type of an item.static ItemType
getBuiltInItemType
(NamespaceUri namespace, String localName) Get the ItemType object for a built-in atomic or list typestatic SimpleType
getBuiltInSimpleType
(NamespaceUri namespace, String localName) Get the SimpleType object for a built-in simple type (atomic type or list type)static ItemType
getCommonSuperType
(ItemType t1, ItemType t2) Get a type that is a common supertype of two given item types, without the benefit of a TypeHierarchy cache.static ItemType
getCommonSuperType
(ItemType t1, ItemType t2, TypeHierarchy th) Get a type that is a common supertype of two given item typesstatic SequenceType
static ItemType
getItemType
(Item item, TypeHierarchy th) Get the ItemType of an Item.static boolean
isGenerallyComparable
(BuiltInAtomicType t1, BuiltInAtomicType t2, boolean ordered) Determine whether two primitive atomic types are comparable under the rules for GeneralComparisons (that is, untyped atomic values treated as comparable to anything)static boolean
isGuaranteedComparable
(BuiltInAtomicType t1, BuiltInAtomicType t2, boolean ordered) Determine whether two primitive atomic types are comparable under the rules for ValueComparisons (that is, untyped atomic values treated as strings)static boolean
isGuaranteedGenerallyComparable
(BuiltInAtomicType t1, BuiltInAtomicType t2, boolean ordered) Determine whether two primitive atomic types are guaranteed comparable under the rules for GeneralComparisons (that is, untyped atomic values treated as comparable to anything).static boolean
isNodeType
(ItemType type) Test whether a given type is (some subtype of) node()static boolean
isPossiblyComparable
(BuiltInAtomicType t1, BuiltInAtomicType t2, int version) Determine whether two primitive atomic types are comparable under the rules for ValueComparisons (that is, untyped atomic values treated as strings)static boolean
isPrimitiveAtomicType
(int fingerprint) Determine whether a given atomic type is a primitive type.static boolean
isPrimitiveAtomicUType
(int fingerprint) Determine whether this type is a type that corresponds exactly to a UTypestatic boolean
isSubType
(AtomicType one, AtomicType two) Determine whether one atomic type is a subtype of another (without access to the TypeHierarchy object)
-
Field Details
-
ELEMENT
public static final short ELEMENTType representing an element node - element()- See Also:
-
ATTRIBUTE
public static final short ATTRIBUTEItem type representing an attribute node - attribute()- See Also:
-
TEXT
public static final short TEXTItem type representing a text node - text()- See Also:
-
WHITESPACE_TEXT
public static final short WHITESPACE_TEXTItem type representing a text node stored in the tiny tree as compressed whitespace- See Also:
-
PROCESSING_INSTRUCTION
public static final short PROCESSING_INSTRUCTIONItem type representing a processing-instruction node- See Also:
-
COMMENT
public static final short COMMENTItem type representing a comment node- See Also:
-
DOCUMENT
public static final short DOCUMENTItem type representing a document node- See Also:
-
NAMESPACE
public static final short NAMESPACEItem type representing a namespace node- See Also:
-
STOPPER
public static final short STOPPERDummy node kind used in the tiny tree to mark the end of the tree- See Also:
-
PARENT_POINTER
public static final short PARENT_POINTERDummy node kind used in the tiny tree to contain a parent pointer- See Also:
-
TEXTUAL_ELEMENT
public static final short TEXTUAL_ELEMENTNode kind used in the tiny tree to represent an element node having simple text content- See Also:
-
NODE
public static final short NODEAn item type that matches any node- See Also:
-
NODE_TYPE
-
ITEM
public static final short ITEMAn item type that matches any item- See Also:
-
ITEM_TYPE
-
FUNCTION
public static final short FUNCTIONA type number for function()- See Also:
-
-
Method Details
-
isNodeType
Test whether a given type is (some subtype of) node()- Parameters:
type
- The type to be tested- Returns:
- true if the item type is node() or a subtype of node()
-
getItemType
Get the ItemType of an Item. This method is used almost entirely for diagnostics, to report the actual type of an item when it differs from the required type. The actual result is not completely well-defined, since there are many item types that a given type conforms to, and it is not always the case that one of them is a subtype of all the others.- Parameters:
item
- the item whose type is requiredth
- the type hierarchy cache. In most cases this can be null, but the returned type may then be less precise (for example, the type returned for a map or array will simply bemap(*)
orarray(*)
). For external objects, the parameter must not be null- Returns:
- the item type of the item
-
displayTypeName
Output (for diagnostics) a representation of the type of an item. This does not have to be the most specific type- Parameters:
item
- the item whose type is to be displayed- Returns:
- a string representation of the type of the item
-
getBuiltInItemType
Get the ItemType object for a built-in atomic or list type- Parameters:
namespace
- the namespace URI of the typelocalName
- the local name of the type- Returns:
- the ItemType, or null if not found
-
getBuiltInSimpleType
Get the SimpleType object for a built-in simple type (atomic type or list type)- Parameters:
namespace
- the namespace URI of the typelocalName
- the local name of the type- Returns:
- the SimpleType, or null if not found
-
isSubType
Determine whether one atomic type is a subtype of another (without access to the TypeHierarchy object)- Parameters:
one
- the first atomic typetwo
- the second atomic type- Returns:
- true if the first atomic type is equal to, or derived by restriction from, the second atomic type
-
getCommonSuperType
Get a type that is a common supertype of two given item types- Parameters:
t1
- the first item typet2
- the second item typeth
- the type hierarchy cache- Returns:
- the item type that is a supertype of both the supplied item types
-
getCommonSuperType
Get a type that is a common supertype of two given item types, without the benefit of a TypeHierarchy cache. This will generally give a less precise answer than the methodgetCommonSuperType(ItemType, ItemType, TypeHierarchy)
- Parameters:
t1
- the first item typet2
- the second item type- Returns:
- an item type that is a supertype of both the supplied item types
-
getCommonSuperType
-
isPrimitiveAtomicType
public static boolean isPrimitiveAtomicType(int fingerprint) Determine whether a given atomic type is a primitive type. The primitive types are the 19 primitive types of XML Schema, plus xs:integer, xs:dayTimeDuration and xs:yearMonthDuration; xs:untypedAtomic; the 7 node kinds; and all supertypes of these (item(), node(), xs:anyAtomicType, xs:numeric, ...)- Parameters:
fingerprint
- the item type code to be tested- Returns:
- true if the type is considered primitive under the above rules
-
isPrimitiveAtomicUType
public static boolean isPrimitiveAtomicUType(int fingerprint) Determine whether this type is a type that corresponds exactly to a UType- Parameters:
fingerprint
- the item type code to be tested- Returns:
- true if the type is considered primitive under the above rules
-
isGuaranteedComparable
public static boolean isGuaranteedComparable(BuiltInAtomicType t1, BuiltInAtomicType t2, boolean ordered) Determine whether two primitive atomic types are comparable under the rules for ValueComparisons (that is, untyped atomic values treated as strings)- Parameters:
t1
- the first type to compare. This must be a primitive atomic type as defined byItemType.getPrimitiveType()
t2
- the second type to compare. This must be a primitive atomic type as defined byItemType.getPrimitiveType()
ordered
- true if testing for an ordering comparison (lt, gt, le, ge). False if testing for an equality comparison (eq, ne)- Returns:
- true if the types are comparable, as defined by the rules of the "eq" operator; false if they are not comparable, or if we don't yet know (because some subtypes of the static type are comparable and others are not)
-
isPossiblyComparable
Determine whether two primitive atomic types are comparable under the rules for ValueComparisons (that is, untyped atomic values treated as strings)- Parameters:
t1
- the first type to compare. This must be a primitive atomic type as defined byItemType.getPrimitiveType()
t2
- the second type to compare. This must be a primitive atomic type as defined byItemType.getPrimitiveType()
version
- the XPath language level (either 20, 30, 305, 31 or 40)- Returns:
- true if the types are guaranteed comparable, as defined by the rules of the "eq" operator, or if we don't yet know (because some subtypes of the static type are comparable and others are not). False if they are definitely not comparable.
-
isGenerallyComparable
public static boolean isGenerallyComparable(BuiltInAtomicType t1, BuiltInAtomicType t2, boolean ordered) Determine whether two primitive atomic types are comparable under the rules for GeneralComparisons (that is, untyped atomic values treated as comparable to anything)- Parameters:
t1
- the first type to compare. This must be a primitive atomic type as defined byItemType.getPrimitiveType()
t2
- the second type to compare. This must be a primitive atomic type as defined byItemType.getPrimitiveType()
ordered
- true if testing for an ordering comparison (lt, gt, le, ge). False if testing for an equality comparison (eq, ne)- Returns:
- true if the types are comparable, as defined by the rules of the "=" operator
-
isGuaranteedGenerallyComparable
public static boolean isGuaranteedGenerallyComparable(BuiltInAtomicType t1, BuiltInAtomicType t2, boolean ordered) Determine whether two primitive atomic types are guaranteed comparable under the rules for GeneralComparisons (that is, untyped atomic values treated as comparable to anything). This method returns false if a run-time check is necessary.- Parameters:
t1
- the first type to compare. This must be a primitive atomic type as defined byItemType.getPrimitiveType()
t2
- the second type to compare. This must be a primitive atomic type as defined byItemType.getPrimitiveType()
ordered
- true if testing for an ordering comparison (lt, gt, le, ge). False if testing for an equality comparison (eq, ne)- Returns:
- true if the types are comparable, as defined by the rules of the "=" operator
-