KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > rolap > RolapNativeRegistry


1 /*
2 // This software is subject to the terms of the Common Public License
3 // Agreement, available at the following URL:
4 // http://www.opensource.org/licenses/cpl.html.
5 // Copyright (C) 2004-2005 TONBELLER AG
6 // All Rights Reserved.
7 // You must accept the terms of that agreement to use this software.
8 */

9 package mondrian.rolap;
10
11 import java.util.ArrayList JavaDoc;
12 import java.util.List JavaDoc;
13
14 import mondrian.olap.Exp;
15 import mondrian.olap.FunDef;
16 import mondrian.olap.NativeEvaluator;
17
18 /**
19  * Composite of {@link RolapNative}s. Uses chain of responsibility
20  * to select the appropriate {@link RolapNative} evaluator.
21  */

22 public class RolapNativeRegistry extends RolapNative {
23
24     private List JavaDoc<RolapNative> natives = new ArrayList JavaDoc<RolapNative>();
25
26     public RolapNativeRegistry() {
27         super.setEnabled(true);
28         register(new RolapNativeCrossJoin());
29         register(new RolapNativeTopCount());
30         register(new RolapNativeFilter());
31     }
32
33     /**
34      * Returns the matching NativeEvaluator or null if <code>fun</code> can not
35      * be executed in SQL for the given context and arguments.
36      */

37     public NativeEvaluator createEvaluator(
38         RolapEvaluator evaluator, FunDef fun, Exp[] args)
39     {
40         if (!isEnabled()) {
41             return null;
42         }
43         for (RolapNative rn : natives) {
44             NativeEvaluator ne = rn.createEvaluator(evaluator, fun, args);
45             if (ne != null) {
46                 if (listener != null) {
47                     NativeEvent e = new NativeEvent(this, ne);
48                     listener.foundEvaluator(e);
49                 }
50                 return ne;
51             }
52         }
53         return null;
54     }
55
56     public void register(RolapNative rn) {
57         natives.add(rn);
58     }
59
60     /** for testing */
61     void setListener(Listener listener) {
62         super.setListener(listener);
63         for (RolapNative rn : natives) {
64             rn.setListener(listener);
65         }
66     }
67
68     /** for testing */
69     void useHardCache(boolean hard) {
70         for (RolapNative rn : natives) {
71             rn.useHardCache(hard);
72         }
73     }
74
75 }
76
77 // End RolapNativeRegistry.java
78
Popular Tags