PreparedExpression pexpr = new PreparedExpression();
String exprText;
if (operation == EVALUATE_NODE) {
NodeInfo node = (NodeInfo)argument[0].evaluateItem(context);
IndependentContext env = staticContext.copy();
pexpr.expStaticContext = env;
env.setBaseURI(node.getBaseURI());
env.setFunctionLibrary(getExecutable().getFunctionLibrary());
env.setNamespaces(node);
exprText = node.getStringValue();
UnfailingIterator single = SingletonIterator.makeIterator(node);
single.next();
context.setCurrentIterator(single);
Expression expr;
try {
expr = ExpressionTool.make(exprText, env, 0, Token.EOF, 1, false);
expr.setContainer(env);
} catch (XPathException e) {
String name = getFunctionName().getDisplayName();
XPathException err = new XPathException("Static error in XPath expression supplied to " + name + ": " +
e.getMessage().trim());
err.setXPathContext(context);
throw err;
}
ItemType contextItemType = Type.ITEM_TYPE;
ExpressionVisitor visitor = ExpressionVisitor.make(env);
visitor.setExecutable(env.getExecutable());
expr = visitor.typeCheck(expr, contextItemType);
pexpr.stackFrameMap = env.getStackFrameMap();
ExpressionTool.allocateSlots(expr, pexpr.stackFrameMap.getNumberOfVariables(), pexpr.stackFrameMap);
pexpr.expression = expr;
expr.setContainer(env);
return pexpr;
}
AtomicValue exprSource = (AtomicValue)argument[0].evaluateItem(context);
exprText = exprSource.getStringValue();
IndependentContext env = staticContext.copy();
env.setFunctionLibrary(getExecutable().getFunctionLibrary());
pexpr.expStaticContext = env;
pexpr.variables = new XPathVariable[10];
for (int i=1; i<10; i++) {
pexpr.variables[i-1] = env.declareVariable("", "p"+i);
}
Expression expr;
try {
expr = ExpressionTool.make(exprText, env, 0, Token.EOF, 1, false);
} catch (XPathException e) {
String name = getFunctionName().getDisplayName();
XPathException err = new XPathException("Static error in XPath expression supplied to " + name + ": " +
e.getMessage().trim());
err.setXPathContext(context);
throw err;
}
ItemType contextItemType = Type.ITEM_TYPE;
ExpressionVisitor visitor = ExpressionVisitor.make(env);
visitor.setExecutable(env.getExecutable());
expr = visitor.typeCheck(expr, contextItemType);
pexpr.stackFrameMap = env.getStackFrameMap();
ExpressionTool.allocateSlots(expr, pexpr.stackFrameMap.getNumberOfVariables(), pexpr.stackFrameMap);
pexpr.expression = expr;
expr.setContainer(env);
return pexpr;