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: * An implementation of ItemType that matches any item (node or atomic value)
011: */
012:
013: public class AnyItemType implements ItemType, Serializable {
014:
015: private AnyItemType() {
016: };
017:
018: private static AnyItemType theInstance = new AnyItemType();
019:
020: /**
021: * Factory method to get the singleton instance
022: */
023:
024: public static AnyItemType getInstance() {
025: return theInstance;
026: }
027:
028: /**
029: * Determine whether this item type is atomic (that is, whether it can ONLY match
030: * atomic values)
031: *
032: * @return false: this type can match nodes or atomic values
033: */
034:
035: public boolean isAtomicType() {
036: return false;
037: }
038:
039: /**
040: * Test whether a given item conforms to this type
041: * @param item The item to be tested
042: * @param context
043: * @return true if the item is an instance of this type; false otherwise
044: */
045:
046: public boolean matchesItem(Item item, XPathContext context) {
047: return true;
048: }
049:
050: public ItemType getSuperType(TypeHierarchy th) {
051: return null;
052: }
053:
054: /**
055: * Get the primitive item type corresponding to this item type. For item(),
056: * this is Type.ITEM. For node(), it is Type.NODE. For specific node kinds,
057: * it is the value representing the node kind, for example Type.ELEMENT.
058: * For anyAtomicValue it is Type.ATOMIC_VALUE. For numeric it is Type.NUMBER.
059: * For other atomic types it is the primitive type as defined in XML Schema,
060: * except that INTEGER is considered to be a primitive type.
061: */
062:
063: public ItemType getPrimitiveItemType() {
064: return this ;
065: }
066:
067: public int getPrimitiveType() {
068: return Type.ITEM;
069: }
070:
071: public AtomicType getAtomizedItemType() {
072: return Type.ANY_ATOMIC_TYPE;
073: }
074:
075: public String toString() {
076: return "item()";
077: }
078:
079: public String toString(NamePool pool) {
080: return "item()";
081: }
082:
083: /**
084: * Returns a hash code value for the object.
085: */
086:
087: public int hashCode() {
088: return "AnyItemType".hashCode();
089: }
090:
091: }
092:
093: //
094: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
095: // you may not use this file except in compliance with the License. You may obtain a copy of the
096: // License at http://www.mozilla.org/MPL/
097: //
098: // Software distributed under the License is distributed on an "AS IS" basis,
099: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
100: // See the License for the specific language governing rights and limitations under the License.
101: //
102: // The Original Code is: all this file.
103: //
104: // The Initial Developer of the Original Code is Michael H. Kay.
105: //
106: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
107: //
108: // Contributor(s): none.
109: //
|