// fixme! - hook for debugger here /ljo
final Sequence sequence = null;
final XQuery xqueryService = evalContext.getBroker().getXQueryService();
final XQueryContext innerContext;
if (contextInit != null) {
// eval-with-context: initialize a new context
innerContext = xqueryService.newContext(evalContext.getAccessContext());
initContextSequence = initContext(contextInit.getNode(), innerContext);
} else {
// use the existing outer context
// TODO: check if copying the static context would be sufficient???
innerContext = evalContext.copyContext();
innerContext.setShared(true);
//innerContext = context;
}
//set module load path
if(Type.subTypeOf(expr.getType(), Type.ANY_URI)) {
String uri = null;
final Object key = querySource.getKey();
if(key instanceof XmldbURI) {
uri = XmldbURI.EMBEDDED_SERVER_URI.append(((XmldbURI)key).removeLastSegment()).toString();
// } else if (key instanceof URL) {
// TODO: uri = ((URL) key).getParent()
} else if (key instanceof String && querySource instanceof FileSource) {
uri = ((FileSource) querySource).getFile().getParent();
}
if (uri != null) {
innerContext.setModuleLoadPath(uri);
}
}
//bind external vars?
if(isCalledAs("eval") && getArgumentCount() == 3) {
if(!args[2].isEmpty()) {
final Sequence externalVars = args[2];
for(int i = 0; i < externalVars.getItemCount(); i++) {
final Item varName = externalVars.itemAt(i);
if(varName.getType() == Type.QNAME) {
final Item varValue = externalVars.itemAt(++i);
innerContext.declareVariable(((QNameValue)varName).getQName(), varValue);
}
}
}
}