本文整理汇总了Java中org.apache.commons.jexl3.JexlEngine类的典型用法代码示例。如果您正苦于以下问题:Java JexlEngine类的具体用法?Java JexlEngine怎么用?Java JexlEngine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JexlEngine类属于org.apache.commons.jexl3包,在下文中一共展示了JexlEngine类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getJexlEngine
import org.apache.commons.jexl3.JexlEngine; //导入依赖的package包/类
/**
* Get JexlEngine from ThreadLocal
* @return JexlEngine
*/
private static JexlEngine getJexlEngine() {
JexlEngine engine = threadLocalJexl.get();
if(engine == null) {
engine = new JexlBuilder()
.cache(512)
.silent(true)
.strict(true)
// debug is true by default an impact negatively performances
// by a factory of 10
// Use JexlInfo if necessary
.debug(false)
// see https://issues.apache.org/jira/browse/JEXL-186
.arithmetic(new JMeterArithmetic(true))
.create();
threadLocalJexl.set(engine);
}
return engine;
}
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:23,代码来源:Jexl3Function.java
示例2: getEngine
import org.apache.commons.jexl3.JexlEngine; //导入依赖的package包/类
private static JexlEngine getEngine() {
synchronized (LOG) {
if (JEXL_ENGINE == null) {
JEXL_ENGINE = new JexlBuilder().
uberspect(new ClassFreeUberspect()).
loader(new EmptyClassLoader()).
namespaces(Collections.<String, Object>singletonMap("syncope", new SyncopeJexlFunctions())).
cache(512).
silent(false).
strict(false).
create();
}
}
return JEXL_ENGINE;
}
开发者ID:apache,项目名称:syncope,代码行数:17,代码来源:JexlUtils.java
示例3: JexlRowFactory
import org.apache.commons.jexl3.JexlEngine; //导入依赖的package包/类
public JexlRowFactory(Map<String, String> customFields, JoinHandler joinHandler) {
this.joinHandler = joinHandler;
this.expressions = new HashMap<>();
Map<String, Object> ns = Maps.newHashMap();
ns.put("Json", JsonEncoder.class); // make method Json:stringify available in expressions
ns.put("Math", Math.class); // make all methods of Math available
ns.put("Integer", Integer.class); // make method Integer
JexlEngine jexl = new JexlBuilder().namespaces(ns).create();
StringBuilder result = new StringBuilder();
customFields.forEach((key, value) -> {
try {
expressions.put(key, jexl.createExpression(value));
result.append(" ").append(key).append(": ").append(value).append("\n");
} catch (Exception e) { // Catch the runtime exceptions
LOG.error("Could not compile expression '{}'", value);
LOG.error("Exception thrown", e);
}
});
this.stringRepresentation = result.toString();
}
开发者ID:HuygensING,项目名称:timbuctoo,代码行数:21,代码来源:JexlRowFactory.java
示例4: visit
import org.apache.commons.jexl3.JexlEngine; //导入依赖的package包/类
@Override
protected Object visit(ASTUnaryMinusNode node, Object data) {
JexlNode valNode = node.jjtGetChild(0);
Object val = valNode.jjtAccept(this, data);
try {
Object result = operators.tryOverload(node, JexlOperator.NEGATE, val);
if (result != JexlEngine.TRY_FAILED) {
return result;
}
Object number = arithmetic.negate(val);
// attempt to recoerce to literal class
if (valNode instanceof ASTNumberLiteral && number instanceof Number) {
number = arithmetic.narrowNumber((Number) number, ((ASTNumberLiteral) valNode).getLiteralClass());
}
return number;
} catch (ArithmeticException xrt) {
throw new JexlException(valNode, "- error", xrt);
}
}
开发者ID:apache,项目名称:commons-jexl,代码行数:20,代码来源:Interpreter.java
示例5: tryInvoke
import org.apache.commons.jexl3.JexlEngine; //导入依赖的package包/类
@Override
public Object tryInvoke(String name, Object obj, Object... args) {
MethodKey tkey = new MethodKey(name, args);
// let's assume that invocation will fly if the declaring class is the
// same and arguments have the same type
if (objectClass.equals(obj.getClass()) && tkey.equals(key)) {
try {
return invoke(obj, args);
} catch (InvocationTargetException xinvoke) {
return TRY_FAILED; // fail
} catch (IllegalAccessException xill) {
return TRY_FAILED;// fail
} catch (IllegalArgumentException xarg) {
return TRY_FAILED;// fail
}
}
return JexlEngine.TRY_FAILED;
}
开发者ID:apache,项目名称:commons-jexl,代码行数:19,代码来源:MethodExecutor.java
示例6: size
import org.apache.commons.jexl3.JexlEngine; //导入依赖的package包/类
/**
* Calculate the <code>size</code> of various types:
* Collection, Array, Map, String, and anything that has a int size() method.
* <p>Note that the result may not be an integer.
*
* @param node the node that gave the value to size
* @param object the object to get the size of.
* @return the evaluation result
*/
protected Object size(JexlNode node, Object object) {
if (object == null) {
return 0;
}
final JexlArithmetic arithmetic = interpreter.arithmetic;
final JexlUberspect uberspect = interpreter.uberspect;
Object result = Operators.this.tryOverload(node, JexlOperator.SIZE, object);
if (result != JexlEngine.TRY_FAILED) {
return result;
}
result = arithmetic.size(object);
if (result == null) {
// check if there is a size method on the object that returns an
// integer and if so, just use it
JexlMethod vm = uberspect.getMethod(object, "size", Interpreter.EMPTY_PARAMS);
if (vm != null && (Integer.TYPE.equals(vm.getReturnType()) || Integer.class.equals(vm.getReturnType()))) {
try {
result = (Integer) vm.invoke(object, Interpreter.EMPTY_PARAMS);
} catch (Exception xany) {
interpreter.operatorError(node, JexlOperator.SIZE, xany);
}
}
}
return result;
}
开发者ID:apache,项目名称:commons-jexl,代码行数:35,代码来源:Operators.java
示例7: testCtorBlack
import org.apache.commons.jexl3.JexlEngine; //导入依赖的package包/类
@Test
public void testCtorBlack() throws Exception {
String expr = "new('" + Foo.class.getName() + "', '42')";
JexlScript script = JEXL.createScript(expr);
Object result;
result = script.execute(null);
Assert.assertEquals("42", ((Foo) result).getName());
JexlSandbox sandbox = new JexlSandbox();
sandbox.black(Foo.class.getName()).execute("");
JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).create();
script = sjexl.createScript(expr);
try {
result = script.execute(null);
Assert.fail("ctor should not be accessible");
} catch (JexlException.Method xmethod) {
// ok, ctor should not have been accessible
LOGGER.info(xmethod.toString());
}
}
开发者ID:apache,项目名称:commons-jexl,代码行数:22,代码来源:SandboxTest.java
示例8: testMethodBlack
import org.apache.commons.jexl3.JexlEngine; //导入依赖的package包/类
@Test
public void testMethodBlack() throws Exception {
String expr = "foo.Quux()";
JexlScript script = JEXL.createScript(expr, "foo");
Foo foo = new Foo("42");
Object result;
result = script.execute(null, foo);
Assert.assertEquals(foo.Quux(), result);
JexlSandbox sandbox = new JexlSandbox();
sandbox.black(Foo.class.getName()).execute("Quux");
JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).create();
script = sjexl.createScript(expr, "foo");
try {
result = script.execute(null, foo);
Assert.fail("Quux should not be accessible");
} catch (JexlException.Method xmethod) {
// ok, Quux should not have been accessible
LOGGER.info(xmethod.toString());
}
}
开发者ID:apache,项目名称:commons-jexl,代码行数:23,代码来源:SandboxTest.java
示例9: testGetBlack
import org.apache.commons.jexl3.JexlEngine; //导入依赖的package包/类
@Test
public void testGetBlack() throws Exception {
String expr = "foo.alias";
JexlScript script = JEXL.createScript(expr, "foo");
Foo foo = new Foo("42");
Object result;
result = script.execute(null, foo);
Assert.assertEquals(foo.alias, result);
JexlSandbox sandbox = new JexlSandbox();
sandbox.black(Foo.class.getName()).read("alias");
JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).create();
script = sjexl.createScript(expr, "foo");
try {
result = script.execute(null, foo);
Assert.fail("alias should not be accessible");
} catch (JexlException.Property xvar) {
// ok, alias should not have been accessible
LOGGER.info(xvar.toString());
}
}
开发者ID:apache,项目名称:commons-jexl,代码行数:23,代码来源:SandboxTest.java
示例10: testSetBlack
import org.apache.commons.jexl3.JexlEngine; //导入依赖的package包/类
@Test
public void testSetBlack() throws Exception {
String expr = "foo.alias = $0";
JexlScript script = JEXL.createScript(expr, "foo", "$0");
Foo foo = new Foo("42");
Object result;
result = script.execute(null, foo, "43");
Assert.assertEquals("43", result);
JexlSandbox sandbox = new JexlSandbox();
sandbox.black(Foo.class.getName()).write("alias");
JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).create();
script = sjexl.createScript(expr, "foo", "$0");
try {
result = script.execute(null, foo, "43");
Assert.fail("alias should not be accessible");
} catch (JexlException.Property xvar) {
// ok, alias should not have been accessible
LOGGER.info(xvar.toString());
}
}
开发者ID:apache,项目名称:commons-jexl,代码行数:23,代码来源:SandboxTest.java
示例11: testCantSeeMe
import org.apache.commons.jexl3.JexlEngine; //导入依赖的package包/类
@Test
public void testCantSeeMe() throws Exception {
JexlContext jc = new MapContext();
String expr = "foo.doIt()";
JexlScript script;
Object result = null;
JexlSandbox sandbox = new JexlSandbox(false);
sandbox.white(Foo.class.getName());
JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).create();
jc.set("foo", new CantSeeMe());
script = sjexl.createScript(expr);
try {
result = script.execute(jc);
Assert.fail("should have failed, doIt()");
} catch (JexlException xany) {
//
}
jc.set("foo", new Foo("42"));
result = script.execute(jc);
Assert.assertEquals(42, ((Integer) result).intValue());
}
开发者ID:apache,项目名称:commons-jexl,代码行数:24,代码来源:SandboxTest.java
示例12: testGetWhite
import org.apache.commons.jexl3.JexlEngine; //导入依赖的package包/类
@Test
public void testGetWhite() throws Exception {
Foo foo = new Foo("42");
String expr = "foo.alias";
JexlScript script;
Object result;
JexlSandbox sandbox = new JexlSandbox();
sandbox.white(Foo.class.getName()).read("alias");
sandbox.get(Foo.class.getName()).read().alias("alias", "ALIAS");
JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).create();
script = sjexl.createScript(expr, "foo");
result = script.execute(null, foo);
Assert.assertEquals(foo.alias, result);
script = sjexl.createScript("foo.ALIAS", "foo");
result = script.execute(null, foo);
Assert.assertEquals(foo.alias, result);
}
开发者ID:apache,项目名称:commons-jexl,代码行数:21,代码来源:SandboxTest.java
示例13: testSetWhite
import org.apache.commons.jexl3.JexlEngine; //导入依赖的package包/类
@Test
public void testSetWhite() throws Exception {
Foo foo = new Foo("42");
String expr = "foo.alias = $0";
JexlScript script;
Object result;
JexlSandbox sandbox = new JexlSandbox();
sandbox.white(Foo.class.getName()).write("alias");
JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).create();
script = sjexl.createScript(expr, "foo", "$0");
result = script.execute(null, foo, "43");
Assert.assertEquals("43", result);
Assert.assertEquals("43", foo.alias);
}
开发者ID:apache,项目名称:commons-jexl,代码行数:17,代码来源:SandboxTest.java
示例14: threadFinished
import org.apache.commons.jexl3.JexlEngine; //导入依赖的package包/类
@Override
public void threadFinished() {
JexlEngine engine = threadLocalJexl.get();
if(engine != null) {
engine.clearCache();
threadLocalJexl.remove();
}
}
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:9,代码来源:Jexl3Function.java
示例15: evaluateVisibility
import org.apache.commons.jexl3.JexlEngine; //导入依赖的package包/类
private boolean evaluateVisibility(Object object,
PropertyDescriptor[] beanPropertyDescriptors, String visibleWhen)
{
Map<String, PropertyDescriptor> descriptorsMap =
new HashMap<String, PropertyDescriptor>();
for (PropertyDescriptor pd : beanPropertyDescriptors)
{
descriptorsMap.put(pd.getName(), pd);
}
JexlEngine jexl = new JexlBuilder().create();
JexlExpression expression = jexl.createExpression(visibleWhen);
JexlContext context = new MapContext();
Set<List<String>> vars = ((Script) expression).getVariables();
for (List<String> varList : vars)
{
for (String varName : varList)
{
PropertyDescriptor propertyDescriptor = descriptorsMap.get(varName);
if (propertyDescriptor != null)
{
try
{
Object value = propertyDescriptor.getReadMethod().invoke(object);
context.set(varName, value);
}
catch (Exception e)
{
Activator.logError(Status.ERROR,
"Could not retrieve value for property " + varName, e);
}
}
}
}
return (boolean) expression.evaluate(context);
}
开发者ID:debrief,项目名称:limpet,代码行数:39,代码来源:ReflectivePropertySource.java
示例16: createJexlEngine
import org.apache.commons.jexl3.JexlEngine; //导入依赖的package包/类
/**
* Create the internal JexlEngine member during the initialization.
* This method can be overriden to specify more detailed options
* into the JexlEngine.
* @return new JexlEngine instance
*/
protected JexlEngine createJexlEngine() {
// With null prefix, define top-level user defined functions.
// See javadoc of org.apache.commons.jexl2.JexlEngine#setFunctions(Map<String,Object> funcs) for detail.
Map<String, Object> funcs = new HashMap<>();
funcs.put(null, JexlBuiltin.class);
return new JexlBuilder().namespaces(funcs).strict(jexlEngineStrict).silent(jexlEngineSilent).cache(256).create();
}
开发者ID:apache,项目名称:commons-scxml,代码行数:14,代码来源:JexlEvaluator.java
示例17: getJexlEngine
import org.apache.commons.jexl3.JexlEngine; //导入依赖的package包/类
/**
* Returns the internal JexlEngine if existing.
* Otherwise, it creates a new engine by invoking {@link #createJexlEngine()}.
* <P>
* <EM>NOTE: The internal JexlEngine instance can be null when this is deserialized.</EM>
* </P>
* @return the current JexlEngine
*/
private JexlEngine getJexlEngine() {
JexlEngine engine = jexlEngine;
if (engine == null) {
synchronized (this) {
engine = jexlEngine;
if (engine == null) {
jexlEngine = engine = createJexlEngine();
}
}
}
return engine;
}
开发者ID:apache,项目名称:commons-scxml,代码行数:21,代码来源:JexlEvaluator.java
示例18: ScriptExecution
import org.apache.commons.jexl3.JexlEngine; //导入依赖的package包/类
public ScriptExecution(final CameraService cameraService, final File imgDownloadPath, final Logger logger, final String scriptName,
final List<ScriptStep> steps, final JexlEngine engine, final ScriptExecutionObserver scriptExecutionObserver,
final ScriptExecutionFinishListener finishListener) {
this.steps = steps.toArray(new ScriptStep[steps.size()]);
this.engine = engine;
this.context = new JexlMapContext();
context.set("__lightmeter", new LightMeterImpl(cameraService, logger));
context.set("__helper", new ScriptHelper());
this.scriptExecutionObserver = scriptExecutionObserver;
this.finishListener = finishListener;
this.scriptName = scriptName;
this.cameraService = cameraService;
this.imgDownloadPath = imgDownloadPath;
}
开发者ID:mvmn,项目名称:gp2srv,代码行数:15,代码来源:ScriptExecution.java
示例19: evalCondition
import org.apache.commons.jexl3.JexlEngine; //导入依赖的package包/类
public boolean evalCondition(JexlEngine engine, JexlMapContext context) {
boolean execute = true;
if (condition != null && !condition.trim().isEmpty()) {
execute = Boolean
.valueOf((conditionExpressionCache == null ? (conditionExpressionCache = engine.createExpression(condition)) : conditionExpressionCache)
.evaluate(context).toString());
}
return execute;
}
开发者ID:mvmn,项目名称:gp2srv,代码行数:11,代码来源:ScriptStep.java
示例20: evalExpression
import org.apache.commons.jexl3.JexlEngine; //导入依赖的package包/类
public Object evalExpression(JexlEngine engine, JexlMapContext context, CameraConfigEntryBean configEntryForEval) {
Object evaluatedValue = null;
if (type.getUsesExpression()) {
if (configEntryForEval != null) {
context.set("__camprop", configEntryForEval);
}
evaluatedValue = (expressionExpressionCache == null ? (expressionExpressionCache = engine.createExpression(expression)) : expressionExpressionCache)
.evaluate(context);
}
return evaluatedValue;
}
开发者ID:mvmn,项目名称:gp2srv,代码行数:12,代码来源:ScriptStep.java
注:本文中的org.apache.commons.jexl3.JexlEngine类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论