All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.saxon.instruct.GlobalVariable Maven / Gradle / Ivy

Go to download

Provides a basic XSLT 2.0 and XQuery 1.0 processor (W3C Recommendations, January 2007). Command line interfaces and implementations of several Java APIs (DOM, XPath, s9api) are also included.

The newest version!
package net.sf.saxon.instruct;
import net.sf.saxon.Configuration;
import net.sf.saxon.Controller;
import net.sf.saxon.query.XQueryFunctionLibrary;
import net.sf.saxon.query.XQueryFunction;
import net.sf.saxon.expr.*;
import net.sf.saxon.om.SingletonIterator;
import net.sf.saxon.om.UnfailingIterator;
import net.sf.saxon.om.ValueRepresentation;
import net.sf.saxon.trace.InstructionInfo;
import net.sf.saxon.trans.XPathException;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

/**
* A compiled global variable in a stylesheet or query. 
*/ public class GlobalVariable extends GeneralVariable implements Container { private Executable executable; private SlotManager stackFrameMap = null; private int hostLanguage; /** * Create a global variable */ public GlobalVariable(){} /** * Get the executable containing this global variable * @return the containing executable */ public Executable getExecutable() { return executable; } /** * Set the containing executable * @param executable the executable that contains this global variable */ public void setExecutable(Executable executable) { this.executable = executable; } /** * Set the host language for this declaration * @param language the host language (for example XSLT, XQuery) */ public void setHostLanguage(int language) { hostLanguage = language; } /** * Get the host language for this declaration * @return the host language (for example XSLT, XQuery) */ public int getHostLanguage() { return hostLanguage; } /** * The expression that initializes a global variable may itself use local variables. * In this case a stack frame needs to be allocated while evaluating the global variable * @param map The stack frame map for local variables used while evaluating this global * variable. */ public void setContainsLocals(SlotManager map) { this.stackFrameMap = map; } /** * Is this a global variable? * @return true (yes, it is a global variable) */ public boolean isGlobal() { return true; } /** * Check for cycles in this variable definition * @param referees the calls leading up to this one; it's an error if this variable is on the * stack, because that means it calls itself directly or indirectly. The stack may contain * variable definitions (GlobalVariable objects) and user-defined functions (UserFunction objects). * It will never contain the same object more than once. * @param globalFunctionLibrary the library containing all global functions */ public void lookForCycles(Stack referees, XQueryFunctionLibrary globalFunctionLibrary) throws XPathException { if (referees.contains(this)) { int s = referees.indexOf(this); referees.push(this); String message = "Circular definition of global variable. $" + getVariableQName().getDisplayName(); for (int i = s; i < referees.size() - 1; i++) { if (i != s) { message += ", which"; } if (referees.get(i + 1) instanceof GlobalVariable) { GlobalVariable next = (GlobalVariable)referees.get(i + 1); message += " uses $" + next.getVariableQName().getDisplayName(); } else if (referees.get(i + 1) instanceof XQueryFunction) { XQueryFunction next = (XQueryFunction)referees.get(i + 1); message += " calls " + next.getFunctionName().getDisplayName() + "#" + next.getNumberOfArguments() + "()"; } } message += '.'; XPathException err = new XPathException(message); err.setErrorCode("XQST0054"); err.setIsStaticError(true); err.setLocator(this); throw err; } if (select != null) { referees.push(this); List list = new ArrayList(10); ExpressionTool.gatherReferencedVariables(select, list); for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy