@Override public net.sf.saxon.type.ItemType getUnderlyingItemType() { return NumericType.getInstance(); } };
/** * Return a string representation of this ItemType suitable for use in stylesheet * export files. This differs from the result of toString() in that it will not contain * any references to anonymous types. Note that it may also use the Saxon extended syntax * for union types and tuple types. The default implementation returns the result of * calling {@code toString()}. * * @return the string representation as an instance of the XPath SequenceType construct */ @Override public String toExportString() { return toString(); }
@Override public net.sf.saxon.type.ItemType getUnderlyingItemType() { return NumericType.getInstance(); } };
/** * Return a string representation of this ItemType suitable for use in stylesheet * export files. This differs from the result of toString() in that it will not contain * any references to anonymous types. Note that it may also use the Saxon extended syntax * for union types and tuple types. The default implementation returns the result of * calling {@code toString()}. * * @return the string representation as an instance of the XPath SequenceType construct */ @Override public String toExportString() { return toString(); }
/** * Ask whether a built-in type is a numeric type (integer, float, double) * @return true if the type is numeric */ public boolean isNumericType() { ItemType p = getPrimitiveItemType(); return p == NumericType.getInstance() || p == DECIMAL || p == DOUBLE || p == FLOAT || p == INTEGER; }
/** * Ask whether a built-in type is a numeric type (integer, float, double) * @return true if the type is numeric */ public boolean isNumericType() { ItemType p = getPrimitiveItemType(); return p == NumericType.getInstance() || p == DECIMAL || p == DOUBLE || p == FLOAT || p == INTEGER; }
/** * Determine whether an expression, when used as a filter, is potentially positional; * that is, where it either contains a call on position() or last(), or where it is capable of returning * a numeric result. * * @param exp the expression to be examined * @param th the type hierarchy cache * @return true if the expression depends on position() or last() explicitly or implicitly */ public static boolean isPositionalFilter(Expression exp, TypeHierarchy th) { ItemType type = exp.getItemType(); if (type.equals(BuiltInAtomicType.BOOLEAN)) { // common case, get it out of the way quickly return isExplicitlyPositional(exp); } return type.equals(BuiltInAtomicType.ANY_ATOMIC) || type instanceof AnyItemType || type.equals(BuiltInAtomicType.INTEGER) || type.equals(NumericType.getInstance()) || th.isSubType(type, NumericType.getInstance()) || isExplicitlyPositional(exp); }
/** * Determine whether an expression, when used as a filter, is potentially positional; * that is, where it either contains a call on position() or last(), or where it is capable of returning * a numeric result. * * @param exp the expression to be examined * @param th the type hierarchy cache * @return true if the expression depends on position() or last() explicitly or implicitly */ public static boolean isPositionalFilter(Expression exp, TypeHierarchy th) { ItemType type = exp.getItemType(); if (type.equals(BuiltInAtomicType.BOOLEAN)) { // common case, get it out of the way quickly return isExplicitlyPositional(exp); } return type.equals(BuiltInAtomicType.ANY_ATOMIC) || type instanceof AnyItemType || type.equals(BuiltInAtomicType.INTEGER) || type.equals(NumericType.getInstance()) || th.isSubType(type, NumericType.getInstance()) || isExplicitlyPositional(exp); }
/** * Obtain (that is, create or get) an itemType that matches all items whose primitive type is one * of the types present in this UType. * @return a corresponding ItemType */ public ItemType toItemType() { Set<PrimitiveUType> p = decompose(); if (p.isEmpty()) { return ErrorType.getInstance(); } else if (p.size() == 1) { return p.toArray(new PrimitiveUType[1])[0].toItemType(); } else if (ANY_NODE.subsumes(this)) { return AnyNodeTest.getInstance(); } else if (equals(NUMERIC)) { return NumericType.getInstance(); } else if (ANY_ATOMIC.subsumes(this)) { return BuiltInAtomicType.ANY_ATOMIC; } else { return AnyItemType.getInstance(); } }
/** * Obtain (that is, create or get) an itemType that matches all items whose primitive type is one * of the types present in this UType. * @return a corresponding ItemType */ public ItemType toItemType() { Set<PrimitiveUType> p = decompose(); if (p.isEmpty()) { return ErrorType.getInstance(); } else if (p.size() == 1) { return p.toArray(new PrimitiveUType[1])[0].toItemType(); } else if (ANY_NODE.subsumes(this)) { return AnyNodeTest.getInstance(); } else if (equals(NUMERIC)) { return NumericType.getInstance(); } else if (ANY_ATOMIC.subsumes(this)) { return BuiltInAtomicType.ANY_ATOMIC; } else { return AnyItemType.getInstance(); } }
(th.isSubType(t2, NumericType.getInstance()) || th.isSubType(t1, NumericType.getInstance()))) { resultType = NumericType.getInstance();
(th.isSubType(t2, NumericType.getInstance()) || th.isSubType(t1, NumericType.getInstance()))) { resultType = NumericType.getInstance();
public Sequence<?> call(XPathContext context, Sequence[] arguments) throws XPathException { final TypeHierarchy th = context.getConfiguration().getTypeHierarchy(); Item value = arguments[0].head(); ItemType type = SequenceTool.getItemType(value, th); if (th.isSubType(type, AnyNodeTest.getInstance())) { return new StringValue("node-set"); } else if (th.isSubType(type, BuiltInAtomicType.STRING)) { return new StringValue("string"); } else if (th.isSubType(type, NumericType.getInstance())) { return new StringValue("number"); } else if (th.isSubType(type, BuiltInAtomicType.BOOLEAN)) { return new StringValue("boolean"); } else { return new StringValue(type.toString()); } } }
public Sequence<?> call(XPathContext context, Sequence[] arguments) throws XPathException { final TypeHierarchy th = context.getConfiguration().getTypeHierarchy(); Item value = arguments[0].head(); ItemType type = SequenceTool.getItemType(value, th); if (th.isSubType(type, AnyNodeTest.getInstance())) { return new StringValue("node-set"); } else if (th.isSubType(type, BuiltInAtomicType.STRING)) { return new StringValue("string"); } else if (th.isSubType(type, NumericType.getInstance())) { return new StringValue("number"); } else if (th.isSubType(type, BuiltInAtomicType.BOOLEAN)) { return new StringValue("boolean"); } else { return new StringValue(type.toString()); } } }
/** * Test whether a given expression is capable of returning a value that has an effective boolean * value. * * @param exp the given expression * @param th the type hierarchy cache * @return null if the expression is OK (optimistically), an exception object if not */ public static XPathException ebvError(Expression exp, TypeHierarchy th) { if (Cardinality.allowsZero(exp.getCardinality())) { return null; } ItemType t = exp.getItemType(); if (th.relationship(t, Type.NODE_TYPE) == TypeHierarchy.DISJOINT && th.relationship(t, BuiltInAtomicType.BOOLEAN) == TypeHierarchy.DISJOINT && th.relationship(t, BuiltInAtomicType.STRING) == TypeHierarchy.DISJOINT && th.relationship(t, BuiltInAtomicType.ANY_URI) == TypeHierarchy.DISJOINT && th.relationship(t, BuiltInAtomicType.UNTYPED_ATOMIC) == TypeHierarchy.DISJOINT && th.relationship(t, NumericType.getInstance()) == TypeHierarchy.DISJOINT && !(t instanceof JavaExternalObjectType)) { XPathException err = new XPathException( "Effective boolean value is defined only for sequences containing " + "booleans, strings, numbers, URIs, or nodes"); err.setErrorCode("FORG0006"); err.setIsTypeError(true); return err; } return null; }
/** * Test whether a given expression is capable of returning a value that has an effective boolean * value. * * @param exp the given expression * @param th the type hierarchy cache * @return null if the expression is OK (optimistically), an exception object if not */ public static XPathException ebvError(Expression exp, TypeHierarchy th) { if (Cardinality.allowsZero(exp.getCardinality())) { return null; } ItemType t = exp.getItemType(); if (th.relationship(t, Type.NODE_TYPE) == TypeHierarchy.DISJOINT && th.relationship(t, BuiltInAtomicType.BOOLEAN) == TypeHierarchy.DISJOINT && th.relationship(t, BuiltInAtomicType.STRING) == TypeHierarchy.DISJOINT && th.relationship(t, BuiltInAtomicType.ANY_URI) == TypeHierarchy.DISJOINT && th.relationship(t, BuiltInAtomicType.UNTYPED_ATOMIC) == TypeHierarchy.DISJOINT && th.relationship(t, NumericType.getInstance()) == TypeHierarchy.DISJOINT && !(t instanceof JavaExternalObjectType)) { XPathException err = new XPathException( "Effective boolean value is defined only for sequences containing " + "booleans, strings, numbers, URIs, or nodes"); err.setErrorCode("FORG0006"); err.setIsTypeError(true); return err; } return null; }
if (reqItemType.equals(NumericType.getInstance()) || reqItemType.equals(BuiltInAtomicType.DOUBLE) && !Cardinality.allowsMany(req.getCardinality()) && !th.isSubType(supplied.getItemType(), BuiltInAtomicType.DOUBLE)) {
if (reqItemType.equals(NumericType.getInstance()) || reqItemType.equals(BuiltInAtomicType.DOUBLE) && !Cardinality.allowsMany(req.getCardinality()) && !th.isSubType(supplied.getItemType(), BuiltInAtomicType.DOUBLE)) {
return NumericType.getInstance();
private void init() { // Test whether supplied argument is equal to an integer register("is-whole-number", 1, IsWholeNumberFn.class, BuiltInAtomicType.BOOLEAN, ONE, 0, 0) .arg(0, NumericType.getInstance(), OPT, EMPTY); // Evaluate the value of a try-catch variable such as $err:code register("dynamic-error-info", 1, DynamicErrorInfoFn.class, AnyItemType.getInstance(), STAR, 0, FOCUS | LATE | SIDE) .arg(0, BuiltInAtomicType.STRING, ONE, null); // saxon:apply is the same as fn:apply, but does not require the HOF feature register("apply", 2, ApplyFn.class, AnyItemType.getInstance(), STAR, 0, LATE) .arg(0, AnyFunctionType.getInstance(), ONE, null) .arg(1, ArrayItemType.ANY_ARRAY_TYPE, ONE, null); // Create a map according to the semantics of the XPath map constructor and XSLT xsl:map instruction register("create-map", 1, MapCreate.class, MapType.ANY_MAP_TYPE, ONE, 0, 0) .arg(0, MapType.ANY_MAP_TYPE, STAR, null); // Variant of the doc() function with an options parameter register("doc", 2, Doc_2.class, NodeKindTest.DOCUMENT, ONE, 0, LATE) .arg(0, BuiltInAtomicType.STRING, ONE, null) .arg(1, MapType.ANY_MAP_TYPE, ONE, EMPTY) .optionDetails(Doc_2.makeOptionsParameter()); // Function analogous to map:contains except in the way it handles untyped key values register("map-untyped-contains", 2, MapUntypedContains.class, BuiltInAtomicType.BOOLEAN, ONE, 0, 0) .arg(0, MapType.ANY_MAP_TYPE, STAR, null) .arg(1, BuiltInAtomicType.ANY_ATOMIC, ONE, null); }