in src/main/java/org/apache/commons/jexl3/internal/Engine.java [326:381]
public Engine(final JexlBuilder conf) {
// options:
this.options = conf.options().copy();
this.strict = options.isStrict();
this.safe = options.isSafe();
this.silent = options.isSilent();
this.cancellable = option(conf.cancellable(), !silent && strict);
options.setCancellable(cancellable);
this.debug = option(conf.debug(), true);
this.collectMode = conf.collectMode();
this.stackOverflow = conf.stackOverflow() > 0? conf.stackOverflow() : Integer.MAX_VALUE;
// core properties:
final JexlUberspect uber = conf.uberspect() == null
? getUberspect(conf.logger(), conf.strategy(), conf.permissions())
: conf.uberspect();
final ClassLoader loader = conf.loader();
if (loader != null) {
uber.setClassLoader(loader);
}
final JexlSandbox sandbox = conf.sandbox();
if (sandbox == null) {
this.uberspect = uber;
} else {
this.uberspect = new SandboxUberspect(uber, sandbox);
}
this.logger = conf.logger() == null ? LogFactory.getLog(JexlEngine.class) : conf.logger();
this.arithmetic = conf.arithmetic() == null ? new JexlArithmetic(this.strict) : conf.arithmetic();
options.setMathContext(arithmetic.getMathContext());
options.setMathScale(arithmetic.getMathScale());
options.setStrictArithmetic(arithmetic.isStrict());
final Map<String, Object> ns = conf.namespaces();
this.functions = ns == null || ns.isEmpty()? Collections.emptyMap() : ns; // should we make a copy?
this.classNameSolver = new FqcnResolver(uberspect, conf.imports());
// parsing & features:
final JexlFeatures features = conf.features() == null ? DEFAULT_FEATURES : conf.features();
Predicate<String> nsTest = features.namespaceTest();
final Set<String> nsNames = functions.keySet();
if (!nsNames.isEmpty()) {
nsTest = nsTest == JexlFeatures.TEST_STR_FALSE ?nsNames::contains : nsTest.or(nsNames::contains);
}
this.expressionFeatures = new JexlFeatures(features).script(false).namespaceTest(nsTest);
this.scriptFeatures = new JexlFeatures(features).script(true).namespaceTest(nsTest);
this.charset = conf.charset();
// caching:
final IntFunction<JexlCache<?, ?>> factory = conf.cacheFactory();
this.cacheFactory = factory == null ? SoftCache::new : factory;
this.cache = (JexlCache<Source, ASTJexlScript>) (conf.cache() > 0 ? cacheFactory.apply(conf.cache()) : null);
this.cacheThreshold = conf.cacheThreshold();
if (uberspect == null) {
throw new IllegalArgumentException("uberspect cannot be null");
}
this.parserFactory = conf.parserFactory() == null ?
() -> new Parser(new StringProvider(";"))
: conf.parserFactory();
this.parser = parserFactory.get();
}