createValueExpression

javax.el 
Class ExpressionFactory

java.lang.Object
  extended by javax.el.ExpressionFactory

public abstract class ExpressionFactory
   
   
    
    extends 
    
    Object
   
   


Constructor Summary
ExpressionFactory() 
           
 
Method Summary
abstract  ObjectcoerceToType(Object obj, Class<?> targetType) 
          Coerces an object to a specific type according to the EL type conversion rules.
abstract  MethodExpressioncreateMethodExpression(ELContext context, String expression, Class<?> expectedReturnType, Class<?>[] expectedParamTypes) 
          Parses an expression into a MethodExpression for later evaluation.
abstract  ValueExpressioncreateValueExpression(ELContext context, String expression, Class<?> expectedType) 
          Parses an expression into a ValueExpression for later evaluation.
abstract  ValueExpressioncreateValueExpression(Object instance, Class<?> expectedType) 
          Creates a ValueExpression that wraps an object instance.
static ExpressionFactorynewInstance() 
          Creates a new instance of a ExpressionFactory.
static ExpressionFactorynewInstance(Properties properties) 
          Create a new instance of a ExpressionFactory, with optional properties.
 
Methods inherited from class java.lang.Object
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait
 

Constructor Detail

ExpressionFactory

public ExpressionFactory()
Method Detail

newInstance

public static ExpressionFactory newInstance()
Creates a new instance of a  ExpressionFactory. This method uses the following ordered lookup procedure to determine the  ExpressionFactoryimplementation class to load:
  • Use the Services API (as detailed in the JAR specification). If a resource with the name of META-INF/services/javax.el.ExpressionFactoryexists, then its first line, if present, is used as the UTF-8 encoded name of the implementation class.
  • Use the properties file "lib/el.properties" in the JRE directory. If this file exists and it is readable by thejava.util.Properties.load(InputStream) method, and it contains an entry whose key is "javax.el.ExpressionFactory", then the value of that entry is used as the name of the implementation class.
  • Use the javax.el.ExpressionFactory system property. If a system property with this name is defined, then its value is used as the name of the implementation class.
  • Use a platform default implementation.


newInstance

public static ExpressionFactory newInstance(Properties properties)

Create a new instance of a ExpressionFactory, with optional properties. This method uses the same lookup procedure as the one used innewInstance().

If the argument properties is not null, and if the implementation contains a constructor with a single parameter of type java.util.Properties, then the constructor is used to create the instance.

Properties are optional and can be ignored by an implementation.

The name of a property should start with "javax.el."

The following are some suggested names for properties.

  • javax.el.cacheSize

Parameters:
properties - Properties passed to the implementation. If null, then no properties.

createValueExpression

public abstract ValueExpression createValueExpression(ELContext context,
                                                      String expression,
                                                      Class<?> expectedType)
Parses an expression into a  ValueExpression for later evaluation. Use this method for expressions that refer to values.

This method should perform syntactic validation of the expression. If in doing so it detects errors, it should raise an ELException.

Parameters:
context - The EL context used to parse the expression. The  FunctionMapper and  VariableMapper stored in the ELContext are used to resolve functions and variables found in the expression. They can be  null, in which case functions or variables are not supported for this expression. The object returned must invoke the same functions and access the same variable mappings regardless of whether the mappings in the provided  FunctionMapper and  VariableMapper instances change between calling  ExpressionFactory.createValueExpression() and any method on  ValueExpression.

Note that within the EL, the ${} and #{} syntaxes are treated identically. This includes the use of VariableMapper and FunctionMapper at expression creation time. Each is invoked if not null, independent of whether the #{} or ${} syntax is used for the expression.

expression - The expression to parse
expectedType - The type the result of the expression will be coerced to after evaluation.
Returns:
The parsed expression
Throws:
NullPointerException - Thrown if expectedType is null.
ELException - Thrown if there are syntactical errors in the provided expression.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据你提供的代码片段,我猜测你是在使用Java中的EL表达式语言。如果是这样,那么你遇到的错误是因为在表达式中使用了一个名为'variables:notEquals'的函数,而该函数并没有被正确地定义和注册到系统中。 要解决这个问题,你需要确保在你的代码中正确地定义了'variables:notEquals'函数,并且将其注册到系统中。在你的表达式中,'variables'是一个命名空间,而'notEquals'是该命名空间下的一个函数。因此,你需要在代码中显式地定义这个命名空间,以及命名空间下的函数。 以下是一个可能的解决方案,你可以根据自己的需要进行修改: ``` package com.example; import javax.el.*; public class MyFunctions { public static boolean notEquals(Object obj1, Object obj2) { return !obj1.equals(obj2); } } ExpressionFactory factory = new ExpressionFactoryImpl(); SimpleContext context = new SimpleContext(); // 定义命名空间 context.setFunction("variables", "notEquals", MyFunctions.class.getMethod("notEquals", Object.class, Object.class)); // 设置变量 context.setVariable("varName", factory.createValueExpression("123", Object.class)); context.setVariable("Flow_0kgaow2", factory.createValueExpression(snc, Object.class)); // 构造表达式并计算结果 String exp = "${variables:notEquals(varName, '123')}"; ValueExpression e = factory.createValueExpression(context, exp, Boolean.class); Object r = e.getValue(context); ``` 在上面的代码中,我们首先定义了一个名为'MyFunctions'的类,该类包含了我们需要使用的'notEquals'函数。然后,我们使用SimpleContext来构造一个EL表达式的上下文,并在上下文中定义了一个名为'variables'的命名空间,并将'notEquals'函数注册到该命名空间中。 最后,我们可以使用ExpressionFactory来构造表达式,并调用getValue方法来计算表达式的结果。在这个例子中,表达式的结果应该是false,因为我们将'varName'设置为了'123',而在表达式中判断'varName'是否等于'123'。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值