|
|
|
package com.jayway.jsonpath.internal;
|
|
|
|
|
|
|
|
import com.jayway.jsonpath.Configuration;
|
|
|
|
import com.jayway.jsonpath.internal.compiler.EvaluationContextImpl;
|
|
|
|
import com.jayway.jsonpath.internal.compiler.PathToken;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
public class CompiledPath implements Path {
|
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(CompiledPath.class);
|
|
|
|
|
|
|
|
private final PathToken root;
|
|
|
|
|
|
|
|
private final boolean isRootPath;
|
|
|
|
|
|
|
|
|
|
|
|
public CompiledPath(PathToken root, boolean isRootPath) {
|
|
|
|
this.root = root;
|
|
|
|
this.isRootPath = isRootPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isRootPath() {
|
|
|
|
return isRootPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EvaluationContext evaluate(Object document, Object rootDocument, Configuration configuration) {
|
|
|
|
if (logger.isDebugEnabled()) {
|
|
|
|
logger.debug("Evaluating path: {}", toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
EvaluationContextImpl ctx = new EvaluationContextImpl(this, rootDocument, configuration);
|
|
|
|
root.evaluate("", document, ctx);
|
|
|
|
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isDefinite() {
|
|
|
|
return root.isPathDefinite();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return root.toString();
|
|
|
|
}
|
|
|
|
}
|