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.expr.XPathContext;
006:
007: import java.io.Serializable;
008:
009: /**
010: * ItemType is an interface that allows testing of whether an Item conforms to an
011: * expected type. ItemType represents the types in the type hierarchy in the XPath model,
012: * as distinct from the schema model: an item type is either item() (matches everything),
013: * a node type (matches nodes), an atomic type (matches atomic values), or empty()
014: * (matches nothing). Atomic types, represented by the class AtomicType, are also
015: * instances of SimpleType in the schema type heirarchy. Node Types, represented by
016: * the class NodeTest, are also Patterns as used in XSLT.
017: * @see net.sf.saxon.type.AtomicType
018: * @see net.sf.saxon.pattern.NodeTest
019: */
020:
021: public interface ItemType extends Serializable {
022:
023: /**
024: * Determine whether this item type is atomic (that is, whether it can ONLY match
025: * atomic values)
026: * @return true if this is ANY_ATOMIC_TYPE or a subtype thereof
027: */
028:
029: public boolean isAtomicType();
030:
031: /**
032: * Test whether a given item conforms to this type
033: * @param item The item to be tested
034: * @param context
035: * @return true if the item is an instance of this type; false otherwise
036: */
037:
038: public boolean matchesItem(Item item, XPathContext context);
039:
040: /**
041: * Get the type from which this item type is derived by restriction. This
042: * is the supertype in the XPath type heirarchy, as distinct from the Schema
043: * base type: this means that the supertype of xs:boolean is xdt:anyAtomicType,
044: * whose supertype is item() (rather than xs:anySimpleType).
045: * <p>
046: * In fact the concept of "supertype" is not really well-defined, because the types
047: * form a lattice rather than a hierarchy. The only real requirement on this function
048: * is that it returns a type that strictly subsumes this type, ideally as narrowly
049: * as possible.
050: * @return the supertype, or null if this type is item()
051: * @param th
052: */
053:
054: public ItemType getSuperType(TypeHierarchy th);
055:
056: /**
057: * Get the primitive item type corresponding to this item type. For item(),
058: * this is Type.ITEM. For node(), it is Type.NODE. For specific node kinds,
059: * it is the value representing the node kind, for example Type.ELEMENT.
060: * For anyAtomicValue it is Type.ATOMIC_VALUE. For numeric it is Type.NUMBER.
061: * For other atomic types it is the primitive type as defined in XML Schema,
062: * except that INTEGER is considered to be a primitive type.
063: */
064:
065: public ItemType getPrimitiveItemType();
066:
067: /**
068: * Get the primitive type corresponding to this item type. For item(),
069: * this is Type.ITEM. For node(), it is Type.NODE. For specific node kinds,
070: * it is the value representing the node kind, for example Type.ELEMENT.
071: * For anyAtomicValue it is Type.ATOMIC_VALUE. For numeric it is Type.NUMBER.
072: * For other atomic types it is the primitive type as defined in XML Schema,
073: * except that INTEGER is considered to be a primitive type.
074: */
075:
076: public int getPrimitiveType();
077:
078: /**
079: * Produce a representation of this type name for use in error messages.
080: * Where this is a QName, it will use conventional prefixes
081: */
082:
083: public String toString(NamePool pool);
084:
085: /**
086: * Get the item type of the atomic values that will be produced when an item
087: * of this type is atomized
088: */
089:
090: public AtomicType getAtomizedItemType();
091:
092: }
093:
094: //
095: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
096: // you may not use this file except in compliance with the License. You may obtain a copy of the
097: // License at http://www.mozilla.org/MPL/
098: //
099: // Software distributed under the License is distributed on an "AS IS" basis,
100: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
101: // See the License for the specific language governing rights and limitations under the License.
102: //
103: // The Original Code is: all this file.
104: //
105: // The Initial Developer of the Original Code is Michael H. Kay.
106: //
107: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
108: //
109: // Contributor(s): none.
110: //
|