KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > olap > CubeBase


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/olap/CubeBase.java#24 $
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) 2001-2002 Kana Software, Inc.
7 // Copyright (C) 2001-2006 Julian Hyde and others
8 // All Rights Reserved.
9 // You must accept the terms of that agreement to use this software.
10 //
11 // jhyde, 6 August, 2001
12 */

13
14 package mondrian.olap;
15
16 import mondrian.resource.MondrianResource;
17
18 /**
19  * <code>CubeBase</code> is an abstract implementation of {@link Cube}.
20  *
21  * @author jhyde
22  * @since 6 August, 2001
23  * @version $Id: //open/mondrian/src/main/mondrian/olap/CubeBase.java#24 $
24  */

25 public abstract class CubeBase extends OlapElementBase implements Cube {
26
27     /** constraints indexes for adSchemaMembers
28      *
29      * http://msdn.microsoft.com/library/psdk/dasdk/mdx8h4k.htm
30      * check "Restrictions in the MEMBER Rowset" under MEMBER Rowset section
31      */

32     public static final int CATALOG_NAME = 0;
33     public static final int SCHEMA_NAME = 1;
34     public static final int CUBE_NAME = 2;
35     public static final int DIMENSION_UNIQUE_NAME = 3;
36     public static final int HIERARCHY_UNIQUE_NAME = 4;
37     public static final int LEVEL_UNIQUE_NAME = 5;
38     public static final int LEVEL_NUMBER = 6;
39     public static final int MEMBER_NAME = 7;
40     public static final int MEMBER_UNIQUE_NAME = 8;
41     public static final int MEMBER_CAPTION = 9;
42     public static final int MEMBER_TYPE = 10;
43     public static final int Tree_Operator = 11;
44     public static final int maxNofConstraintsForAdSchemaMember = 12;
45     public static final int MDTREEOP_SELF = 0;
46     public static final int MDTREEOP_CHILDREN = 1;
47     public static final int MDPROP_USERDEFINED0 = 19;
48
49     protected final String JavaDoc name;
50     protected Dimension[] dimensions;
51
52     protected CubeBase(String JavaDoc name, Dimension[] dimensions) {
53         this.name = name;
54         this.dimensions = dimensions;
55     }
56
57     // implement OlapElement
58
public String JavaDoc getName() {
59         return name;
60     }
61
62     public String JavaDoc getUniqueName() {
63         return name;
64     }
65
66     public String JavaDoc getQualifiedName() {
67         return MondrianResource.instance().MdxCubeName.str(getName());
68     }
69
70     public Dimension getDimension() {
71         return null;
72     }
73
74     public Hierarchy getHierarchy() {
75         return null;
76     }
77
78     public String JavaDoc getDescription() {
79         return null;
80     }
81
82     public Dimension[] getDimensions() {
83         return dimensions;
84     }
85
86     public Hierarchy lookupHierarchy(String JavaDoc s, boolean unique) {
87         for (Dimension dimension : dimensions) {
88             Hierarchy[] hierarchies = dimension.getHierarchies();
89             for (Hierarchy hierarchy : hierarchies) {
90                 String JavaDoc name = unique
91                     ? hierarchy.getUniqueName() : hierarchy.getName();
92                 if (name.equals(s)) {
93                     return hierarchy;
94                 }
95             }
96         }
97         return null;
98     }
99
100     public OlapElement lookupChild(SchemaReader schemaReader, String JavaDoc s)
101     {
102         return lookupChild(schemaReader, s, MatchType.EXACT);
103     }
104
105     public OlapElement lookupChild(
106         SchemaReader schemaReader, String JavaDoc s, MatchType matchType)
107     {
108         Dimension mdxDimension = (Dimension)lookupDimension(s);
109         if (mdxDimension != null) {
110             return mdxDimension;
111         }
112
113         //maybe this is not a dimension - maybe it's hierarchy, level or name
114
for (Dimension dimension : dimensions) {
115             OlapElement mdxElement = dimension.lookupChild(
116                 schemaReader, s, matchType);
117             if (mdxElement != null) {
118                 return mdxElement;
119             }
120         }
121         return null;
122     }
123
124     public Dimension getTimeDimension() {
125         for (Dimension dimension : dimensions) {
126             if (dimension.getDimensionType() ==
127                 DimensionType.TimeDimension) {
128                 return dimension;
129             }
130         }
131
132         return null;
133     }
134
135     public OlapElement lookupDimension(String JavaDoc s) {
136         for (Dimension dimension : dimensions) {
137             if (dimension.getName().equalsIgnoreCase(s)) {
138                 return dimension;
139             }
140         }
141         return null;
142     }
143
144     // ------------------------------------------------------------------------
145

146     private Level getTimeLevel(LevelType levelType) {
147         for (Dimension dimension : dimensions) {
148             if (dimension.getDimensionType() == DimensionType.TimeDimension) {
149                 Hierarchy[] hierarchies = dimension.getHierarchies();
150                 for (Hierarchy hierarchy : hierarchies) {
151                     Level[] levels = hierarchy.getLevels();
152                     for (Level level : levels) {
153                         if (level.getLevelType() == levelType) {
154                             return level;
155                         }
156                     }
157                 }
158             }
159         }
160         return null;
161     }
162
163     public Level getYearLevel() {
164         return getTimeLevel(LevelType.TimeYears);
165     }
166
167     public Level getQuarterLevel() {
168         return getTimeLevel(LevelType.TimeQuarters);
169     }
170
171     public Level getMonthLevel() {
172         return getTimeLevel(LevelType.TimeMonths);
173     }
174
175     public Level getWeekLevel() {
176         return getTimeLevel(LevelType.TimeWeeks);
177     }
178
179 }
180
181
182 // End CubeBase.java
183
Popular Tags