1 16 17 package org.apache.cocoon.forms.expression; 18 19 import org.apache.avalon.framework.component.Component; 20 import org.apache.avalon.framework.configuration.Configurable; 21 import org.apache.avalon.framework.configuration.Configuration; 22 import org.apache.avalon.framework.configuration.ConfigurationException; 23 import org.apache.avalon.framework.thread.ThreadSafe; 24 25 import org.outerj.expression.DefaultFunctionFactory; 26 import org.outerj.expression.Expression; 27 import org.outerj.expression.ExpressionException; 28 import org.outerj.expression.FormulaParser; 29 import org.outerj.expression.ParseException; 30 31 41 public class DefaultExpressionManager 42 implements ExpressionManager, Component, Configurable, ThreadSafe { 43 45 private DefaultFunctionFactory factory; 46 47 public void configure(Configuration config) throws ConfigurationException { 48 factory = new DefaultFunctionFactory(); 49 50 Configuration[] functions = config.getChildren("function"); 51 for (int i = 0; i < functions.length; i++) { 52 String name = functions[i].getAttribute("name"); 53 String clazz = functions[i].getAttribute("class"); 54 try { 55 factory.registerFunction(name, Class.forName(clazz)); 56 } catch (ClassNotFoundException e) { 57 throw new ConfigurationException("Can not find class " + clazz + " for function " + name + ": " + e); 58 } 59 } 60 } 61 62 public Expression parse(String expressionString) throws ParseException, ExpressionException { 63 64 FormulaParser parser = new FormulaParser(new java.io.StringReader (expressionString), factory); 65 parser.sum(); 66 67 Expression expression = parser.getExpression(); 68 expression.check(); 69 70 return expression; 71 } 72 } 73 | Popular Tags |