Package org.outerj.expression

Examples of org.outerj.expression.Expression


        // compile combine expression
        Element combineElement = DomHelper.getChildElement(widgetElement, FormsConstants.DEFINITION_NS, "combine", true);
        if(combineElement!=null) {
            String combineExprString = DomHelper.getAttribute(combineElement, "expression");
            Expression combineExpr;
            try {
                combineExpr = expressionManager.parse(combineExprString);
            } catch (Exception e) {
                throw new FormsException("Invalid combine expression '" + combineExprString + "'.",
                                         e, DomHelper.getLocationObject(combineElement));
            }
            Class clazz = definition.getDatatype().getTypeClass();
            if (combineExpr.getResultType() != null && !clazz.isAssignableFrom(combineExpr.getResultType())) {
                throw new FormsException("The result of the combine expression should be '" + clazz.getName() + "', not '" + combineExpr.getResultType().getName() + "'.",
                                         DomHelper.getLocationObject(combineElement));
            }
            definition.setCombineExpression(combineExpr);
        }
    }
View Full Code Here


        }

        // compile combine expression
        Element combineElement = DomHelper.getChildElement(widgetElement, Constants.WD_NS, "combine", true);
        String combineExprString = DomHelper.getAttribute(combineElement, "expression");
        Expression combineExpr = null;
        try {
            combineExpr = expressionManager.parse(combineExprString);
        } catch (Exception e) {
            throw new Exception("Problem with combine expression defined at " + DomHelper.getLocation(combineElement) + ": " + e.getMessage());
        }
        if (combineExpr.getResultType() != null && !String.class.isAssignableFrom(combineExpr.getResultType()))
            throw new Exception("The result of the combine expression should be a string, at " + DomHelper.getLocation(combineElement));
        definition.setCombineExpression(combineExpr);

        // add validation rules
        Element validationElement = DomHelper.getChildElement(widgetElement, Constants.WD_NS, "validation", false);
View Full Code Here

    public Expression parse(String expressionString) throws ParseException, ExpressionException {
       
        FormulaParser parser = new FormulaParser(new java.io.StringReader(expressionString), factory);
        parser.sum();

        Expression expression = parser.getExpression();
        expression.check();

        return expression;
    }
View Full Code Here

        String exactExprString = validationRuleElement.getAttribute("exact");
        String minExprString = validationRuleElement.getAttribute("min");
        String maxExprString = validationRuleElement.getAttribute("max");

        if (exactExprString.length() > 0) {
            Expression expression = parseExpression(exactExprString, validationRuleElement, "exact");
            rule.setExactExpr(expression);
        } else if (minExprString.length() > 0 && maxExprString.length() > 0) {
            Expression expression = parseExpression(minExprString, validationRuleElement, "min");
            rule.setMinExpr(expression);
            expression = parseExpression(maxExprString, validationRuleElement, "max");
            rule.setMaxExpr(expression);
        } else if (minExprString.length() > 0) {
            Expression expression = parseExpression(minExprString, validationRuleElement, "min");
            rule.setMinExpr(expression);
        } else if (maxExprString.length() > 0) {
            Expression expression = parseExpression(maxExprString, validationRuleElement, "max");
            rule.setMaxExpr(expression);
        } else {
            throw new Exception("length validation rule requires a min and/or max, or exact attribute at " + DomHelper.getLocation(validationRuleElement));
        }
View Full Code Here

        String minExprString = validationRuleElement.getAttribute("min");
        String maxExprString = validationRuleElement.getAttribute("max");

        if (minExprString.length() > 0 && maxExprString.length() > 0) {
            Expression expression = parseExpression(minExprString, validationRuleElement, "min");
            rule.setMinExpr(expression);
            expression = parseExpression(maxExprString, validationRuleElement, "max");
            rule.setMaxExpr(expression);
        } else if (minExprString.length() > 0) {
            Expression expression = parseExpression(minExprString, validationRuleElement, "min");
            rule.setMinExpr(expression);
        } else if (maxExprString.length() > 0) {
            Expression expression = parseExpression(maxExprString, validationRuleElement, "max");
            rule.setMaxExpr(expression);
        } else {
            throw new Exception("range validation rule requires a min and/or max attribute at " + DomHelper.getLocation(validationRuleElement));
        }
View Full Code Here

public class AssertValidationRuleBuilder extends AbstractValidationRuleBuilder {
    public ValidationRule build(Element validationRuleElement) throws Exception {
        String exprStr = validationRuleElement.getAttribute("test");
        if (exprStr.length() == 0)
            throw new Exception("assert validation rule requires a \"test\" attribute at " + DomHelper.getLocation(validationRuleElement));
        Expression testExpression = parseExpression(exprStr, validationRuleElement, "test");
        if (testExpression.getResultType() != null && !Boolean.class.isAssignableFrom(testExpression.getResultType()))
            throw new Exception("Expression should evaluate to a boolean on assert validation rule at " + DomHelper.getLocation(validationRuleElement));
        AssertValidationRule rule = new AssertValidationRule(testExpression);
        buildFailMessage(validationRuleElement, rule);
        return rule;
    }
View Full Code Here

