1 16 package org.outerj.daisy.query.model; 17 18 import org.outerj.daisy.query.ParseException; 20 import org.outerj.daisy.query.model.functions.*; 21 22 import java.util.HashMap ; 23 24 public class FunctionFactory { 25 private static final HashMap FUNCTIONS; 26 static { 27 FUNCTIONS = new HashMap (); 28 FUNCTIONS.put(LengthFunction.NAME, LengthFunction.class); 30 FUNCTIONS.put(ConcatFunction.NAME, ConcatFunction.class); 31 FUNCTIONS.put(LeftFunction.NAME, LeftFunction.class); 32 FUNCTIONS.put(RightFunction.NAME, RightFunction.class); 33 FUNCTIONS.put(SubstringFunction.NAME, SubstringFunction.class); 34 FUNCTIONS.put(UpperCaseFunction.NAME, UpperCaseFunction.class); 35 FUNCTIONS.put(LowerCaseFunction.NAME, LowerCaseFunction.class); 36 37 FUNCTIONS.put(CurrentDateFunction.NAME, CurrentDateFunction.class); 39 FUNCTIONS.put(YearFunction.NAME, YearFunction.class); 40 FUNCTIONS.put(MonthFunction.NAME, MonthFunction.class); 41 FUNCTIONS.put(DayOfWeekFunction.NAME, DayOfWeekFunction.class); 42 FUNCTIONS.put(DayOfMonthFunction.NAME, DayOfMonthFunction.class); 43 FUNCTIONS.put(DayOfYearFunction.NAME, DayOfYearFunction.class); 44 FUNCTIONS.put(WeekFunction.NAME, WeekFunction.class); 45 FUNCTIONS.put(RelativeDateFunction.NAME, RelativeDateFunction.class); 46 47 FUNCTIONS.put(CurrentDateTimeFunction.NAME, CurrentDateTimeFunction.class); 49 FUNCTIONS.put(RelativeDateTimeFunction.NAME, RelativeDateTimeFunction.class); 50 51 FUNCTIONS.put(RandomFunction.NAME, RandomFunction.class); 53 FUNCTIONS.put(ModFunction.NAME, ModFunction.class); 54 FUNCTIONS.put(AbsFunction.NAME, AbsFunction.class); 55 FUNCTIONS.put(FloorFunction.NAME, FloorFunction.class); 56 FUNCTIONS.put(CeilingFunction.NAME, CeilingFunction.class); 57 FUNCTIONS.put(RoundFunction.NAME, RoundFunction.class); 58 59 FUNCTIONS.put(ContextDocFunction.NAME, ContextDocFunction.class); 61 FUNCTIONS.put(UserIdFunction.NAME, UserIdFunction.class); 62 } 63 64 public static Function createFunction(String name) throws ParseException { 65 Class functionClass = (Class )FUNCTIONS.get(name); 66 if (functionClass == null) 67 throw new ParseException("No such function: " + name); 68 try { 69 return (Function)functionClass.newInstance(); 70 } catch (Exception e) { 71 throw new ParseException("Error creating function " + name + ": " + e.toString()); 72 } 73 } 74 } 75 | Popular Tags |