Package net.sf.saxon.instruct

Examples of net.sf.saxon.instruct.GlobalVariable


            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


    public XQSequenceType getStaticVariableType(QName name) throws XQException {
        checkNotClosed();
        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

     */

    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.setHostLanguage(Configuration.XQUERY);
        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);

        Iterator iter = references.iterator();
        while (iter.hasNext()) {
            BindingReference binding = (BindingReference)iter.next();
            fixupReference(binding, th);
            //binding.setStaticType(requiredType, null, 0);
            binding.fixup(var);
        }
        exec.registerGlobalVariable(var);
//        int referenceCount = RangeVariable.getReferenceCount(references, true);
//        if (referenceCount < 10) {
//            // allow for the fact that the references may be in functions that are executed repeatedly
//            referenceCount = 10;
//        }
//        var.setReferenceCount(referenceCount);
        var.setReferenceCount(10); // TODO: temporary!
        compiledVar = var;
        return var;
    }
View Full Code Here

     */

    // TODO: watch bug 5224: is the context item defined for use in the body expression?

    public void typeCheck(ExpressionVisitor visitor) throws XPathException {
        GlobalVariable var = getCompiledVariable();
        Expression value = var.getSelectExpression();
        if (value != null) {
            value.setContainer(var);
            RoleLocator role = new RoleLocator(
                    RoleLocator.VARIABLE, var.getVariableQName(), 0, null);
            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

        }

        if (!redundant) {
            GeneralVariable inst;
            if (global) {
                inst = new GlobalVariable();
                ((GlobalVariable)inst).setExecutable(getExecutable());
                ((GlobalVariable)inst).setHostLanguage(Configuration.XSLT);
                if (select != null) {
                    select.setContainer(((GlobalVariable)inst));
                }
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 && (select.getDependencies() & StaticProperty.DEPENDS_ON_FOCUS) != 0) {
                    return true;
                }
            }
        }
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();
                select.addToPathMap(pathMap, null);
            }
        }
        return pathMap;
    }
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.