Package net.sf.saxon.instruct

Examples of net.sf.saxon.instruct.GlobalVariable


        }
        HashMap map = executable.getCompiledGlobalVariables();
        if (map != null) {
            Iterator iter = map.values().iterator();
            while (iter.hasNext()) {
                GlobalVariable var = (GlobalVariable)iter.next();
                Expression select = var.getSelectExpression();
                select.addToPathMap(pathMap, null);
            }
        }
        return pathMap;
    }
View Full Code Here


        }
        HashMap map = executable.getCompiledGlobalVariables();
        if (map != null) {
            Iterator iter = map.values().iterator();
            while (iter.hasNext()) {
                GlobalVariable var = (GlobalVariable)iter.next();
                Expression select = var.getSelectExpression();
                if (select != null && ExpressionTool.dependsOnFocus(select)) {
                    return true;
                }
            }
        }
View Full Code Here

                throw new XPathException("The supplied context item does not match the required context item type");
            }
            // Now check it against the required type defined in the query prolog
            StructuredQName varQName = executable.getInitialContextItemVariableName();
            if (varQName != null) {
                GlobalVariable var = executable.getGlobalVariable(varQName);
                if (var == null) {
                    throw new IllegalStateException("Context item variable not found in executable");
                }
                controller.setParameter(varQName, contextItem);
                try {
                    // do early evaluation to force the type-checking of the context item
                    controller.getBindery().useGlobalParameter(
                            varQName, var.getSlotNumber(), var.getRequiredType(), context);
                } catch (XPathException err) {
                    err.maybeSetLocation(var);
                    if (!err.hasBeenReported()) {
                        try {
                            controller.getErrorListener().fatalError(err);
                        } catch (TransformerException e) {
                            // no action
                        }
                    }
                    throw err;
                }
            }
            UnfailingIterator single = SingletonIterator.makeIterator(contextItem);
            single.next();
            context.setCurrentIterator(single);
            controller.setInitialContextItem(contextItem);
        } else {
            // there might be a default value for the context item
            StructuredQName varQName = executable.getInitialContextItemVariableName();
            if (varQName != null) {
                GlobalVariable var = executable.getGlobalVariable(varQName);
                if (var == null) {
                    throw new IllegalStateException("Context item variable not found in executable");
                }
                try {
                    // do early evaluation to force the type-checking of the context item
                    controller.getBindery().useGlobalParameter(varQName, var.getSlotNumber(), var.getRequiredType(), context);
                } catch (XPathException err) {
                    err.maybeSetLocation(var);
                    if (!err.hasBeenReported()) {
                        try {
                            controller.getErrorListener().fatalError(err);
                        } catch (TransformerException e) {
                            // no action
                        }
                    }
                    throw err;
                }
                ValueRepresentation val = var.getSelectValue(context);
                contextItem = Value.asItem(val);
                UnfailingIterator single = SingletonIterator.makeIterator(contextItem);
                single.next();
                context.setCurrentIterator(single);
                controller.setInitialContextItem(contextItem);
View Full Code Here

        }

        if (!redundant) {
            GeneralVariable inst;
            if (global) {
                inst = new GlobalVariable();
                ((GlobalVariable)inst).setExecutable(getExecutable());
                if (select != null) {
                    select.setContainer(((GlobalVariable)inst));
                }
                initializeInstruction(exec, inst);
View Full Code Here

     */

    public GlobalVariable compile(Executable exec, int slot) throws XPathException {

        TypeHierarchy th = exec.getConfiguration().getTypeHierarchy();
        GlobalVariable var;
        if (isParameter) {
            var = new GlobalParam();
            var.setExecutable(exec);
            var.setRequiredParam(value==null);
        } else {
            var = new GlobalVariable();
            var.setExecutable(exec);
        }

        var.setSelectExpression(value);
        var.setRequiredType(requiredType);
        var.setVariableQName(variableName);
        var.setSlotNumber(slot);

        int loc = exec.getLocationMap().allocateLocationId(systemId, lineNumber);
        var.setLocationId(loc);
        var.setContainer(var);

        final SequenceType type = getRequiredType();
        Iterator iter = references.iterator();
        while (iter.hasNext()) {
            BindingReference ref = (BindingReference)iter.next();
            ref.fixup(var);
            Value constantValue = null;
            int properties = 0;
            Expression select = value;
            if (select instanceof Literal && !isParameter) {
                // we can't rely on the constant value because it hasn't yet been type-checked,
                // which could change it (eg by numeric promotion). Rather than attempt all the type-checking
                // now, we do a quick check. See test bug64
                int relation = th.relationship(select.getItemType(th), type.getPrimaryType());
                if (relation == TypeHierarchy.SAME_TYPE || relation == TypeHierarchy.SUBSUMED_BY) {
                    constantValue = ((Literal)select).getValue();
                }
            }
            if (select != null) {
                properties = select.getSpecialProperties();
            }
            properties |= StaticProperty.NON_CREATIVE;
                // a variable reference is non-creative even if its initializer is creative
            ref.setStaticType(type, constantValue, properties);
        }
        exec.registerGlobalVariable(var);
        var.setReferenceCount(10); // TODO: temporary!
        compiledVar = var;
        return var;
    }
View Full Code Here

     * @param visitor an expression visitor
     * @throws XPathException if compile-time errors are found.
     */

    public void typeCheck(ExpressionVisitor visitor) throws XPathException {
        GlobalVariable var = getCompiledVariable();
        Expression value = var.getSelectExpression();
        if (value != null) {
            value.checkForUpdatingSubexpressions();
            if (value.isUpdatingExpression()) {
                throw new XPathException(
                        "Initializing expression for global variable must not be an updating expression", "XUST0001");
            }
            value.setContainer(var);
            RoleLocator role = new RoleLocator(
                    RoleLocator.VARIABLE, var.getVariableQName(), 0);
            Expression value2 = TypeChecker.strictTypeCheck(
                    visitor.typeCheck(visitor.simplify(value), AnyItemType.getInstance()),
                    var.getRequiredType(), role, visitor.getStaticContext());
            value2 = value2.optimize(visitor, AnyItemType.getInstance());
            var.setSelectExpression(value2);
            value2.setContainer(var);
            // the value expression may declare local variables
            SlotManager map = visitor.getConfiguration().makeSlotManager();
            int slots = ExpressionTool.allocateSlots(value2, 0, map);
            if (slots > 0) {
                var.setContainsLocals(map);
            }

            if (var.getRequiredType() == SequenceType.ANY_SEQUENCE && !(var instanceof GlobalParam)) {
                // no type was declared; try to deduce a type from the value
                try {
                    final TypeHierarchy th = visitor.getConfiguration().getTypeHierarchy();
                    final ItemType itemType = value.getItemType(th);
                    final int cardinality = value.getCardinality();
                    var.setRequiredType(SequenceType.makeSequenceType(itemType, cardinality));
                    Value constantValue = null;
                    if (value2 instanceof Literal) {
                        constantValue = ((Literal)value2).getValue();
                    }
                    for (Iterator iter = references.iterator(); iter.hasNext(); ) {
View Full Code Here

            return EMPTY_QNAME_ARRAY;
        } else {
            HashSet params = new HashSet(vars.size());
            Iterator iter = vars.values().iterator();
            while (iter.hasNext()) {
                GlobalVariable var = (GlobalVariable)iter.next();
                if (var instanceof GlobalParam) {
                    params.add(var.getVariableQName());
                }
            }
            QName[] qnames = new QName[params.size()];
            int q=0;
            for (Iterator it=params.iterator(); it.hasNext();) {
View Full Code Here

        checkNotClosed();
        checkNotNull(name);
        StructuredQName qn = new StructuredQName(
                name.getPrefix(), name.getNamespaceURI(), name.getLocalPart());
        HashMap vars = expression.getExecutable().getCompiledGlobalVariables();
        GlobalVariable var = (vars == null ? null : (GlobalVariable)vars.get(qn));
        if (var == null) {
            throw new XQException("Variable " + name + " is not declared");
        }
        return new SaxonXQSequenceType(var.getRequiredType(), connection.getConfiguration());
    }
View Full Code Here

    protected boolean externalVariableExists(QName name) {
        StructuredQName qn = new StructuredQName(
                name.getPrefix(), name.getNamespaceURI(), name.getLocalPart());
        HashMap vars = expression.getExecutable().getCompiledGlobalVariables();
        GlobalVariable var = (vars == null ? null : (GlobalVariable)vars.get(qn));
        return var != null && var instanceof GlobalParam;
    }
View Full Code Here

        }

        if (!redundant) {
            GeneralVariable inst;
            if (global) {
                inst = new GlobalVariable();
                ((GlobalVariable)inst).setExecutable(getExecutable());
                if (select instanceof ComputedExpression) {
                    ((ComputedExpression)select).setParentExpression(inst);
                }
            } else {
View Full Code Here

TOP

Related Classes of net.sf.saxon.instruct.GlobalVariable

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.