| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.expr.instruct; |
| 9 |
|
| 10 |
import net.sf.saxon.Configuration; |
| 11 |
import net.sf.saxon.Controller; |
| 12 |
import net.sf.saxon.expr.Component; |
| 13 |
import net.sf.saxon.expr.XPathContext; |
| 14 |
import net.sf.saxon.om.GroundedValue; |
| 15 |
import net.sf.saxon.om.Item; |
| 16 |
import net.sf.saxon.trans.XPathException; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
public final class GlobalParam extends GlobalVariable { |
| 28 |
|
| 29 |
private boolean implicitlyRequired; |
| 30 |
|
| 31 |
public GlobalParam() { |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public void setImplicitlyRequiredParam(boolean requiredParam) { |
| 41 |
this.implicitlyRequired = requiredParam; |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
public boolean isImplicitlyRequiredParam() { |
| 50 |
return this.implicitlyRequired; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
@Override |
| 57 |
public GroundedValue<?> evaluateVariable(XPathContext context, Component target) throws XPathException { |
| 58 |
Controller controller = context.getController(); |
| 59 |
assert controller != null; |
| 60 |
Bindery b = controller.getBindery(getPackageData()); |
| 61 |
GroundedValue<?> val = b.getGlobalVariableValue(this); |
| 62 |
if (val != null) { |
| 63 |
if (val instanceof Bindery.FailureValue) { |
| 64 |
throw ((Bindery.FailureValue)val).getObject(); |
| 65 |
} |
| 66 |
return val; |
| 67 |
} |
| 68 |
val = controller.getConvertedParameter(getVariableQName(), getRequiredType(), context); |
| 69 |
if (val != null) { |
| 70 |
return b.saveGlobalVariableValue(this, val); |
| 71 |
} |
| 72 |
if (isRequiredParam()) { |
| 73 |
XPathException e = new XPathException("No value supplied for required parameter $" + |
| 74 |
getVariableQName().getDisplayName()); |
| 75 |
e.setXPathContext(context); |
| 76 |
e.setLocator(this); |
| 77 |
e.setErrorCode(getPackageData().getHostLanguage() == Configuration.XSLT ? "XTDE0050" : "XPDY0002"); |
| 78 |
throw e; |
| 79 |
} else if (isImplicitlyRequiredParam()) { |
| 80 |
XPathException e = new XPathException("A value must be supplied for parameter $" + |
| 81 |
getVariableQName().getDisplayName() + |
| 82 |
" because there is no default value for the required type"); |
| 83 |
e.setXPathContext(context); |
| 84 |
e.setLocator(this); |
| 85 |
e.setErrorCode("XTDE0700"); |
| 86 |
throw e; |
| 87 |
} |
| 88 |
|
| 89 |
return actuallyEvaluate(context, target); |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
@Override |
| 97 |
public GroundedValue<?> evaluateVariable(XPathContext context) throws XPathException { |
| 98 |
return evaluateVariable(context, null); |
| 99 |
} |
| 100 |
|
| 101 |
@Override |
| 102 |
protected String getFlags() { |
| 103 |
String f = super.getFlags(); |
| 104 |
if (isImplicitlyRequiredParam()) { |
| 105 |
f += "i"; |
| 106 |
} |
| 107 |
return f; |
| 108 |
} |
| 109 |
} |
| 110 |
|