KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > olap > HierarchyBase


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

25 public abstract class HierarchyBase
26     extends OlapElementBase
27     implements Hierarchy {
28
29     protected final Dimension dimension;
30     /**
31      * <code>name</code> and <code>subName</code> are the name of the
32      * hierarchy, respectively containing and not containing dimension
33      * name. For example:
34      * <table>
35      * <tr> <th>uniqueName</th> <th>name</th> <th>subName</th></tr>
36      * <tr> <td>[Time.Weekly]</td> <td>Time.Weekly</td> <td>Weekly</td></tr>
37      * <tr> <td>[Customers]</td> <td>Customers</td> <td>null</td></tr>
38      * </table>
39      */

40     protected final String JavaDoc subName;
41     protected final String JavaDoc name;
42     protected final String JavaDoc uniqueName;
43     protected String JavaDoc description;
44     protected Level[] levels;
45     protected final boolean hasAll;
46     protected String JavaDoc allMemberName;
47     protected String JavaDoc allLevelName;
48
49     protected HierarchyBase(Dimension dimension,
50                             String JavaDoc subName,
51                             boolean hasAll) {
52         this.dimension = dimension;
53         this.hasAll = hasAll;
54         setCaption(dimension.getCaption());
55
56         this.subName = subName;
57         String JavaDoc name = dimension.getName();
58         if (this.subName != null) {
59             // e.g. "Time.Weekly"
60
this.name = name + "." + subName;
61             // e.g. "[Time.Weekly]"
62
this.uniqueName = Util.makeFqName(this.name);
63         } else {
64             // e.g. "Time"
65
this.name = name;
66             // e.g. "[Time]"
67
this.uniqueName = dimension.getUniqueName();
68         }
69     }
70
71     // implement MdxElement
72
public String JavaDoc getUniqueName() {
73         return uniqueName;
74     }
75
76     public String JavaDoc getName() {
77         return name;
78     }
79
80     public String JavaDoc getQualifiedName() {
81         return MondrianResource.instance().MdxHierarchyName.str(getUniqueName());
82     }
83
84     public abstract boolean isRagged();
85
86     public String JavaDoc getDescription() {
87         return description;
88     }
89
90     public Dimension getDimension() {
91         return dimension;
92     }
93
94     public Level[] getLevels() {
95         return levels;
96     }
97
98     public Hierarchy getHierarchy() {
99         return this;
100     }
101
102     public boolean hasAll() {
103         return hasAll;
104     }
105
106     public boolean equals(OlapElement mdxElement) {
107         // Use object identity, because a private hierarchy can have the same
108
// name as a public hierarchy.
109
return (this == mdxElement);
110     }
111
112     public OlapElement lookupChild(SchemaReader schemaReader, String JavaDoc s) {
113         return lookupChild(schemaReader, s, MatchType.EXACT);
114     }
115
116     public OlapElement lookupChild(
117         SchemaReader schemaReader, String JavaDoc s, MatchType matchType)
118     {
119         OlapElement oe = Util.lookupHierarchyLevel(this, s);
120         if (oe == null) {
121             oe = Util.lookupHierarchyRootMember(
122                 schemaReader, this, s, matchType);
123         }
124         if (getLogger().isDebugEnabled()) {
125             StringBuilder JavaDoc buf = new StringBuilder JavaDoc(64);
126             buf.append("HierarchyBase.lookupChild: ");
127             buf.append("name=");
128             buf.append(getName());
129             buf.append(", childname=");
130             buf.append(s);
131             if (oe == null) {
132                 buf.append(" returning null");
133             } else {
134                 buf.append(" returning elementname="+oe.getName());
135             }
136             getLogger().debug(buf.toString());
137         }
138         return oe;
139     }
140
141     public String JavaDoc getAllMemberName() {
142         return allMemberName;
143     }
144 }
145
146 // End HierarchyBase.java
147
Popular Tags