当前位置: 首页>>代码示例>>Java>>正文


Java ExpressionFactory.newInstance方法代码示例

本文整理汇总了Java中javax.el.ExpressionFactory.newInstance方法的典型用法代码示例。如果您正苦于以下问题:Java ExpressionFactory.newInstance方法的具体用法?Java ExpressionFactory.newInstance怎么用?Java ExpressionFactory.newInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.el.ExpressionFactory的用法示例。


在下文中一共展示了ExpressionFactory.newInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: bug56185

import javax.el.ExpressionFactory; //导入方法依赖的package包/类
@Test
public void bug56185() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    TesterBeanC beanC = new TesterBeanC();
    ValueExpression var =
        factory.createValueExpression(beanC, TesterBeanC.class);
    context.getVariableMapper().setVariable("myBean", var);

    ValueExpression ve = factory.createValueExpression(context,
        "${(myBean.int1 > 1 and myBean.myBool) or "+
        "((myBean.myBool or myBean.myBool1) and myBean.int1 > 1)}",
        Boolean.class);
    assertEquals(Boolean.FALSE, ve.getValue(context));
    beanC.setInt1(2);
    beanC.setMyBool1(true);
    assertEquals(Boolean.TRUE, ve.getValue(context));
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:20,代码来源:TestELParser.java

示例2: testBug51544Direct

import javax.el.ExpressionFactory; //导入方法依赖的package包/类
/**
 * Test using list directly as variable.
 */
