/** * Get the return type, given knowledge of the actual arguments * @param args the actual arguments supplied * @return the best available item type that the function will return */ public ItemType getResultItemType(Expression[] args) { if ((details.properties & BuiltInFunctionSet.AS_ARG0) != 0) { return args[0].getItemType(); } else if ((details.properties & BuiltInFunctionSet.AS_PRIM_ARG0) != 0) { return args[0].getItemType().getPrimitiveItemType(); } else { return details.itemType; } }
/** * Allow the function to create an optimized call based on the values of the actual arguments * * @param visitor the expression visitor * @param contextInfo information about the context item * @param arguments the supplied arguments to the function call. Note: modifying the contents * of this array should not be attempted, it is likely to have no effect. * @return either a function call on this function, or an expression that delivers * the same result, or null indicating that no optimization has taken place * @throws XPathException if an error is detected */ @Override public Expression makeOptimizedFunctionCall(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo, Expression... arguments) throws XPathException { if (arguments[0].getItemType().getPrimitiveItemType() == BuiltInAtomicType.INTEGER) { return Literal.makeLiteral(BooleanValue.TRUE); } return null; }
/** * Get the return type, given knowledge of the actual arguments * @param args the actual arguments supplied * @return the best available item type that the function will return */ public ItemType getResultItemType(Expression[] args) { if ((details.properties & BuiltInFunctionSet.AS_ARG0) != 0) { return args[0].getItemType(); } else if ((details.properties & BuiltInFunctionSet.AS_PRIM_ARG0) != 0) { return args[0].getItemType().getPrimitiveItemType(); } else { return details.itemType; } }
/** * Allow the function to create an optimized call based on the values of the actual arguments * * @param visitor the expression visitor * @param contextInfo information about the context item * @param arguments the supplied arguments to the function call. Note: modifying the contents * of this array should not be attempted, it is likely to have no effect. * @return either a function call on this function, or an expression that delivers * the same result, or null indicating that no optimization has taken place * @throws XPathException if an error is detected */ @Override public Expression makeOptimizedFunctionCall(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo, Expression... arguments) throws XPathException { if (arguments[0].getItemType().getPrimitiveItemType() == BuiltInAtomicType.INTEGER) { return Literal.makeLiteral(BooleanValue.TRUE); } return null; }
public ItemType getResultItemType(Expression[] args) { TypeHierarchy th = getRetainedStaticContext().getConfiguration().getTypeHierarchy(); ItemType base = Atomizer.getAtomizedItemType(args[0], false, th); if (base.equals(BuiltInAtomicType.UNTYPED_ATOMIC)) { base = BuiltInAtomicType.DOUBLE; } return base.getPrimitiveItemType(); }
public ItemType getResultItemType(Expression[] args) { TypeHierarchy th = getRetainedStaticContext().getConfiguration().getTypeHierarchy(); ItemType base = Atomizer.getAtomizedItemType(args[0], false, th); if (base.equals(BuiltInAtomicType.UNTYPED_ATOMIC)) { base = BuiltInAtomicType.DOUBLE; } return base.getPrimitiveItemType(); }
/** * Determine the data type of the expression, if this is known statically */ public ItemType getItemType(TypeHierarchy th) { if (calculator == null) { return BuiltInAtomicType.ANY_ATOMIC; // type is not known statically } else { ItemType t1 = operand0.getItemType(th); if (!(t1 instanceof AtomicType)) { t1 = t1.getAtomizedItemType(); } ItemType t2 = operand1.getItemType(th); if (!(t2 instanceof AtomicType)) { t2 = t2.getAtomizedItemType(); } return calculator.getResultType((AtomicType) t1.getPrimitiveItemType(), (AtomicType) t2.getPrimitiveItemType()); } }
/** * Determine the data type of the expression, if this is known statically */ public ItemType getItemType(TypeHierarchy th) { if (calculator == null) { return BuiltInAtomicType.ANY_ATOMIC; // type is not known statically } else { ItemType t1 = operand0.getItemType(th); if (!(t1 instanceof AtomicType)) { t1 = t1.getAtomizedItemType(); } ItemType t2 = operand1.getItemType(th); if (!(t2 instanceof AtomicType)) { t2 = t2.getAtomizedItemType(); } return calculator.getResultType((AtomicType) t1.getPrimitiveItemType(), (AtomicType) t2.getPrimitiveItemType()); } }
/** * Get the primitive item type corresponding to this item type. For item(), * this is Type.ITEM. For node(), it is Type.NODE. For specific node kinds, * it is the value representing the node kind, for example Type.ELEMENT. * For anyAtomicValue it is Type.ATOMIC_VALUE. For numeric it is Type.NUMBER. * For other atomic types it is the primitive type as defined in XML Schema, * except that INTEGER is considered to be a primitive type. */ /*@NotNull*/ public BuiltInAtomicType getPrimitiveItemType() { if (isPrimitiveType()) { return this; } else { ItemType s = (ItemType) getBaseType(); assert s != null; if (s.isPlainType()) { return (BuiltInAtomicType)s.getPrimitiveItemType(); } else { return this; } } }
/** * Get the primitive item type corresponding to this item type. For item(), * this is Type.ITEM. For node(), it is Type.NODE. For specific node kinds, * it is the value representing the node kind, for example Type.ELEMENT. * For anyAtomicValue it is Type.ATOMIC_VALUE. For numeric it is Type.NUMBER. * For other atomic types it is the primitive type as defined in XML Schema, * except that INTEGER is considered to be a primitive type. */ public ItemType getPrimitiveItemType() { if (isPrimitiveType()) { return this; } else { ItemType s = (ItemType)getBaseType(); if (s.isAtomicType()) { return s.getPrimitiveItemType(); } else { return this; } } }
/** * Get the primitive item type corresponding to this item type. For item(), * this is Type.ITEM. For node(), it is Type.NODE. For specific node kinds, * it is the value representing the node kind, for example Type.ELEMENT. * For anyAtomicValue it is Type.ATOMIC_VALUE. For numeric it is Type.NUMBER. * For other atomic types it is the primitive type as defined in XML Schema, * except that INTEGER is considered to be a primitive type. */ public ItemType getPrimitiveItemType() { if (isPrimitiveType()) { return this; } else { ItemType s = (ItemType)getBaseType(); if (s.isAtomicType()) { return s.getPrimitiveItemType(); } else { return this; } } }
/** * Get the primitive item type corresponding to this item type. For item(), * this is Type.ITEM. For node(), it is Type.NODE. For specific node kinds, * it is the value representing the node kind, for example Type.ELEMENT. * For anyAtomicValue it is Type.ATOMIC_VALUE. For numeric it is Type.NUMBER. * For other atomic types it is the primitive type as defined in XML Schema, * except that INTEGER is considered to be a primitive type. */ /*@NotNull*/ public BuiltInAtomicType getPrimitiveItemType() { if (isPrimitiveType()) { return this; } else { ItemType s = (ItemType) getBaseType(); assert s != null; if (s.isPlainType()) { return (BuiltInAtomicType)s.getPrimitiveItemType(); } else { return this; } } }
/** * Determine the data type of the expression, if this is known statically */ /*@NotNull*/ public PlainType getItemType() { if (calculator == null) { return BuiltInAtomicType.ANY_ATOMIC; // type is not known statically } else { ItemType t1 = getLhsExpression().getItemType(); if (!(t1 instanceof AtomicType)) { t1 = t1.getAtomizedItemType(); } ItemType t2 = getRhsExpression().getItemType(); if (!(t2 instanceof AtomicType)) { t2 = t2.getAtomizedItemType(); } return calculator.getResultType((AtomicType) t1.getPrimitiveItemType(), (AtomicType) t2.getPrimitiveItemType()); } }
/** * Determine the data type of the expression, if this is known statically */ /*@NotNull*/ public PlainType getItemType() { if (calculator == null) { return BuiltInAtomicType.ANY_ATOMIC; // type is not known statically } else { ItemType t1 = getLhsExpression().getItemType(); if (!(t1 instanceof AtomicType)) { t1 = t1.getAtomizedItemType(); } ItemType t2 = getRhsExpression().getItemType(); if (!(t2 instanceof AtomicType)) { t2 = t2.getAtomizedItemType(); } return calculator.getResultType((AtomicType) t1.getPrimitiveItemType(), (AtomicType) t2.getPrimitiveItemType()); } }
/** * A step equivalent to the XPath "cast as" operator: the supplied item is atomized * if necessary, and the resulting atomic values are cast to the required type */ public static Step<XdmAtomicValue> castAs(ItemType type) { if (!ItemType.ANY_ATOMIC_VALUE.subsumes(type)) { throw new IllegalArgumentException("Target of castAs must be an atomic type"); } final net.sf.saxon.type.ItemType tType = type.getUnderlyingItemType().getPrimitiveItemType(); final ConversionRules rules = type.getConversionRules(); return atomize().then(new Step<XdmAtomicValue>() { public Stream<? extends XdmAtomicValue> apply(XdmItem xdmItem) { try { AtomicValue source = ((XdmAtomicValue)xdmItem).getUnderlyingValue(); Converter converter = rules.getConverter(source.getItemType(), (AtomicType)tType); AtomicValue result = converter.convert(source).asAtomic(); return Stream.of((XdmAtomicValue) XdmValue.wrap(result)); } catch (ValidationException e) { throw new SaxonApiUncheckedException(new SaxonApiException(e)); } } }); }
/** * A step equivalent to the XPath "cast as" operator: the supplied item is atomized * if necessary, and the resulting atomic values are cast to the required type */ public static Step<XdmAtomicValue> castAs(ItemType type) { if (!ItemType.ANY_ATOMIC_VALUE.subsumes(type)) { throw new IllegalArgumentException("Target of castAs must be an atomic type"); } final net.sf.saxon.type.ItemType tType = type.getUnderlyingItemType().getPrimitiveItemType(); final ConversionRules rules = type.getConversionRules(); return atomize().then(new Step<XdmAtomicValue>() { public Stream<? extends XdmAtomicValue> apply(XdmItem xdmItem) { try { AtomicValue source = ((XdmAtomicValue)xdmItem).getUnderlyingValue(); Converter converter = rules.getConverter(source.getItemType(), (AtomicType)tType); AtomicValue result = converter.convert(source).asAtomic(); return Stream.of((XdmAtomicValue) XdmValue.wrap(result)); } catch (ValidationException e) { throw new SaxonApiUncheckedException(new SaxonApiException(e)); } } }); }
public ItemType getResultItemType(Expression[] args) { TypeHierarchy th = getRetainedStaticContext().getConfiguration().getTypeHierarchy(); ItemType base = Atomizer.getAtomizedItemType(args[0], false, th); if (base.equals(BuiltInAtomicType.UNTYPED_ATOMIC)) { base = BuiltInAtomicType.DOUBLE; } if (Cardinality.allowsZero(args[0].getCardinality())) { if (getArity() == 1) { return Type.getCommonSuperType(base, BuiltInAtomicType.INTEGER, th); } else { return Type.getCommonSuperType(base, args[1].getItemType(), th); } } else { return base.getPrimitiveItemType(); } }
public ItemType getResultItemType(Expression[] args) { TypeHierarchy th = getRetainedStaticContext().getConfiguration().getTypeHierarchy(); ItemType base = Atomizer.getAtomizedItemType(args[0], false, th); if (base.equals(BuiltInAtomicType.UNTYPED_ATOMIC)) { base = BuiltInAtomicType.DOUBLE; } if (Cardinality.allowsZero(args[0].getCardinality())) { if (getArity() == 1) { return Type.getCommonSuperType(base, BuiltInAtomicType.INTEGER, th); } else { return Type.getCommonSuperType(base, args[1].getItemType(), th); } } else { return base.getPrimitiveItemType(); } }
@Override public Expression makeOptimizedFunctionCall(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo, Expression... arguments) throws XPathException { // test for a singleton: this often happens after (A<B) is rewritten as (min(A) lt max(B)) int card = arguments[0].getCardinality(); if (!Cardinality.allowsMany(card)) { ItemType it = arguments[0].getItemType().getPrimitiveItemType(); if (it instanceof BuiltInAtomicType && ((BuiltInAtomicType)it).isOrdered(false)) { TypeHierarchy th = visitor.getConfiguration().getTypeHierarchy(); if (th.relationship(it, BuiltInAtomicType.UNTYPED_ATOMIC) != TypeHierarchy.DISJOINT) { return UntypedSequenceConverter.makeUntypedSequenceConverter( visitor.getConfiguration(), arguments[0], BuiltInAtomicType.DOUBLE).typeCheck(visitor, contextInfo); } else { return arguments[0]; } } } return null; }
@Override public Expression makeOptimizedFunctionCall(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo, Expression... arguments) throws XPathException { // test for a singleton: this often happens after (A<B) is rewritten as (min(A) lt max(B)) int card = arguments[0].getCardinality(); if (!Cardinality.allowsMany(card)) { ItemType it = arguments[0].getItemType().getPrimitiveItemType(); if (it instanceof BuiltInAtomicType && ((BuiltInAtomicType)it).isOrdered(false)) { TypeHierarchy th = visitor.getConfiguration().getTypeHierarchy(); if (th.relationship(it, BuiltInAtomicType.UNTYPED_ATOMIC) != TypeHierarchy.DISJOINT) { return UntypedSequenceConverter.makeUntypedSequenceConverter( visitor.getConfiguration(), arguments[0], BuiltInAtomicType.DOUBLE).typeCheck(visitor, contextInfo); } else { return arguments[0]; } } } return null; }