Package cambridge.model

Examples of cambridge.model.Expression


    }

    public static BehaviorProvider<FromBehavior> getProvider() {
        return new BehaviorProvider<FromBehavior>() {
            public FromBehavior get(DynamicAttribute keyAttribute, Map<AttributeKey, Attribute> attributes, int line, int col) throws ExpressionParsingException, BehaviorInstantiationException {
                Expression from = keyAttribute.getExpression();
                AttributeKey toKey = new AttributeKey(keyAttribute.getAttributeNameSpace(), "to");

                Attribute toAttribute = attributes.get(toKey);

                if (toAttribute == null || !(toAttribute instanceof DynamicAttribute)) {
                    throw new BehaviorInstantiationException("Required parameters to is not set", line, col);
                }

                Expression to = ((DynamicAttribute) toAttribute).getExpression();

                return new FromBehavior(from, to, line, col);
            }
        };
    }
View Full Code Here


      }

      String varName = matcher.group(1);
      String expression = matcher.group(2);

      Expression ex = expressionLanguage.parse(expression, currentToken.getLineNo(), currentToken.getColumn());

      return new SetDirective(varName, ex);
   }
View Full Code Here

   @Test
   public void testBoolean() {
      String expression = "true || false";
      try {
         Expression e = Expressions.parse(expression, 0, 0);
         //assertEquals("Testing type", CambridgeExpression.Type.Boolean, e.getType(bindings));
         assertTrue(e.asBoolean(bindings));
      } catch (ExpressionParsingException e) {
         e.printStackTrace();
      } catch (ExpressionEvaluationException e) {
         e.printStackTrace();
      }
   }
View Full Code Here

   @Test
   public void testList() {
      String expression = "['a', 'b', 213, aa]";
      try {
         Expression e = Expressions.parse(expression, 0, 0);
//         assertEquals("Testing type", CambridgeExpression.Type.Object, e.getType(bindings));
         assertTrue(e.eval(bindings) instanceof List);
         List l = (List) e.eval(bindings);
         assertEquals("a", l.get(0));
         assertEquals("b", l.get(1));
         assertEquals(213, l.get(2));
      } catch (ExpressionParsingException e) {
         e.printStackTrace();
      } catch (ExpressionEvaluationException e) {
         e.printStackTrace();
      }
   }
View Full Code Here

    }

    public static BehaviorProvider<RepeatBehavior> getProvider() {
        return new BehaviorProvider<RepeatBehavior>() {
            public RepeatBehavior get(DynamicAttribute keyAttribute, Map<AttributeKey, Attribute> attributes, int line, int col) throws ExpressionParsingException, BehaviorInstantiationException {
                Expression number = keyAttribute.getExpression();
                return new RepeatBehavior(number, line, col);
            }
        };
    }
View Full Code Here

                Attribute asAttribute = attributes.get(asKey);

                AttributeKey iterKey = new AttributeKey(keyAttribute.getAttributeNameSpace(), "iter");
                Attribute iterAttribute = attributes.get(iterKey);

                Expression e = keyAttribute.getExpression();
                return new ForeachBehavior(e, asAttribute == null ? null : asAttribute.getValue(), iterAttribute == null ? null : iterAttribute.getValue(), line, col);
            }
        };
    }
View Full Code Here

    @Test
    public void testSimple() throws ExpressionEvaluationException
    {
        ExpressionContext context = expressionLanguage.createNewContext();
        Expression expression = expressionLanguage.parse("5 + 8", 1, 1);

        Object result = expression.eval(context);
        assertEquals("Testing simple arithmetic", 13, result);
    }
View Full Code Here

    @Test
    public void testVariableAccess() throws Exception
    {
        ExpressionContext context = expressionLanguage.createNewContext();
        context.put("name", "Cambridge");
        Expression expression = expressionLanguage.parse("name", 1, 1);

        Object result = expression.eval(context);
        assertEquals("Testing variable access", "Cambridge", result);
    }
View Full Code Here

    @Test
    public void testBean() throws Exception
    {
        ExpressionContext context = expressionLanguage.createNewContext();
        context.put("sample", sample);
        Expression expression = expressionLanguage.parse("sample", 1, 1);

        Object result = expression.eval(context);
        assertEquals("Testing variable access", sample, result);
        assertTrue("Testing variable access", sample == result);

        assertEquals("Testing bean name", "Cambridge", expressionLanguage.parse("sample.name", 1, 1).eval(context));
        assertEquals("Testing bean id", 100, expressionLanguage.parse("sample.id", 1, 1).eval(context));
View Full Code Here

    @Test
    public void testBoolean() throws Exception
    {
        String expression = "true || false";
        ExpressionContext context = expressionLanguage.createNewContext();
        Expression e = expressionLanguage.parse(expression, 0, 0);
        //assertEquals("Testing type", CambridgeExpression.Type.Boolean, e.getType(bindings));
        assertTrue(e.asBoolean(context));
    }
View Full Code Here

TOP

Related Classes of cambridge.model.Expression

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.