KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > olap > LevelBase


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/olap/LevelBase.java#19 $
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  * Skeleton implementation of {@link Level}
20  *
21  * @author jhyde
22  * @since 6 August, 2001
23  * @version $Id: //open/mondrian/src/main/mondrian/olap/LevelBase.java#19 $
24  */

25 public abstract class LevelBase
26     extends OlapElementBase
27     implements Level {
28
29     protected final Hierarchy hierarchy;
30     protected final String JavaDoc name;
31     protected final String JavaDoc uniqueName;
32     protected String JavaDoc description;
33     protected final int depth;
34     protected final LevelType levelType;
35     protected MemberFormatter memberFormatter;
36     protected int approxRowCount;
37
38     protected LevelBase(
39             Hierarchy hierarchy,
40             String JavaDoc name,
41             int depth,
42             LevelType levelType) {
43         this.hierarchy = hierarchy;
44         this.name = name;
45         this.uniqueName = Util.makeFqName(hierarchy, name);
46         this.depth = depth;
47         this.levelType = levelType;
48     }
49
50     /**
51      * Sets the approximate number of members in this Level.
52      * @see #getApproxRowCount()
53      */

54     public void setApproxRowCount(int approxRowCount) {
55         this.approxRowCount = approxRowCount;
56     }
57
58     // from Element
59
public String JavaDoc getQualifiedName() {
60         return MondrianResource.instance().MdxLevelName.str(getUniqueName());
61     }
62
63     public LevelType getLevelType() {
64         return levelType;
65     }
66
67     public String JavaDoc getUniqueName() {
68         return uniqueName;
69     }
70
71     public String JavaDoc getName() {
72         return name;
73     }
74
75     public String JavaDoc getDescription() {
76         return description;
77     }
78
79     public Hierarchy getHierarchy() {
80         return hierarchy;
81     }
82
83     public Dimension getDimension() {
84         return hierarchy.getDimension();
85     }
86
87     public int getDepth() {
88         return depth;
89     }
90
91     public Level getChildLevel() {
92         int childDepth = depth + 1;
93         Level[] levels = hierarchy.getLevels();
94         return (childDepth < levels.length)
95             ? levels[childDepth]
96             : null;
97     }
98
99     public Level getParentLevel() {
100         int parentDepth = depth - 1;
101         Level[] levels = hierarchy.getLevels();
102         return (parentDepth >= 0)
103             ? levels[parentDepth]
104             : null;
105     }
106
107     public abstract boolean isAll();
108
109     public boolean isMeasure() {
110         return hierarchy.getName().equals("Measures");
111     }
112
113     public OlapElement lookupChild(SchemaReader schemaReader, String JavaDoc s) {
114         return lookupChild(schemaReader, s, MatchType.EXACT);
115     }
116
117     public OlapElement lookupChild(
118         SchemaReader schemaReader, String JavaDoc s, MatchType matchType)
119     {
120         return areMembersUnique()
121             ? Util.lookupHierarchyRootMember(
122                 schemaReader, hierarchy, s, matchType)
123             : null;
124     }
125
126     /**
127       * Returns the object which is used to format members of this level.
128       */

129     public MemberFormatter getMemberFormatter() {
130         return memberFormatter;
131     }
132 }
133
134
135 // End LevelBase.java
136
Popular Tags