KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > olap > DimensionBase


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

25 public abstract class DimensionBase
26     extends OlapElementBase
27     implements Dimension {
28
29     protected final String JavaDoc name;
30     protected final String JavaDoc uniqueName;
31     protected final String JavaDoc description;
32     protected final int globalOrdinal;
33     protected Hierarchy[] hierarchies;
34     protected DimensionType dimensionType;
35
36     protected DimensionBase(
37             String JavaDoc name,
38             int globalOrdinal,
39             DimensionType dimensionType)
40     {
41         this.name = name;
42         this.uniqueName = Util.makeFqName(name);
43         this.description = null;
44         this.globalOrdinal = globalOrdinal;
45         this.dimensionType = dimensionType;
46     }
47
48     public String JavaDoc getUniqueName() {
49         return uniqueName;
50     }
51
52     public String JavaDoc getName() {
53         return name;
54     }
55
56     public String JavaDoc getDescription() {
57         return description;
58     }
59
60     public Hierarchy[] getHierarchies() {
61         return hierarchies;
62     }
63
64     public Hierarchy getHierarchy() {
65         return hierarchies[0];
66     }
67
68     public Dimension getDimension() {
69         return this;
70     }
71
72     public DimensionType getDimensionType() {
73         return dimensionType;
74     }
75
76     public String JavaDoc getQualifiedName() {
77         return MondrianResource.instance().MdxDimensionName.str(getUniqueName());
78     }
79
80     public boolean isMeasures() {
81         return getUniqueName().equals(MEASURES_UNIQUE_NAME);
82     }
83
84     public boolean usesDimension(Dimension dimension) {
85         return dimension == this;
86     }
87
88     public OlapElement lookupChild(SchemaReader schemaReader, String JavaDoc s)
89     {
90         return lookupChild(schemaReader, s, MatchType.EXACT);
91     }
92
93     public OlapElement lookupChild(
94         SchemaReader schemaReader, String JavaDoc s, MatchType matchType)
95     {
96         OlapElement oe = lookupHierarchy(s);
97
98         // If the user is looking for [Marital Status].[Marital Status] we
99
// should not return oe "Marital Status", because he is
100
// looking for level - we can check that by checking of hierarchy and
101
// dimension name is the same.
102
if ((oe == null) || oe.getName().equalsIgnoreCase(getName()) ) {
103             OlapElement oeLevel =
104                 getHierarchy().lookupChild(schemaReader, s, matchType);
105             if (oeLevel != null)
106                 oe = oeLevel; // level match overrides hierarchy match
107
}
108
109         if (getLogger().isDebugEnabled()) {
110             StringBuilder JavaDoc buf = new StringBuilder JavaDoc(64);
111             buf.append("DimensionBase.lookupChild: ");
112             buf.append("name=");
113             buf.append(getName());
114             buf.append(", childname=");
115             buf.append(s);
116             if (oe == null) {
117                 buf.append(" returning null");
118             } else {
119                 buf.append(" returning elementname="+oe.getName());
120             }
121             getLogger().debug(buf.toString());
122         }
123
124         return oe;
125     }
126
127     private Hierarchy lookupHierarchy(String JavaDoc s) {
128         for (Hierarchy hierarchy : hierarchies) {
129             if (hierarchy.getName().equalsIgnoreCase(s)) {
130                 return hierarchy;
131             }
132         }
133         return null;
134     }
135 }
136
137
138 // End DimensionBase.java
139
Popular Tags