1 16 17 package org.apache.cocoon.woody.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 44 private DefaultFunctionFactory factory; 45 46 public void configure(Configuration config) throws ConfigurationException { 47 factory = new DefaultFunctionFactory(); 48 49 Configuration[] functions = config.getChildren("function"); 50 for (int i = 0; i < functions.length; i++) { 51 String name = functions[i].getAttribute("name"); 52 String clazz = functions[i].getAttribute("class"); 53 try { 54 factory.registerFunction(name, Class.forName(clazz)); 55 } catch (ClassNotFoundException e) { 56 throw new ConfigurationException("Can not find class " + clazz + " for function " + name + ": " + e); 57 } 58 } 59 } 60 61 public Expression parse(String expressionString) throws ParseException, ExpressionException { 62 63 FormulaParser parser = new FormulaParser(new java.io.StringReader (expressionString), factory); 64 parser.sum(); 65 66 Expression expression = parser.getExpression(); 67 expression.check(); 68 69 return expression; 70 } 71 } 72 | Popular Tags |