KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > mdx > NamedSetExpr


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/mdx/NamedSetExpr.java#10 $
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) 2006-2006 Julian Hyde
7 // All Rights Reserved.
8 // You must accept the terms of that agreement to use this software.
9 */

10 package mondrian.mdx;
11
12 import mondrian.olap.*;
13 import mondrian.olap.type.Type;
14 import mondrian.calc.*;
15 import mondrian.calc.impl.AbstractListCalc;
16
17 import java.util.List JavaDoc;
18
19 /**
20  * Usage of a {@link mondrian.olap.NamedSet} in an MDX expression.
21  *
22  * @author jhyde
23  * @version $Id: //open/mondrian/src/main/mondrian/mdx/NamedSetExpr.java#10 $
24  * @since Sep 26, 2005
25  */

26 public class NamedSetExpr extends ExpBase implements Exp {
27     private final NamedSet namedSet;
28
29     /**
30      * Creates a usage of a named set.
31      *
32      * @param namedSet namedSet
33      * @pre NamedSet != null
34      */

35     public NamedSetExpr(NamedSet namedSet) {
36         Util.assertPrecondition(namedSet != null, "namedSet != null");
37         this.namedSet = namedSet;
38     }
39
40     /**
41      * Returns the named set.
42      *
43      * @post return != null
44      */

45     public NamedSet getNamedSet() {
46         return namedSet;
47     }
48
49     public String JavaDoc toString() {
50         return namedSet.getUniqueName();
51     }
52
53     public NamedSetExpr clone() {
54         return new NamedSetExpr(namedSet);
55     }
56
57     public int getCategory() {
58         return Category.Set;
59     }
60
61     public Exp accept(Validator validator) {
62         // A set is sometimes used in more than one cube. So, clone the
63
// expression and re-validate every time it is used.
64
//
65
// But keep the expression wrapped in a NamedSet, so that the
66
// expression is evaluated once per query. (We don't want the
67
// expression to be evaluated context-sensitive.)
68
NamedSet namedSet2 = namedSet.validate(validator);
69         if (namedSet2 == namedSet) {
70             return this;
71         }
72         return new NamedSetExpr(namedSet2);
73     }
74
75     public Calc accept(ExpCompiler compiler) {
76         return new AbstractListCalc(this, new Calc[] { /* todo: compile namedSet.getExp() */ }, false) {
77             public List JavaDoc evaluateList(Evaluator evaluator) {
78                 return (List JavaDoc) evaluator.evaluateNamedSet(
79                     namedSet.getName(), namedSet.getExp());
80             }
81
82             public boolean dependsOn(Dimension dimension) {
83                 // Given that a named set is never re-evaluated within the scope
84
// of a query, effectively it's independent of all dimensions.
85
return false;
86             }
87         };
88     }
89
90     public Object JavaDoc accept(MdxVisitor visitor) {
91         Object JavaDoc o = visitor.visit(this);
92         namedSet.getExp().accept(visitor);
93         return o;
94     }
95
96     public Type getType() {
97         return namedSet.getType();
98     }
99 }
100
101 // End NamedSetExpr.java
102
Popular Tags