Package net.sf.saxon.type

Examples of net.sf.saxon.type.ItemType


        compiledTemplate.setStackFrameMap(stackFrameMap);
        compiledTemplate.setExecutable(getExecutable());
        compiledTemplate.setSystemId(getSystemId());
        compiledTemplate.setLineNumber(getLineNumber());

        ItemType contextItemType = Type.ITEM_TYPE;
        if (getObjectFingerprint() == -1) {
            // the template can't be called by name, so the context item must match the match pattern
            contextItemType = match.getNodeTest();
        }
View Full Code Here


     * @return the item type that should be used for arithmetic between
     *     operands of the two specified item types
     */

    public static ItemType promote(ItemType v1, ItemType v2) {
        ItemType t1 = (Type.isSubType(v1, Type.NUMBER_TYPE) ? v1 : Type.DOUBLE_TYPE);
        ItemType t2 = (Type.isSubType(v2, Type.NUMBER_TYPE) ? v2 : Type.DOUBLE_TYPE);

        if (t1 == t2) return t1;

        if (t1 == Type.DOUBLE_TYPE || t2 == Type.DOUBLE_TYPE) {
            return Type.DOUBLE_TYPE;
View Full Code Here

     * @return the conversion preference. A high number indicates a low preference;
     * -1 indicates that conversion is not possible.
     */

    private int getConversionPreference(Expression arg, Class required) {
        ItemType itemType = arg.getItemType();
        int cardinality = arg.getCardinality();
        if (required == Object.class) {
            return 100;
        } else if (Cardinality.allowsMany(cardinality)) {
            if (required.isAssignableFrom(SequenceIterator.class)) {
                return 20;
            } else if (required.isAssignableFrom(SequenceValue.class)) {
                return 21;
            } else if (Collection.class.isAssignableFrom(required)) {
                return 22;
            } else if (required.isAssignableFrom(NodeList.class)) {
                return 23;
            } else if (required.isArray()) {
                return 24;
                // sort out at run-time whether the component type of the array is actually suitable
            } else {
                return -1;    // conversion not possible
            }
        } else {
            if (Type.isNodeType(itemType)) {
                if (required.isAssignableFrom(NodeInfo.class)) {
                    return 20;
                } else if (required.isAssignableFrom(DocumentInfo.class)) {
                    return 21;
                } else if (required.isAssignableFrom(Node.class)) {
                    return 22;
                } else if (required.isAssignableFrom(NodeList.class)) {
                    return 23;
                } else {
                    return -1;
                }
            } else {
                int primitiveType = itemType.getPrimitiveType();
                return atomicConversionPreference(primitiveType, required);
            }
        }
    }
View Full Code Here

     * Get the item type of the items returned by evaluating this instruction
     * @return the static item type of the instruction
     */

    public ItemType getItemType() {
        ItemType type = actions[0].getItemType();
        for (int i=1; i<actions.length; i++) {
            type = Type.getCommonSuperType(type, actions[i].getItemType());
        }
        return type;
    }
View Full Code Here

        var.setNameCode(nameCode);
        var.setRequiredType(requiredType);
        if (requiredType == SequenceType.ANY_SEQUENCE && !isParameter) {
            // no type was declared; try to deduce a type from the value
            try {
                ItemType itemType = value.getItemType();
                int cardinality = value.getCardinality();
                requiredType = new SequenceType(itemType, cardinality);
                var.setRequiredType(requiredType);
            } catch (Exception err) {
                // exceptions can happen because references to variables and functions are still unbound
View Full Code Here

    public ItemType getItemType() {
        switch (operation) {
            case COUNT:
                return super.getItemType();
            case SUM: {
                ItemType base = argument[0].getItemType();
                if (base == Type.UNTYPED_ATOMIC_TYPE) {
                    base = Type.DOUBLE_TYPE;
                }
                if (Cardinality.allowsZero(argument[0].getCardinality())) {
                    if (argument.length == 1) {
                        return Type.getCommonSuperType(base, Type.INTEGER_TYPE);
                    } else {
                        return Type.getCommonSuperType(base, argument[1].getItemType());
                    }
                } else {
                    return base;
                }
            }
            case AVG: {
                ItemType base = argument[0].getItemType();
                if (base == Type.UNTYPED_ATOMIC_TYPE) {
                    return Type.DOUBLE_TYPE;
                } else if (base.getPrimitiveType() == Type.INTEGER) {
                    return Type.DECIMAL_TYPE;
                } else {
                    return base;
                }
            }
View Full Code Here

        }
        Value val = globalParameters.get(fingerprint);
        if (val==null) {
            return false;
        }
        ItemType reqItemType = binding.getRequiredType().getPrimaryType();
        if (val instanceof AtomicValue && reqItemType instanceof AtomicType) {
            // If the parameter is an atomic value, typically a string supplied on
            // the command line, we attempt to convert it to the required type. This
            // will not always succeed.
            val = ((AtomicValue)val).convert((AtomicType)reqItemType, null);
View Full Code Here

                DynamicError err = new DynamicError("Static error in XPath expression supplied to saxon:evaluate: " +
                        e.getMessage().trim());
                err.setXPathContext(context);
                throw err;
            }
            ItemType contextItemType = Type.ITEM_TYPE;
            expr = expr.analyze(staticContext, contextItemType);
            pexpr.stackFrameMap = staticContext.getStackFrameMap();
            ExpressionTool.allocateSlots(expr, pexpr.stackFrameMap.getNumberOfVariables(), pexpr.stackFrameMap);
            pexpr.expression = expr;
View Full Code Here

    /**
    * Determine the item type of the value returned by the function
    */

    public ItemType getItemType() {
        ItemType type = details.itemType;
        if (type == StandardFunction.SAME_AS_FIRST_ARGUMENT) {
            if (argument.length > 0) {
                return argument[0].getItemType();
            } else {
                return AnyItemType.getInstance();
View Full Code Here

    * Return the type of the supplied value: "sequence", "string", "number", "boolean",
    * "external". (EXSLT spec not yet modified to cater for XPath 2.0 data model)
    */

    public static String objectType(XPathContext context, Value value) {
        ItemType type = value.getItemType();
        if (Type.isSubType(type, AnyNodeTest.getInstance())) {
            return "node-set";
        } else if (Type.isSubType(type, Type.STRING_TYPE)) {
            return "string";
        } else if (Type.isSubType(type, Type.NUMBER_TYPE)) {
            return "number";
        } else if (Type.isSubType(type, Type.BOOLEAN_TYPE)) {
            return "boolean";
        } else {
            return type.toString(context.getController().getNamePool());
        }
    }
View Full Code Here

TOP

Related Classes of net.sf.saxon.type.ItemType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.