if (path.isFunctionPath() && path.next() instanceof ScanPathToken) { PathToken token = path; PathToken prior = null; path.setTail(prior); parameter.setType(ParamType.PATH); ((FunctionPathToken)token).setParameters(Arrays.asList(parameter)); RootPathToken functionRoot = new RootPathToken('$'); functionRoot.setTail(token); functionRoot.setNext(token);
@Override public PathTokenAppender appendPathToken(PathToken next) { append(next); return this; } };
@Override public EvaluationContext evaluate(Object document, Object rootDocument, Configuration configuration, boolean forUpdate) { if (logger.isDebugEnabled()) { logger.debug("Evaluating path: {}", toString()); } EvaluationContextImpl ctx = new EvaluationContextImpl(this, rootDocument, configuration, forUpdate); try { PathRef op = ctx.forUpdate() ? PathRef.createRoot(rootDocument) : PathRef.NO_OP; root.evaluate("", op, document, ctx); } catch (EvaluationAbortException abort) {} return ctx; }
@Override public String toString() { return root.toString(); } }
@Override public boolean isDefinite() { return root.isPathDefinite(); }
private Path compile() { RootPathToken root = readContextToken(); return new CompiledPath(root, root.getPathFragment().equals("$")); }
public static RootPathToken createRootPathToken(char token) { return new RootPathToken(token); }
@Override public boolean isFunctionPath() { return root.isFunctionPath(); }
private RootPathToken readContextToken() { readWhitespace(); if (!isPathContext(path.currentChar())) { throw new InvalidPathException("Path must start with '$' or '@'"); } RootPathToken pathToken = PathTokenFactory.createRootPathToken(path.currentChar()); if (path.currentIsTail()) { return pathToken; } path.incrementPosition(1); if(path.currentChar() != PERIOD && path.currentChar() != OPEN_SQUARE_BRACKET){ fail("Illegal character at position " + path.position() + " expected '.' or '['"); } PathTokenAppender appender = pathToken.getPathTokenAppender(); readNextToken(appender); return pathToken; }
@Override public String toString() { return root.toString(); } }
@Override public boolean isDefinite() { return root.isPathDefinite(); }
private Path compile() { RootPathToken root = readContextToken(); return new CompiledPath(root, root.getPathFragment().equals("$")); }
public static RootPathToken createRootPathToken(char token) { return new RootPathToken(token); }
@Override public boolean isFunctionPath() { return root.isFunctionPath(); }
private RootPathToken readContextToken() { readWhitespace(); if (!isPathContext(path.currentChar())) { throw new InvalidPathException("Path must start with '$' or '@'"); } RootPathToken pathToken = PathTokenFactory.createRootPathToken(path.currentChar()); if (path.currentIsTail()) { return pathToken; } path.incrementPosition(1); if(path.currentChar() != PERIOD && path.currentChar() != OPEN_SQUARE_BRACKET){ fail("Illegal character at position " + path.position() + " expected '.' or '["); } PathTokenAppender appender = pathToken.getPathTokenAppender(); readNextToken(appender); return pathToken; }
if (path.isFunctionPath() && path.next() instanceof ScanPathToken) { PathToken token = path; PathToken prior = null; path.setTail(prior); parameter.setType(ParamType.PATH); ((FunctionPathToken)token).setParameters(Arrays.asList(parameter)); RootPathToken functionRoot = new RootPathToken('$'); functionRoot.setTail(token); functionRoot.setNext(token);
@Override public void evaluate(String currentPath, PathRef pathRef, Object model, EvaluationContextImpl ctx) { if (isLeaf()) { PathRef op = ctx.forUpdate() ? pathRef : PathRef.NO_OP; if (ctx.configuration().getComputeRoot()) { // KR ok to overwrite root here ctx.setRoot(model); ctx.setParent(model); } ctx.addResult(rootToken, op, model); } else { if (ctx.configuration().getComputeRoot()) { Object root; if (null != ctx.getRoot()) { root = ctx.getRoot(); } else { root = ctx.configuration().jsonProvider().copy(model); } ctx.setRoot(root); ctx.setParent(root); } next().evaluate(rootToken, pathRef, model, ctx); } }
@Override public EvaluationContext evaluate(Object document, Object rootDocument, Configuration configuration, boolean forUpdate) { if (logger.isDebugEnabled()) { logger.debug("Evaluating path: {}", toString()); } EvaluationContextImpl ctx = new EvaluationContextImpl(this, rootDocument, configuration, forUpdate); try { PathRef op = ctx.forUpdate() ? PathRef.createRoot(rootDocument) : PathRef.NO_OP; root.evaluate("", op, document, ctx); } catch (EvaluationAbortException abort){}; return ctx; }