Package org.springframework.expression.spel.standard

Examples of org.springframework.expression.spel.standard.SpelExpression


            }

            final ThymeleafEvaluationContextWrapper evaluationContext =
                    new ThymeleafEvaluationContextWrapper(baseEvaluationContext, contextVariables);

            final SpelExpression exp = getExpression(configuration, spelExpression);
           
            final Object evaluationRoot =
                    (useSelectionAsRoot?
                            processingContext.getExpressionSelectionEvaluationRoot() :
                            processingContext.getExpressionEvaluationRoot());
           
            setVariableRestrictions(expContext, evaluationRoot, contextVariables);

            if (!expContext.getPerformTypeConversion()) {
                return exp.getValue(evaluationContext, evaluationRoot);
            }

            final IStandardConversionService conversionService =
                    StandardExpressions.getConversionService(configuration);

            if (conversionService instanceof SpringStandardConversionService) {
                // The conversion service is a mere bridge with the Spring ConversionService, therefore
                // this makes use of the complete Spring type conversion infrastructure, without needing
                // to manually execute the conversion.
                return exp.getValue(evaluationContext, evaluationRoot, String.class);
            }

            // We need type conversion, but conversion service is not a mere bridge to the Spring one,
            // so we need manual execution.
            final Object result = exp.getValue(evaluationContext, evaluationRoot);
            return conversionService.convert(configuration, processingContext, result, String.class);


        } catch (final TemplateProcessingException e) {
            throw e;
View Full Code Here


    }


    private static SpelExpression getExpression(final Configuration configuration, final String spelExpression) {
       
        SpelExpression exp = null;
        ICache<String, Object> cache = null;
       
        final ICacheManager cacheManager = configuration.getCacheManager();
        if (cacheManager != null) {
            cache = cacheManager.getExpressionCache();
View Full Code Here

            }

            final ThymeleafEvaluationContextWrapper evaluationContext =
                    new ThymeleafEvaluationContextWrapper(baseEvaluationContext, contextVariables);

            final SpelExpression exp = getExpression(configuration, spelExpression);
           
            final Object evaluationRoot =
                    (useSelectionAsRoot?
                            processingContext.getExpressionSelectionEvaluationRoot() :
                            processingContext.getExpressionEvaluationRoot());
           
            setVariableRestrictions(expContext, evaluationRoot, contextVariables);

            if (!expContext.getPerformTypeConversion()) {
                return exp.getValue(evaluationContext, evaluationRoot);
            }

            final IStandardConversionService conversionService =
                    StandardExpressions.getConversionService(configuration);

            if (conversionService instanceof SpringStandardConversionService) {
                // The conversion service is a mere bridge with the Spring ConversionService, therefore
                // this makes use of the complete Spring type conversion infrastructure, without needing
                // to manually execute the conversion.
                return exp.getValue(evaluationContext, evaluationRoot, String.class);
            }

            // We need type conversion, but conversion service is not a mere bridge to the Spring one,
            // so we need manual execution.
            final Object result = exp.getValue(evaluationContext, evaluationRoot);
            return conversionService.convert(configuration, processingContext, result, String.class);


        } catch (final TemplateProcessingException e) {
            throw e;
View Full Code Here

    }


    private static SpelExpression getExpression(final Configuration configuration, final String spelExpression) {
       
        SpelExpression exp = null;
        ICache<String, Object> cache = null;
       
        final ICacheManager cacheManager = configuration.getCacheManager();
        if (cacheManager != null) {
            cache = cacheManager.getExpressionCache();
View Full Code Here

    evaluate("2 + 'a'", "2a", String.class);
    evaluate("'ab' + null", "abnull", String.class);
    evaluate("null + 'ab'", "nullab", String.class);

    // AST:
    SpelExpression expr = (SpelExpression)parser.parseExpression("+3");
    assertEquals("+3",expr.toStringAST());
    expr = (SpelExpression)parser.parseExpression("2+3");
    assertEquals("(2 + 3)",expr.toStringAST());

    // use as a unary operator
    evaluate("+5d",5d,Double.class);
    evaluate("+5L",5L,Long.class);
    evaluate("+5",5,Integer.class);
View Full Code Here

  public void testMinus() throws Exception {
    evaluate("'c' - 2", "a", String.class);
    evaluate("3.0f - 5.0f", -2.0f, Float.class);
    evaluateAndCheckError("'ab' - 2", SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES);
    evaluateAndCheckError("2-'ab'", SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES);
    SpelExpression expr = (SpelExpression)parser.parseExpression("-3");
    assertEquals("-3", expr.toStringAST());
    expr = (SpelExpression)parser.parseExpression("2-3");
    assertEquals("(2 - 3)", expr.toStringAST());

    evaluate("-5d",-5d,Double.class);
    evaluate("-5L",-5L,Long.class);
    evaluate("-5", -5, Integer.class);
    evaluate("-new java.math.BigDecimal('5')", new BigDecimal("-5"),BigDecimal.class);
View Full Code Here

    // Variant of above more like what was in the bug report:
    SpelExpressionParser parser = new SpelExpressionParser(
        new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE,
            this.getClass().getClassLoader()));

    SpelExpression ex = parser.parseRaw("#it?.age.equals([0])");
    context = new StandardEvaluationContext(new Object[] { person.getAge() });
    context.setVariable("it", person);
    assertTrue(ex.getValue(context, Boolean.class));
    assertTrue(ex.getValue(context, Boolean.class));
   
    PersonInOtherPackage person2 = new PersonInOtherPackage(1);
    ex = parser.parseRaw("#it?.age.equals([0])");
    context =
        new StandardEvaluationContext(new Object[] { person2.getAge() });
    context.setVariable("it", person2);
    assertTrue(ex.getValue(context, Boolean.class));
    assertTrue(ex.getValue(context, Boolean.class));
   
    ex = parser.parseRaw("#it?.age.equals([0])");
    context =
        new StandardEvaluationContext(new Object[] { person2.getAge() });
    context.setVariable("it", person2);
    assertTrue((Boolean)ex.getValue(context));
    assertTrue((Boolean)ex.getValue(context));
  }
View Full Code Here

    assertEquals("Lorg/springframework/expression/spel/SpelCompilationCoverageTests$Three",getAst().getExitDescriptor());
   
    Expression expression = parser.parseExpression("DR[0].three.four lt 0.1d?#root:null");
    v = expression.getValue(payload);
   
    SpelExpression sExpr = (SpelExpression)expression;
    Ternary ternary = (Ternary)sExpr.getAST();
    OpLT oplt = (OpLT)ternary.getChild(0);
    CompoundExpression cExpr = (CompoundExpression)oplt.getLeftOperand();
    String cExprExitDescriptor = cExpr.getExitDescriptor();
    assertEquals("D",cExprExitDescriptor);
    assertEquals("Z",oplt.getExitDescriptor());
View Full Code Here

 
  // helpers

  private SpelNodeImpl getAst() {
    SpelExpression spelExpression = (SpelExpression)expression;
    SpelNode ast = spelExpression.getAST();
    return (SpelNodeImpl)ast;
  }
View Full Code Here

  @Test
  public void failsWhenSettingContextForExpression_SPR12326() {
      SpelExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE, this
              .getClass().getClassLoader()));
      Person3 person = new Person3("foo", 1);
      SpelExpression expression = parser.parseRaw("#it?.age?.equals([0])");
      StandardEvaluationContext context = new StandardEvaluationContext(new Object[] { 1 });
      context.setVariable("it", person);
      expression.setEvaluationContext(context);
      assertTrue(expression.getValue(Boolean.class));
      assertTrue(expression.getValue(Boolean.class));      
      assertCanCompile(expression);
      assertTrue(expression.getValue(Boolean.class));
  }
View Full Code Here

TOP

Related Classes of org.springframework.expression.spel.standard.SpelExpression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.