當前位置: 首頁>>代碼示例>>Java>>正文


Java ExpressionFactory類代碼示例

本文整理匯總了Java中javax.el.ExpressionFactory的典型用法代碼示例。如果您正苦於以下問題:Java ExpressionFactory類的具體用法?Java ExpressionFactory怎麽用?Java ExpressionFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ExpressionFactory類屬於javax.el包,在下文中一共展示了ExpressionFactory類的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: 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:liaokailin,項目名稱:tomcat7,代碼行數:21,代碼來源:TestELParser.java

示例6: 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:liaokailin,項目名稱:tomcat7,代碼行數:25,代碼來源:TestELParser.java

示例7: testExpression

import javax.el.ExpressionFactory; //導入依賴的package包/類
private void testExpression(String expression, String expected) {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();

    ValueExpression ve = factory.createValueExpression(
            context, expression, String.class);

    String result = (String) ve.getValue(context);
    assertEquals(expected, result);
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:11,代碼來源:TestELParser.java

示例8: 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

示例9: 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

示例10: 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

示例11: 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:liaokailin,項目名稱:tomcat7,代碼行數:27,代碼來源:TestValueExpressionImpl.java

示例12: 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:liaokailin,項目名稱:tomcat7,代碼行數:22,代碼來源:TestValueExpressionImpl.java

示例13: _createValueExpressionFromApplication

import javax.el.ExpressionFactory; //導入依賴的package包/類
private static ValueExpression _createValueExpressionFromApplication(
  String expression,
  Class<?> expectedType)
{
  ApplicationFactory factory = (ApplicationFactory)
    FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
  if (factory != null)
  {
    Application application = factory.getApplication();
    if (application != null)
    {
      ELContext elContext = _getELContext(application);

      ExpressionFactory expressionFactory = application.getExpressionFactory();
      if (expressionFactory != null)
      {
        return expressionFactory.createValueExpression(elContext, expression, expectedType);
      }
    }
  }

  return null;
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:24,代碼來源:LazyValueExpression.java

示例14: convertToType

import javax.el.ExpressionFactory; //導入依賴的package包/類
public static Object convertToType(Object value, Class desiredClass)
{
    if (value == null)
    {
        return null;
    }

    try
    {
        ExpressionFactory expFactory = FacesContext.getCurrentInstance().getApplication().getExpressionFactory();
        return expFactory.coerceToType(value, desiredClass);
    }
    catch (Exception e)
    {
        String message = "Cannot coerce " + value.getClass().getName()
                         + " to " + desiredClass.getName();
        log.log(Level.SEVERE, message, e);
        throw new FacesException(message, e);
    }
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:21,代碼來源:ClassUtils.java

示例15: actionListener

import javax.el.ExpressionFactory; //導入依賴的package包/類
public void actionListener(ActionEvent event)
{
  String value = _actionListener;
  if (value != null)
  {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExpressionFactory expressionFactory =
        facesContext.getApplication().getExpressionFactory();
    ELContext context = facesContext.getELContext();

    MethodExpression methodExpression =
        expressionFactory.createMethodExpression(context, value, Void.TYPE,
            new Class<?>[]
            { ActionEvent.class });
    methodExpression.invoke(context, new Object[]
    { event });
  }

}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:20,代碼來源:ImmutableItemNode.java


注:本文中的javax.el.ExpressionFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。