1 package net.sf.saxon.instruct; 2 import net.sf.saxon.Controller; 3 import net.sf.saxon.Configuration; 4 import net.sf.saxon.expr.ErrorExpression; 5 import net.sf.saxon.expr.XPathContext; 6 import net.sf.saxon.om.ValueRepresentation; 7 import net.sf.saxon.style.StandardNames; 8 import net.sf.saxon.trans.DynamicError; 9 import net.sf.saxon.trans.XPathException; 10 11 19 20 public final class GlobalParam extends GlobalVariable { 21 22 25 26 public int getInstructionNameCode() { 27 return StandardNames.XSL_PARAM; 28 } 29 30 33 34 public ValueRepresentation evaluateVariable(XPathContext context) throws XPathException { 35 Controller controller = context.getController(); 36 Bindery b = controller.getBindery(); 37 boolean wasSupplied = b.useGlobalParameter(getVariableFingerprint(), this, context); 38 39 ValueRepresentation val = b.getGlobalVariableValue(this); 40 if (wasSupplied || val!=null) { 41 return val; 42 } else { 43 if (isRequiredParam()) { 44 DynamicError e = new DynamicError("No value supplied for required parameter $" + 45 context.getController().getNamePool().getDisplayName(getVariableFingerprint())); 46 e.setXPathContext(context); 47 e.setLocator(getSourceLocator()); 48 e.setErrorCode("XTDE0050"); 49 throw e; 50 } 51 52 56 try { 57 b.setExecuting(this, true); 58 ValueRepresentation value = getSelectValue(context); 59 b.defineGlobalVariable(this, value); 60 b.setExecuting(this, false); 61 return value; 62 63 } catch (XPathException err) { 64 b.setExecuting(this, false); 65 if (err instanceof XPathException.Circularity) { 66 DynamicError e = new DynamicError("Circular definition of parameter " + getVariableName()); 67 e.setXPathContext(context); 68 int lang = context.getController().getExecutable().getHostLanguage(); 69 e.setErrorCode(lang == Configuration.XQUERY ? "XQST0054" : "XTDE0640"); 70 select = new ErrorExpression(e); 72 throw e; 73 } else { 74 throw err; 75 } 76 } 77 } 78 } 79 } 80 81 | Popular Tags |