本文整理汇总了Java中org.apache.commons.jexl2.JexlException类的典型用法代码示例。如果您正苦于以下问题:Java JexlException类的具体用法?Java JexlException怎么用?Java JexlException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JexlException类属于org.apache.commons.jexl2包,在下文中一共展示了JexlException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: evaluate
import org.apache.commons.jexl2.JexlException; //导入依赖的package包/类
public String evaluate(final String expression,
final JexlContext jexlContext) {
String result = "";
if (expression != null
&& !expression.isEmpty() && jexlContext != null) {
try {
Expression jexlExpression =
jexlEngine.createExpression(expression);
Object evaluated = jexlExpression.evaluate(jexlContext);
if (evaluated != null) {
result = evaluated.toString();
}
} catch (JexlException e) {
LOG.error("Invalid jexl expression: " + expression, e);
result = "";
}
} else {
LOG.debug("Expression not provided or invalid context");
}
return result;
}
示例2: eval
import org.apache.commons.jexl2.JexlException; //导入依赖的package包/类
public synchronized Object eval(long processInstanceId, String expression) {
expression=expression.trim();
if(expression.startsWith("${") && expression.endsWith("}")){
expression=expression.substring(2,expression.length()-1);
}else{
return expression;
}
CacheService cacheService=EnvironmentUtils.getEnvironment().getCache();
ProcessMapContext context=cacheService.getContext(processInstanceId);
if(context==null){
buildProcessInstanceContext(processService.getProcessInstanceById(processInstanceId));
context=cacheService.getContext(processInstanceId);
}
if(context==null){
log.warn("ProcessInstance "+processInstanceId+" variable context is not exist!");
return null;
}
Object obj=null;
try{
obj=jexl.createExpression(expression).evaluate(context);
}catch(JexlException ex){
log.info("Named "+expression+" variable was not found in ProcessInstance "+processInstanceId);
}
return obj;
}
示例3: isValid
import org.apache.commons.jexl2.JexlException; //导入依赖的package包/类
/**
* Indicates whether the given expression is valid, i.e. can be successfully
* evaluated.
*
* @param expression the expression.
* @param vars the variables, can be null.
* @return true or false.
*/
public static boolean isValid( String expression, Map<String, Object> vars )
{
try
{
Object result = evaluate( expression, vars, true );
return result != null;
}
catch ( JexlException ex )
{
if ( ex.getMessage().contains( "divide error" ) )
{
return true; //TODO division by zero masking
}
return false;
}
}
示例4: parse
import org.apache.commons.jexl2.JexlException; //导入依赖的package包/类
@Override
public ParserNode parse(String expression) throws ParserException
{
if (engine == null)
{
throw new ParserException("Map algebra parser engine was not initialized");
}
try
{
engine.createScript(expression);
jexlRootNode = engine.getScript();
//jexlRootNode = (ASTJexlScript)engine.createScript(expression);
ParserNode last = null;
for (int i = 0; i < jexlRootNode.jjtGetNumChildren(); i++)
{
last = convertToMrGeoNode(jexlRootNode.jjtGetChild(i));
}
return last;
}
catch (JexlException e)
{
throw new ParserException(e);
}
}
示例5: filterOut
import org.apache.commons.jexl2.JexlException; //导入依赖的package包/类
@Override
public boolean filterOut(final SAMRecord record) {
final Object o;
try {
o = this.expr.evaluate(new SamRecordJEXLContext(record));
}
catch(final JexlException err) {
throw new RuntimeException("Cannot evaluate JEXL expression \""+this.exprStr+"\" with SAMRecord 'record' :"+record, err);
}
if(o==null) return true;
if(o instanceof Boolean) {
return Boolean.class.cast(o).booleanValue();
}
if(o instanceof Integer) {
return Integer.class.cast(o).intValue()!=0;
}
throw new IllegalArgumentException("expression "+this.exprStr+" doesn't return a boolean.");
}
示例6: checkFunctions
import org.apache.commons.jexl2.JexlException; //导入依赖的package包/类
/**
* TODO FIXME Must be better way than this...
* @param expr
* @throws Exception
*/
private void checkFunctions(String expr) throws Exception {
// We do not support the . operator for now because
// otherwise http://jira.diamond.ac.uk/browse/SCI-1731
//if (expr.indexOf('.')>-1) {
// throw new Exception("The dot operator '.' is not supported.");
//}
// We now evaluate the expression to try and trap invalid functions.
try {
final Script script = jexl.createScript(expr);
Set<List<String>> names = script.getVariables();
Collection<String> vars = unpack(names);
final Map<String,Object> dummy = new HashMap<String,Object>(vars.size());
for (String name : vars) dummy.put(name, 1);
MapContext dCnxt = new MapContext(dummy);
expression.evaluate(dCnxt);
} catch (JexlException ne) {
if (ne.getMessage().toLowerCase().contains("no such function namespace")) {
final String msg = ne.toString();
final String[] segs = msg.split(":");
throw new Exception(segs[3], ne);
}
} catch (Exception ignored) {
// We allow the expression but it might fail later
}
}
示例7: isBoolean
import org.apache.commons.jexl2.JexlException; //导入依赖的package包/类
/**
* Indicates whether the given expression is valid and evaluates to true or
* false.
*
* @param expression the expression.
* @param vars the variables, can be null.
* @return true or false.
*/
public static boolean isBoolean( String expression, Map<String, Object> vars )
{
try
{
Object result = evaluate( expression, vars );
return ( result instanceof Boolean );
}
catch ( JexlException ex )
{
return false;
}
}
示例8: isExpressionValid
import org.apache.commons.jexl2.JexlException; //导入依赖的package包/类
public boolean isExpressionValid(final String expression) {
boolean result;
try {
jexlEngine.createExpression(expression);
result = true;
} catch (JexlException e) {
LOG.error("Invalid jexl expression: " + expression, e);
result = false;
}
return result;
}
示例9: testEvaluate
import org.apache.commons.jexl2.JexlException; //导入依赖的package包/类
@Test
public void testEvaluate() {
assertTrue("Incorrect evaluation", filter.evaluate("value", new StringContext(), "text == 'value'"));
assertTrue("Incorrect evaluation", filter.evaluate("value", new StringContext(), "text != 'incorrect'"));
try {
filter.evaluate("value", new StringContext(), "text = 'incorrect'");
fail("Exception must be thrown!");
} catch (JexlException ex) {
}
}
示例10: evaluate
import org.apache.commons.jexl2.JexlException; //导入依赖的package包/类
public Object evaluate(String expressionString, ExecutionContext context)
throws JexlEvaluationException {
if (log.isDebugEnabled()) {
log.debug(String.format(
"evaluate: expressionString".replaceAll(", ", "=%s, ")
+ "=%s", expressionString));
}
try {
// Create engine and context.
JexlContext jexlContext = new MapContext(context);
// Create and evaluate expression
Object result = jexl.createExpression(expressionString).evaluate(
jexlContext);
if (log.isDebugEnabled()) {
log.debug(String.format(
"evaluate: expressionString, result, resultClass"
.replaceAll(", ", "=%s, ") + "=%s",
expressionString, result, (result != null ? result
.getClass().getName() : "null")));
}
return result;
} catch (JexlException je) {
throw new JexlEvaluationException("Failed to evaluate: "
+ expressionString + ": " + je.getMessage(), je);
}
}
示例11: bindCustomObjectParam
import org.apache.commons.jexl2.JexlException; //导入依赖的package包/类
private String bindCustomObjectParam(final BoundSql boundSql,
final Object param, final String sql) {
/*
* 쿼리의 ?와 매핑되는 실제 값들이 List 객체로 return이 된다. 이때 List 객체의 0번째 순서에 있는
* ParameterMapping 객체가 쿼리의 첫번째 ?와 매핑이 된다 이런 식으로 쿼리의 ?과 ParameterMapping
* 객체들을 Mapping 한다
*/
String sql2 = new String(sql);
List<ParameterMapping> paramMapping = boundSql.getParameterMappings();
Class<? extends Object> paramClass = param.getClass();
for (ParameterMapping mapping : paramMapping) {
String propValue = mapping.getProperty();
// 해당 파라미터로 넘겨받은 사용자 정의 클래스 객체의 멤버변수명
Object v = null;
try {
v = engine.getProperty(param, propValue);
} catch (JexlException e) {
logger.warn(
String.format(
"SKIP PROPERTY - [%s]. (no such public getter or field on parameter object.).",
propValue), e);
continue;
}
// 해당 파라미터로 넘겨받은 사용자 정의 클래스 객체의 멤버변수의 타입.
Class<?> javaType = mapping.getJavaType();
if (String.class == javaType) {
// SQL의 ? 대신에 실제 값을 넣는다. 이때 String 일 경우는 '를 붙여야.
sql2 = sql2.replaceFirst("\\?", "'" + v + "'");
} else {
sql2 = sql2.replaceFirst("\\?", ObjectUtils.toString(v));
}
}
return sql2;
}
示例12: getExpressionType
import org.apache.commons.jexl2.JexlException; //导入依赖的package包/类
public static String getExpressionType(String expression) {
Object value = null;
try {
value = testExpression(expression);
} catch (JexlException ex) {
ex.printStackTrace();
Show.error(ex);
}
String type = "java.lang.Double";
if ((value instanceof String) || (value instanceof Boolean) || (value instanceof Date) ) {
type = value.getClass().getCanonicalName();
}
return type;
}
示例13: isValidExpression
import org.apache.commons.jexl2.JexlException; //导入依赖的package包/类
public static boolean isValidExpression(String expression) {
Object value = null;
try {
value = testExpression(expression);
} catch (JexlException ex) {
ex.printStackTrace();
return false;
}
return true;
}
示例14: isValidBooleanExpression
import org.apache.commons.jexl2.JexlException; //导入依赖的package包/类
public static boolean isValidBooleanExpression(String expression) {
Object value = null;
try {
value = testExpression(expression);
if ( !(value instanceof Boolean) ) {
return false;
}
} catch (JexlException ex) {
ex.printStackTrace();
return false;
}
return true;
}
示例15: bedLineToString
import org.apache.commons.jexl2.JexlException; //导入依赖的package包/类
private String bedLineToString(final BedLine bedLine) {
final Object o;
try {
o = getOwner().jexlExpr.evaluate(new BedJEXLContext(bedLine));
}
catch(final JexlException err) {
throw new RuntimeException("Cannot evaluate JEXL expression \""+getOwner().formatPattern+"\" with BedRecord :"+bedLine);
}
if(o==null) return null;
return String.valueOf(o);
}