1 11 package mondrian.olap.fun; 12 13 import mondrian.olap.Exp; 14 import mondrian.olap.FunDef; 15 import mondrian.olap.Util; 16 17 import java.lang.reflect.Constructor ; 18 import java.lang.reflect.InvocationTargetException ; 19 20 28 public class ReflectiveMultiResolver extends MultiResolver { 29 private final Constructor constructor; 30 private final String [] reservedWords; 31 32 public ReflectiveMultiResolver( 33 String name, String signature, String description, 34 String [] signatures, Class clazz) { 35 this(name, signature, description, signatures, clazz, null); 36 } 37 38 public ReflectiveMultiResolver( 39 String name, String signature, String description, 40 String [] signatures, Class clazz, 41 String [] reservedWords) { 42 super(name, signature, description, signatures); 43 try { 44 this.constructor = clazz.getConstructor(new Class [] {FunDef.class}); 45 } catch (NoSuchMethodException e) { 46 throw Util.newInternal(e, "Error while registering resolver class " + clazz); 47 } 48 this.reservedWords = reservedWords; 49 } 50 51 protected FunDef createFunDef(Exp[] args, FunDef dummyFunDef) { 52 try { 53 return (FunDef) constructor.newInstance(new Object [] {dummyFunDef}); 54 } catch (InstantiationException e) { 55 throw Util.newInternal(e, "Error while instantiating FunDef '" + getSignature() + "'"); 56 } catch (IllegalAccessException e) { 57 throw Util.newInternal(e, "Error while instantiating FunDef '" + getSignature() + "'"); 58 } catch (InvocationTargetException e) { 59 throw Util.newInternal(e, "Error while instantiating FunDef '" + getSignature() + "'"); 60 } 61 } 62 63 public String [] getReservedWords() { 64 if (reservedWords != null) { 65 return reservedWords; 66 } 67 return super.getReservedWords(); 68 } 69 } 70 71 | Popular Tags |