KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > mdx > DimensionExpr


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/mdx/DimensionExpr.java#5 $
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.DimensionType;
14 import mondrian.olap.type.Type;
15 import mondrian.calc.*;
16 import mondrian.calc.impl.ConstantCalc;
17
18 /**
19  * Usage of a {@link mondrian.olap.Dimension} as an MDX expression.
20  *
21  * @author jhyde
22  * @version $Id: //open/mondrian/src/main/mondrian/mdx/DimensionExpr.java#5 $
23  * @since Sep 26, 2005
24  */

25 public class DimensionExpr extends ExpBase implements Exp {
26     private final Dimension dimension;
27
28     /**
29      * Creates a dimension expression.
30      *
31      * @param dimension Dimension
32      * @pre dimension != null
33      */

34     public DimensionExpr(Dimension dimension) {
35         Util.assertPrecondition(dimension != null, "dimension != null");
36         this.dimension = dimension;
37     }
38
39     /**
40      * Returns the dimension.
41      *
42      * @post return != null
43      */

44     public Dimension getDimension() {
45         return dimension;
46     }
47
48     public String JavaDoc toString() {
49         return dimension.getUniqueName();
50     }
51
52     public Type getType() {
53         return DimensionType.forDimension(dimension);
54     }
55
56     public DimensionExpr clone() {
57         return new DimensionExpr(dimension);
58     }
59
60     public int getCategory() {
61         return Category.Dimension;
62     }
63
64     public Exp accept(Validator validator) {
65         return this;
66     }
67
68     public Calc accept(ExpCompiler compiler) {
69         return ConstantCalc.constantDimension(dimension);
70     }
71
72     public Object JavaDoc accept(MdxVisitor visitor) {
73         return visitor.visit(this);
74     }
75
76 }
77
78 // End DimensionExpr.java
79
Popular Tags