KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > olap > fun > ReflectiveMultiResolver


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/olap/fun/ReflectiveMultiResolver.java#1 $
3 // This software is subject to the terms of the Common Public License
4 // Agreement, available at the following URL:
5 // http://www.opensource.org/licenses/cpl.html.
6 // Copyright (C) 2002-2002 Kana Software, Inc.
7 // Copyright (C) 2002-2006 Julian Hyde and others
8 // All Rights Reserved.
9 // You must accept the terms of that agreement to use this software.
10 */

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 JavaDoc;
18 import java.lang.reflect.InvocationTargetException JavaDoc;
19
20 /**
21  * Resolver which uses reflection to instantiate a {@link FunDef}.
22  * This reduces the amount of anonymous classes.
23  *
24  * @author jhyde
25  * @version $Id: //open/mondrian/src/main/mondrian/olap/fun/ReflectiveMultiResolver.java#1 $
26  * @since Mar 23, 2006
27  */

28 public class ReflectiveMultiResolver extends MultiResolver {
29     private final Constructor JavaDoc constructor;
30     private final String JavaDoc[] reservedWords;
31
32     public ReflectiveMultiResolver(
33             String JavaDoc name, String JavaDoc signature, String JavaDoc description,
34             String JavaDoc[] signatures, Class JavaDoc clazz) {
35         this(name, signature, description, signatures, clazz, null);
36     }
37
38     public ReflectiveMultiResolver(
39             String JavaDoc name, String JavaDoc signature, String JavaDoc description,
40             String JavaDoc[] signatures, Class JavaDoc clazz,
41             String JavaDoc[] reservedWords) {
42         super(name, signature, description, signatures);
43         try {
44             this.constructor = clazz.getConstructor(new Class JavaDoc[] {FunDef.class});
45         } catch (NoSuchMethodException JavaDoc 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 JavaDoc[] {dummyFunDef});
54         } catch (InstantiationException JavaDoc e) {
55             throw Util.newInternal(e, "Error while instantiating FunDef '" + getSignature() + "'");
56         } catch (IllegalAccessException JavaDoc e) {
57             throw Util.newInternal(e, "Error while instantiating FunDef '" + getSignature() + "'");
58         } catch (InvocationTargetException JavaDoc e) {
59             throw Util.newInternal(e, "Error while instantiating FunDef '" + getSignature() + "'");
60         }
61     }
62
63     public String JavaDoc[] getReservedWords() {
64         if (reservedWords != null) {
65             return reservedWords;
66         }
67         return super.getReservedWords();
68     }
69 }
70
71 // End ReflectiveMultiResolver.java
72
Popular Tags