KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/olap/type/HierarchyType.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.Hierarchy;
13 import mondrian.olap.Dimension;
14 import mondrian.olap.Level;
15
16 /**
17  * The type of an expression which represents a hierarchy.
18  *
19  * @author jhyde
20  * @since Feb 17, 2005
21  * @version $Id: //open/mondrian/src/main/mondrian/olap/type/HierarchyType.java#6 $
22  */

23 public class HierarchyType implements Type {
24     private final Dimension dimension;
25     private final Hierarchy hierarchy;
26     private final String JavaDoc digest;
27
28     /**
29      * Creates a type representing a hierarchy.
30      */

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