@Override public boolean matches(Object model) { return predicatePathToken.accept(model, ctx.rootDocument(), ctx.configuration(), ctx); } }
public void addResult(String path, PathRef operation, Object model) { if(forUpdate) { updateOperations.add(operation); } configuration.jsonProvider().setArrayIndex(valueResult, resultIndex, model); configuration.jsonProvider().setArrayIndex(pathResult, resultIndex, path); resultIndex++; if(!configuration().getEvaluationListeners().isEmpty()){ int idx = resultIndex - 1; for (EvaluationListener listener : configuration().getEvaluationListeners()) { EvaluationListener.EvaluationContinuation continuation = listener.resultFound(new FoundResultImpl(idx, path, model)); if(EvaluationListener.EvaluationContinuation.ABORT == continuation){ throw ABORT_EVALUATION; } } } }
@Override public void evaluate(String currentPath, PathRef parent, Object model, EvaluationContextImpl ctx) { // Can't assert it in ctor because isLeaf() could be changed later on. assert onlyOneIsTrueNonThrow(singlePropertyCase(), multiPropertyMergeCase(), multiPropertyIterationCase()); if (!ctx.jsonProvider().isMap(model)) { if (! isUpstreamDefinite()) { return; } else { String m = model == null ? "null" : model.getClass().getName(); throw new PathNotFoundException(String.format( "Expected to find an object with property %s in path %s but found '%s'. " + "This is not a json object according to the JsonProvider: '%s'.", getPathFragment(), currentPath, m, ctx.configuration().jsonProvider().getClass().getName())); } } if (singlePropertyCase() || multiPropertyMergeCase()) { handleObjectProperty(currentPath, model, ctx, properties); return; } assert multiPropertyIterationCase(); final List<String> currentlyHandledProperty = new ArrayList<String>(1); currentlyHandledProperty.add(null); for (final String property : properties) { currentlyHandledProperty.set(0, property); handleObjectProperty(currentPath, model, ctx, currentlyHandledProperty); } }
private void evaluateParameters(String currentPath, PathRef parent, Object model, EvaluationContextImpl ctx) { if (null != functionParams) { for (Parameter param : functionParams) { if (!param.hasEvaluated()) { switch (param.getType()) { case PATH: param.setLateBinding(new PathLateBindingValue(param.getPath(), ctx.rootDocument(), ctx.configuration())); param.setEvaluated(true); break; case JSON: param.setLateBinding(new JsonLateBindingValue(ctx.configuration().jsonProvider(), param)); param.setEvaluated(true); break; } } } } }
@Override public void evaluate(String currentPath, PathRef ref, Object model, EvaluationContextImpl ctx) { if (ctx.jsonProvider().isMap(model)) { if (accept(model, ctx.rootDocument(), ctx.configuration(), ctx)) { PathRef op = ctx.forUpdate() ? ref : PathRef.NO_OP; if (isLeaf()) { ctx.addResult(currentPath, op, model); } else { next().evaluate(currentPath, op, model, ctx); } } } else if (ctx.jsonProvider().isArray(model)){ int idx = 0; Iterable<?> objects = ctx.jsonProvider().toIterable(model); for (Object idxModel : objects) { if (accept(idxModel, ctx.rootDocument(), ctx.configuration(), ctx)) { handleArrayIndex(idx, currentPath, model, ctx); } idx++; } } else { if (isUpstreamDefinite()) { throw new InvalidPathException(format("Filter: %s can not be applied to primitives. Current context is: %s", toString(), model)); } } }
@Override public boolean matches(Object model) { return predicatePathToken.accept(model, ctx.rootDocument(), ctx.configuration(), ctx); } }
public void addResult(String path, PathRef operation, Object model) { if(forUpdate) { updateOperations.add(operation); } configuration.jsonProvider().setArrayIndex(valueResult, resultIndex, model); configuration.jsonProvider().setArrayIndex(pathResult, resultIndex, path); resultIndex++; if(!configuration().getEvaluationListeners().isEmpty()){ int idx = resultIndex - 1; for (EvaluationListener listener : configuration().getEvaluationListeners()) { EvaluationListener.EvaluationContinuation continuation = listener.resultFound(new FoundResultImpl(idx, path, model)); if(EvaluationListener.EvaluationContinuation.ABORT == continuation){ throw ABORT_EVALUATION; } } } }
@Override public void evaluate(String currentPath, PathRef parent, Object model, EvaluationContextImpl ctx) { // Can't assert it in ctor because isLeaf() could be changed later on. assert onlyOneIsTrueNonThrow(singlePropertyCase(), multiPropertyMergeCase(), multiPropertyIterationCase()); if (!ctx.jsonProvider().isMap(model)) { if (! isUpstreamDefinite()) { return; } else { String m = model == null ? "null" : model.getClass().getName(); throw new PathNotFoundException(String.format( "Expected to find an object with property %s in path %s but found '%s'. " + "This is not a json object according to the JsonProvider: '%s'.", getPathFragment(), currentPath, m, ctx.configuration().jsonProvider().getClass().getName())); } } if (singlePropertyCase() || multiPropertyMergeCase()) { handleObjectProperty(currentPath, model, ctx, properties); return; } assert multiPropertyIterationCase(); final List<String> currentlyHandledProperty = new ArrayList<String>(1); currentlyHandledProperty.add(null); for (final String property : properties) { currentlyHandledProperty.set(0, property); handleObjectProperty(currentPath, model, ctx, currentlyHandledProperty); } }
private void evaluateParameters(String currentPath, PathRef parent, Object model, EvaluationContextImpl ctx) { if (null != functionParams) { for (Parameter param : functionParams) { if (!param.hasEvaluated()) { switch (param.getType()) { case PATH: param.setLateBinding(new PathLateBindingValue(param.getPath(), ctx.rootDocument(), ctx.configuration())); param.setEvaluated(true); break; case JSON: param.setLateBinding(new JsonLateBindingValue(ctx.configuration().jsonProvider(), param)); param.setEvaluated(true); break; } } } } }
@Override public void evaluate(String currentPath, PathRef ref, Object model, EvaluationContextImpl ctx) { if (ctx.jsonProvider().isMap(model)) { if (accept(model, ctx.rootDocument(), ctx.configuration(), ctx)) { PathRef op = ctx.forUpdate() ? ref : PathRef.NO_OP; if (isLeaf()) { ctx.addResult(currentPath, op, model); } else { next().evaluate(currentPath, op, model, ctx); } } } else if (ctx.jsonProvider().isArray(model)){ int idx = 0; Iterable<?> objects = ctx.jsonProvider().toIterable(model); for (Object idxModel : objects) { if (accept(idxModel, ctx.rootDocument(), ctx.configuration(), ctx)) { handleArrayIndex(idx, currentPath, model, ctx); } idx++; } } else { if (isUpstreamDefinite()) { throw new InvalidPathException(format("Filter: %s can not be applied to primitives. Current context is: %s", toString(), model)); } } }
@Override public boolean matches(Object model) { return predicatePathToken.accept(model, ctx.rootDocument(), ctx.configuration(), ctx); } }
public void addResult(String path, PathRef operation, Object model) { if(forUpdate) { updateOperations.add(operation); } configuration.jsonProvider().setArrayIndex(valueResult, resultIndex, model); configuration.jsonProvider().setArrayIndex(pathResult, resultIndex, path); resultIndex++; if(!configuration().getEvaluationListeners().isEmpty()){ int idx = resultIndex - 1; for (EvaluationListener listener : configuration().getEvaluationListeners()) { EvaluationListener.EvaluationContinuation continuation = listener.resultFound(new FoundResultImpl(idx, path, model)); if(EvaluationListener.EvaluationContinuation.ABORT == continuation){ throw ABORT_EVALUATION; } } } }
if (isLeaf()) { if (ctx.configuration().getComputeRoot()) { checkAndFillArrayElements(ctx, ctx.getParent(), evalHit, effectiveIndex); if (ctx.configuration().getComputeRoot()) { curr = (ctx.configuration().jsonProvider().length(old) > effectiveIndex ? ctx.configuration().jsonProvider().getArrayIndex(old, effectiveIndex) : null); if (null == curr) { curr = ctx.configuration().jsonProvider().createMap(); checkAndFillArrayElements(ctx, old, curr, effectiveIndex); if (ctx.configuration().getComputeRoot()) { if (old != curr) { if (ctx.configuration().jsonProvider().isMap(curr) && ctx.configuration().jsonProvider().length(curr) == 0) { ctx.configuration().jsonProvider().removeProperty(old, new Integer(effectiveIndex)); } else if (ctx.configuration().jsonProvider().isArray(curr) && ctx.configuration().jsonProvider().length(curr) == 0) { ctx.configuration().jsonProvider().removeProperty(old, new Integer(effectiveIndex));
@Override public void evaluate(String currentPath, PathRef parent, Object model, EvaluationContextImpl ctx) { // Can't assert it in ctor because isLeaf() could be changed later on. assert onlyOneIsTrueNonThrow(singlePropertyCase(), multiPropertyMergeCase(), multiPropertyIterationCase()); if (!ctx.jsonProvider().isMap(model)) { if (! isUpstreamDefinite()) { return; } else { String m = model == null ? "null" : model.getClass().getName(); throw new PathNotFoundException(String.format( "Expected to find an object with property %s in path %s but found '%s'. " + "This is not a json object according to the JsonProvider: '%s'.", getPathFragment(), currentPath, m, ctx.configuration().jsonProvider().getClass().getName())); } } if (singlePropertyCase() || multiPropertyMergeCase()) { handleObjectProperty(currentPath, model, ctx, properties); return; } assert multiPropertyIterationCase(); final List<String> currentlyHandledProperty = new ArrayList<String>(1); currentlyHandledProperty.add(null); for (final String property : properties) { currentlyHandledProperty.set(0, property); handleObjectProperty(currentPath, model, ctx, currentlyHandledProperty); } }
private void evaluateParameters(String currentPath, PathRef parent, Object model, EvaluationContextImpl ctx) { if (null != functionParams) { for (Parameter param : functionParams) { if (!param.hasEvaluated()) { switch (param.getType()) { case PATH: param.setLateBinding(new PathLateBindingValue(param.getPath(), ctx.rootDocument(), ctx.configuration())); param.setEvaluated(true); break; case JSON: param.setLateBinding(new JsonLateBindingValue(ctx.configuration().jsonProvider(), param)); param.setEvaluated(true); break; } } } } }
@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); } }
if (ctx.configuration().getComputeRoot()) { if (null == ctx.configuration().jsonProvider().getProperty(ctx.getParent(), property)) { ctx.configuration().jsonProvider().setProperty(ctx.getParent(), property, propertyVal); if (ctx.configuration().getComputeRoot()) { curr = ctx.configuration().jsonProvider().getProperty(prev, property); if (null == curr) { if (ctx.configuration().jsonProvider().isMap(propertyVal)) { curr = ctx.configuration().jsonProvider().createMap(); } else if (ctx.configuration().jsonProvider().isArray(propertyVal)) { curr = ctx.configuration().jsonProvider().createArray(); } else { throw new IllegalArgumentException("unknown type"); ctx.configuration().jsonProvider().setProperty(prev, property, curr); if (ctx.configuration().getComputeRoot()) { if (prev != curr) { if (ctx.configuration().jsonProvider().isMap(curr) || ctx.configuration().jsonProvider().isArray(curr)) { if (ctx.configuration().jsonProvider().length(curr) == 0) { ctx.configuration().jsonProvider().removeProperty(prev, property); if (ctx.configuration().getComputeRoot()) { if (null == ctx.configuration().jsonProvider().getProperty(ctx.getParent(), property)) { ctx.configuration().jsonProvider().setProperty(ctx.getParent(), property, propertyVal);
@Override public void evaluate(String currentPath, PathRef ref, Object model, EvaluationContextImpl ctx) { if (ctx.jsonProvider().isMap(model)) { if (accept(model, ctx.rootDocument(), ctx.configuration(), ctx)) { PathRef op = ctx.forUpdate() ? ref : PathRef.NO_OP; if (isLeaf()) { ctx.addResult(currentPath, op, model); } else { next().evaluate(currentPath, op, model, ctx); } } } else if (ctx.jsonProvider().isArray(model)){ int idx = 0; Iterable<?> objects = ctx.jsonProvider().toIterable(model); for (Object idxModel : objects) { if (accept(idxModel, ctx.rootDocument(), ctx.configuration(), ctx)) { handleArrayIndex(idx, currentPath, model, ctx); } idx++; } } else { if (isUpstreamDefinite()) { throw new InvalidPathException(format("Filter: %s can not be applied to primitives. Current context is: %s", toString(), model)); } } }