@Test
public void testBug51544Direct() throws Exception {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    List<?> list = Collections.emptyList();

    ValueExpression var =
        factory.createValueExpression(list, List.class);
    context.getVariableMapper().setVariable("list", var);

    ValueExpression ve = factory.createValueExpression(
            context, "${list.size()}", Integer.class);

    Integer result = (Integer) ve.getValue(context);
    assertEquals(Integer.valueOf(0), result);
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:21,代码来源:TestValueExpressionImpl.java

示例3: parseExpression

import javax.el.ExpressionFactory; //导入方法依赖的package包/类
public Expression parseExpression(String expression,
                                  Class expectedType,
                                  FunctionMapper fMapper )
        throws ELException {

    ExpressionFactory fac = ExpressionFactory.newInstance();
    javax.el.ValueExpression expr;
    ELContextImpl elContext = new ELContextImpl(null);
    javax.el.FunctionMapper fm = new FunctionMapperWrapper(fMapper);
    elContext.setFunctionMapper(fm);
    try {
        expr = fac.createValueExpression(
                       elContext,
                       expression, expectedType);
    } catch (javax.el.ELException ex) {
        throw new ELException(ex);
    }
    return new ExpressionImpl(expr, pageContext);
}
 
开发者ID:eclipse,项目名称:packagedrone,代码行数:20,代码来源:ExpressionEvaluatorImpl.java

示例4: testJavaKeyWordSuffix

import javax.el.ExpressionFactory; //导入方法依赖的package包/类
@Test
public void testJavaKeyWordSuffix() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    TesterBeanA beanA = new TesterBeanA();
    beanA.setInt("five");
    ValueExpression var =
        factory.createValueExpression(beanA, TesterBeanA.class);
    context.getVariableMapper().setVariable("beanA", var);

    // Should fail
    Exception e = null;
    try {
        factory.createValueExpression(context, "${beanA.int}",
                String.class);
    } catch (ELException ele) {
        e = ele;
    }
    assertNotNull(e);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:22,代码来源:TestELParser.java

示例5: testBug51544Bean

import javax.el.ExpressionFactory; //导入方法依赖的package包/类
/**
 * Test returning an empty list as a bean property.
 */
@Test
public void testBug51544Bean() throws Exception {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    TesterBeanA beanA = new TesterBeanA();
    beanA.setValList(Collections.emptyList());

    ValueExpression var =
        factory.createValueExpression(beanA, TesterBeanA.class);
    context.getVariableMapper().setVariable("beanA", var);

    ValueExpression ve = factory.createValueExpression(
            context, "${beanA.valList.size()}", Integer.class);

    Integer result = (Integer) ve.getValue(context);
    assertEquals(Integer.valueOf(0), result);
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:22,代码来源:TestValueExpressionImpl.java

示例6: testGetValueReference

import javax.el.ExpressionFactory; //导入方法依赖的package包/类
@Test
public void testGetValueReference() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    TesterBeanB beanB = new TesterBeanB();
    beanB.setName("Tomcat");
    ValueExpression var =
        factory.createValueExpression(beanB, TesterBeanB.class);
    context.getVariableMapper().setVariable("beanB", var);

    ValueExpression ve = factory.createValueExpression(
            context, "${beanB.name}", String.class);

    // First check the basics work
    String result = (String) ve.getValue(context);
    assertEquals("Tomcat", result);

    // Now check the value reference
    ValueReference vr = ve.getValueReference(context);
    assertNotNull(vr);

    assertEquals(beanB, vr.getBase());
    assertEquals("name", vr.getProperty());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:26,代码来源:TestValueExpressionImpl.java

示例7: testBug50105

import javax.el.ExpressionFactory; //导入方法依赖的package包/类
@Test
public void testBug50105() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    TesterEnum testEnum = TesterEnum.APPLE;

    ValueExpression var =
        factory.createValueExpression(testEnum, TesterEnum.class);
    context.getVariableMapper().setVariable("testEnum", var);

    // When coercing an Enum to a String, name() should always be used.
    ValueExpression ve1 = factory.createValueExpression(
            context, "${testEnum}", String.class);
    String result1 = (String) ve1.getValue(context);
    assertEquals("APPLE", result1);

    ValueExpression ve2 = factory.createValueExpression(
            context, "foo${testEnum}bar", String.class);
    String result2 = (String) ve2.getValue(context);
    assertEquals("fooAPPLEbar", result2);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:23,代码来源:TestValueExpressionImpl.java

示例8: testBug51177ObjectMap

import javax.el.ExpressionFactory; //导入方法依赖的package包/类
@Test
public void testBug51177ObjectMap() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    Object o1 = "String value";
    Object o2 = Integer.valueOf(32);

    Map<Object,Object> map = new HashMap<Object,Object>();
    map.put("key1", o1);
    map.put("key2", o2);

    ValueExpression var =
        factory.createValueExpression(map, Map.class);
    context.getVariableMapper().setVariable("map", var);

    ValueExpression ve1 = factory.createValueExpression(
            context, "${map.key1}", Object.class);
    ve1.setValue(context, o2);
    assertEquals(o2, ve1.getValue(context));

    ValueExpression ve2 = factory.createValueExpression(
            context, "${map.key2}", Object.class);
    ve2.setValue(context, o1);
    assertEquals(o1, ve2.getValue(context));
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:27,代码来源:TestValueExpressionImpl.java

示例9: testBug51177ObjectList

import javax.el.ExpressionFactory; //导入方法依赖的package包/类
@Test
public void testBug51177ObjectList() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    Object o1 = "String value";
    Object o2 = Integer.valueOf(32);

    List<Object> list = new ArrayList<Object>();
    list.add(0, o1);
    list.add(1, o2);

    ValueExpression var =
        factory.createValueExpression(list, List.class);
    context.getVariableMapper().setVariable("list", var);

    ValueExpression ve1 = factory.createValueExpression(
            context, "${list[0]}", Object.class);
    ve1.setValue(context, o2);
    assertEquals(o2, ve1.getValue(context));

    ValueExpression ve2 = factory.createValueExpression(
            context, "${list[1]}", Object.class);
    ve2.setValue(context, o1);
    assertEquals(o1, ve2.getValue(context));
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:27,代码来源:TestValueExpressionImpl.java

示例10: testJavaKeyWordIdentifier

import javax.el.ExpressionFactory; //导入方法依赖的package包/类
@Test
public void testJavaKeyWordIdentifier() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    TesterBeanA beanA = new TesterBeanA();
    beanA.setInt("five");
    ValueExpression var =
        factory.createValueExpression(beanA, TesterBeanA.class);
    context.getVariableMapper().setVariable("this", var);

    // Should fail
    Exception e = null;
    try {
        factory.createValueExpression(context, "${this}", String.class);
    } catch (ELException ele) {
        e = ele;
    }
    assertNotNull(e);
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:21,代码来源:TestELParser.java

示例11: doTestBug56179

import javax.el.ExpressionFactory; //导入方法依赖的package包/类
private void doTestBug56179(int parenthesesCount, String innerExpr) {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    ValueExpression var =
        factory.createValueExpression(Boolean.TRUE, Boolean.class);
    context.getVariableMapper().setVariable("test", var);

    StringBuilder expr = new StringBuilder();
    expr.append("${");
    for (int i = 0; i < parenthesesCount; i++) {
        expr.append("(");
    }
    expr.append(innerExpr);
    for (int i = 0; i < parenthesesCount; i++) {
        expr.append(")");
    }
    expr.append("}");
    ValueExpression ve = factory.createValueExpression(
            context, expr.toString(), String.class);

    String result = (String) ve.getValue(context);
    assertEquals("true", result);
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:25,代码来源:TestELParser.java

示例12: testExpressionRecognizesChanges

import javax.el.ExpressionFactory; //导入方法依赖的package包/类
@Test
public void testExpressionRecognizesChanges() {
    SimpleContext context = new SimpleContext();
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ValueExpression expression = factory.createValueExpression(context, "#{msg.localPort == 123}", boolean.class);

    SimpleContext runtimeContext = new SimpleContext();

    final Message message = new Message();
    factory.createValueExpression(runtimeContext, "${msg}", message.getClass()).setValue(runtimeContext, message);
    //create the expression first, then set the value on the pojo
    message.setLocalPort(123);




    assertTrue((boolean) expression.getValue(runtimeContext));
    message.setLocalPort(456);
    assertFalse((boolean) expression.getValue(runtimeContext));
}
 
开发者ID:wired-mind,项目名称:usher,代码行数:21,代码来源:JuelMatcherTests.java

示例13: canFilterUsingPojo

import javax.el.ExpressionFactory; //导入方法依赖的package包/类
/**
 * Not really testing our code. Added this to confirm expected behavior of our EL library.
 */
@Test
public void canFilterUsingPojo() {
    SimpleContext context = new SimpleContext();
     ExpressionFactory factory = ExpressionFactory.newInstance();
    ValueExpression expression = factory.createValueExpression(context, "#{msg.localPort == 123}", boolean.class);

    SimpleContext runtimeContext = new SimpleContext();

    final Message message = new Message();
    message.setLocalPort(123);

    factory.createValueExpression(runtimeContext, "${msg}", message.getClass()).setValue(runtimeContext, message);


    assertTrue((boolean) expression.getValue(runtimeContext));
}
 
开发者ID:wired-mind,项目名称:usher,代码行数:20,代码来源:JuelMatcherTests.java

示例14: makeExpressionPayload

import javax.el.ExpressionFactory; //导入方法依赖的package包/类
public static Object makeExpressionPayload ( String expr ) throws IllegalArgumentException, IllegalAccessException, Exception  {
    FacesContextImpl fc = new FacesContextImpl((ServletContext) null, (ServletRequest) null, (ServletResponse) null);
    ELContext elContext = new FacesELContext(new CompositeELResolver(), fc);
    Reflections.getField(FacesContextImplBase.class, "_elContext").set(fc, elContext);
    ExpressionFactory expressionFactory = ExpressionFactory.newInstance();

    ValueExpression ve1 = expressionFactory.createValueExpression(elContext, expr, Object.class);
    ValueExpressionMethodExpression e = new ValueExpressionMethodExpression(ve1);
    ValueExpression ve2 = expressionFactory.createValueExpression(elContext, "${true}", Object.class);
    ValueExpressionMethodExpression e2 = new ValueExpressionMethodExpression(ve2);

    return Gadgets.makeMap(e2, e);
}
 
开发者ID:hucheat,项目名称:APacheSynapseSimplePOC,代码行数:14,代码来源:Myfaces1.java

示例15: testBug49345

import javax.el.ExpressionFactory; //导入方法依赖的package包/类
@Test
public void testBug49345() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    TesterBeanA beanA = new TesterBeanA();
    TesterBeanB beanB = new TesterBeanB();
    beanB.setName("Tomcat");
    beanA.setBean(beanB);

    ValueExpression var =
        factory.createValueExpression(beanA, TesterBeanA.class);
    context.getVariableMapper().setVariable("beanA", var);

    ValueExpression ve = factory.createValueExpression(
            context, "${beanA.bean.name}", String.class);

    // First check the basics work
    String result = (String) ve.getValue(context);
    assertEquals("Tomcat", result);

    // Now check the value reference
    ValueReference vr = ve.getValueReference(context);
    assertNotNull(vr);

    assertEquals(beanB, vr.getBase());
    assertEquals("name", vr.getProperty());
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:29,代码来源:TestValueExpressionImpl.java


注:本文中的javax.el.ExpressionFactory.newInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。