KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > olap > type > DimensionType


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

10 package mondrian.olap.type;
11
12 import mondrian.olap.Dimension;
13 import mondrian.olap.Hierarchy;
14 import mondrian.olap.Level;
15
16 /**
17  * The type of an expression which represents a Dimension.
18  *
19  * @author jhyde
20  * @since Feb 17, 2005
21  * @version $Id: //open/mondrian/src/main/mondrian/olap/type/DimensionType.java#6 $
22  */

23 public class DimensionType implements Type {
24     private final Dimension dimension;
25     private final String JavaDoc digest;
26
27     public static final DimensionType Unknown = new DimensionType(null);
28
29     /**
30      * Creates a type representing a dimension.
31      *
32      * @param dimension Dimension that values of this type must belong to.
33      * Null if the dimension is unknown.
34      */

35     public DimensionType(Dimension dimension) {
36         this.dimension = dimension;
37         StringBuilder JavaDoc buf = new StringBuilder JavaDoc("DimensionType<");
38         if (dimension != null) {
39             buf.append("dimension=").append(dimension.getUniqueName());
40         }
41         buf.append(">");
42         this.digest = buf.toString();
43     }
44
45     public static DimensionType forDimension(Dimension dimension) {
46         return new DimensionType(dimension);
47     }
48
49     public static DimensionType forType(Type type) {
50         return new DimensionType(type.getDimension());
51     }
52
53     public boolean usesDimension(Dimension dimension, boolean maybe) {
54         return this.dimension == dimension ||
55                 (maybe && this.dimension == null);
56     }
57
58     public Hierarchy getHierarchy() {
59         return dimension == null ?
60                 null :
61                 dimension.getHierarchies().length > 1 ?
62                 null :
63                 dimension.getHierarchies()[0];
64     }
65
66     public Level getLevel() {
67         return null;
68     }
69
70     public Dimension getDimension() {
71         return dimension;
72     }
73
74     public String JavaDoc toString() {
75         return digest;
76     }
77 }
78
79 // End DimensionType.java
80
Popular Tags