        String exactExprString = validationRuleElement.getAttribute("exact");
        String minExprString = validationRuleElement.getAttribute("min");
        String maxExprString = validationRuleElement.getAttribute("max");

        if (exactExprString.length() > 0) {
            Expression expression = parseExpression(exactExprString, validationRuleElement, "exact");
            rule.setExactExpr(expression);
        } else if (minExprString.length() > 0 && maxExprString.length() > 0) {
            Expression expression = parseExpression(minExprString, validationRuleElement, "min");
            rule.setMinExpr(expression);
            expression = parseExpression(maxExprString, validationRuleElement, "max");
            rule.setMaxExpr(expression);
        } else if (minExprString.length() > 0) {
            Expression expression = parseExpression(minExprString, validationRuleElement, "min");
            rule.setMinExpr(expression);
        } else if (maxExprString.length() > 0) {
            Expression expression = parseExpression(maxExprString, validationRuleElement, "max");
            rule.setMaxExpr(expression);
        } else {
            throw new Exception("value-count validation rule requires a min and/or max, or exact attribute at " + DomHelper.getLocation(validationRuleElement));
        }
View Full Code Here

        // compile combine expression
        Element combineElement = DomHelper.getChildElement(widgetElement, FormsConstants.DEFINITION_NS, "combine", true);
        if(combineElement!=null) {
            String combineExprString = DomHelper.getAttribute(combineElement, "expression");
            Expression combineExpr;
            try {
                combineExpr = expressionManager.parse(combineExprString);
            } catch (Exception e) {
                throw new FormsException("Invalid combine expression '" + combineExprString + "'.",
                                         e, DomHelper.getLocationObject(combineElement));
            }
            Class clazz = definition.getDatatype().getTypeClass();
            if (combineExpr.getResultType() != null && !clazz.isAssignableFrom(combineExpr.getResultType())) {
                throw new FormsException("The result of the combine expression should be '" + clazz.getName() + "', not '" + combineExpr.getResultType().getName() + "'.",
                                         DomHelper.getLocationObject(combineElement));
            }
            definition.setCombineExpression(combineExpr);
        }
    }
View Full Code Here

public class SumFunction extends AbstractExpression {

    public Object evaluate(ExpressionContext context) throws ExpressionException {
        BigDecimal result = new BigDecimal("0");
        for(int i = 0; i < arguments.size(); i++) {
            Expression function = (Expression)arguments.get(i);
            Object ret = function.evaluate(context);
            if (ret instanceof Collection) {
                ret = ((Collection)ret).iterator();
            }
            if (ret instanceof Iterator) {
               Iterator iter = (Iterator)ret;
               while (iter.hasNext()) {
                   Object p = iter.next();
                   BigDecimal db = null;
                   if (p instanceof BigDecimal) {
                       db =(BigDecimal)p;
                   } else if (p instanceof Long) {
                       db = new BigDecimal(((Long)p).longValue());
                   } else if (p instanceof Integer) {
                       db = new BigDecimal(((Integer)p).intValue());
                   } else if (p instanceof Double) {
                       db = new BigDecimal(((Double)p).doubleValue());
                   } else if (p instanceof Float) {
                       db = new BigDecimal(((Float)p).floatValue());
                   } else if (p instanceof BigInteger) {
                       db = new BigDecimal((BigInteger)p);
                   } else if (p instanceof Number) {
                       db = new BigDecimal(((Number)p).doubleValue());
                   } else if (p instanceof String) {
                       db = new BigDecimal((String)p);
                   } else {
                       throw new IllegalArgumentException("Cannot sum an argument of type " + p.getClass().getName());
                   }
                   result = result.add(db);
               }
            } else {
                result = result.add((BigDecimal)function.evaluate(context));
            }
        }
        return result;       
    }
View Full Code Here

        // compile combine expression
        Element combineElement = DomHelper.getChildElement(widgetElement, FormsConstants.DEFINITION_NS, "combine", true);
        if(combineElement!=null) {
            String combineExprString = DomHelper.getAttribute(combineElement, "expression");
            Expression combineExpr;
            try {
                combineExpr = expressionManager.parse(combineExprString);
            } catch (Exception e) {
                throw new FormsException("Invalid combine expression '" + combineExprString + "'.",
                                         e, DomHelper.getLocationObject(combineElement));
            }
            Class clazz = definition.getDatatype().getTypeClass();
            if (combineExpr.getResultType() != null && !clazz.isAssignableFrom(combineExpr.getResultType())) {
                throw new FormsException("The result of the combine expression should be '" + clazz.getName() + "', not '" + combineExpr.getResultType().getName() + "'.",
                                         DomHelper.getLocationObject(combineElement));
            }
            definition.setCombineExpression(combineExpr);
        }
    }
View Full Code Here

TOP

Related Classes of org.outerj.expression.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.