KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > xmla > XMLA_Hierarchy


1 /*
2  * ====================================================================
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) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.jpivot.xmla;
14
15 import java.util.ArrayList JavaDoc;
16
17 import org.apache.log4j.Logger;
18
19 import com.tonbeller.jpivot.olap.mdxparse.CompoundId;
20 import com.tonbeller.jpivot.olap.mdxparse.Exp;
21 import com.tonbeller.jpivot.olap.mdxparse.ExpVisitor;
22 import com.tonbeller.jpivot.olap.model.Dimension;
23 import com.tonbeller.jpivot.olap.model.Hierarchy;
24 import com.tonbeller.jpivot.olap.model.Level;
25 import com.tonbeller.jpivot.olap.model.Member;
26 import com.tonbeller.jpivot.olap.model.OlapException;
27 import com.tonbeller.jpivot.olap.model.Visitor;
28 import com.tonbeller.jpivot.olap.query.MDXElement;
29 import com.tonbeller.jpivot.util.StringUtil;
30
31 /**
32  * Hierarchy for XMLA
33  */

34 public class XMLA_Hierarchy implements Hierarchy,Exp,MDXElement {
35
36   static Logger logger = Logger.getLogger(XMLA_Hierarchy.class);
37
38   private String JavaDoc dimUniqueName;
39   private String JavaDoc uniqueName;
40   private String JavaDoc caption;
41   private int dimType;
42   private int cardinality;
43   private String JavaDoc defaultMember;
44   private String JavaDoc allMember;
45   private XMLA_Model model;
46
47   // could not find documentation on the following "defines"
48
// probably NOT supported by SAP
49
public static final int STRUCTURE_FULLYBALANCED = 0;
50   public static final int STRUCTURE_RAGGEDBALANCED = 1; // ??
51
public static final int STRUCTURE_UNBALANCED = 2; // ?? example: Foodmart.HR.Employee
52
private int structure = 0;
53
54   private boolean isVirtual;
55   private boolean isReadWrite;
56   private int dimUniqueSettings;
57   private boolean isDimVisible;
58   private int ordinal;
59   private boolean isDimShared;
60
61   private boolean isMembersGotten = false;
62
63   private Dimension dimension = null;
64
65   private ArrayList JavaDoc aLevels = new ArrayList JavaDoc();
66
67   public XMLA_Hierarchy( XMLA_Model model) {
68     this.model = model;
69   }
70   
71   /**
72    * Returns the allMember.
73    * @return String
74    */

75   public String JavaDoc getAllMemberName() {
76     return allMember;
77   }
78
79   /**
80    * Returns the allMember.
81    * @return Member
82    */

83   public Member getAllMember() {
84     if (allMember == null)
85       return null;
86     Member mAll = model.lookupMemberByUName(allMember);
87     if (mAll != null)
88       return mAll;
89     try {
90       // the all member was not retrieved yet
91
model.retrieveMember(allMember);
92     } catch (OlapException e) {
93       // should not occur
94
logger.error("could not retrieve member " + allMember, e);
95     }
96     return model.lookupMemberByUName(allMember);
97   }
98
99   /**
100    * Returns the caption.
101    * @return String
102    */

103   public String JavaDoc getCaption() {
104     return caption;
105   }
106
107   /**
108    * Returns the cardinality.
109    * @return int
110    */

111   public int getCardinality() {
112     return cardinality;
113   }
114
115   /**
116    * Returns the defaultMember.
117    * @return String
118    */

119   public String JavaDoc getDefaultMember() {
120     return defaultMember;
121   }
122
123   /**
124    * Returns the dimType.
125    * @return int
126    */

127   public int getDimType() {
128     return dimType;
129   }
130
131   /**
132    * Returns the dimUniqueName.
133    * @return String
134    */

135   public String JavaDoc getDimUniqueName() {
136     return dimUniqueName;
137   }
138
139   /**
140    * Returns the dimUniqueSettings.
141    * @return int
142    */

143   public int getDimUniqueSettings() {
144     return dimUniqueSettings;
145   }
146
147   /**
148    * Returns the isDimShared.
149    * @return boolean
150    */

151   public boolean isDimShared() {
152     return isDimShared;
153   }
154
155   /**
156    * Returns the isDimVisible.
157    * @return boolean
158    */

159   public boolean isDimVisible() {
160     return isDimVisible;
161   }
162
163   /**
164    * Returns the isReadWrite.
165    * @return boolean
166    */

167   public boolean isReadWrite() {
168     return isReadWrite;
169   }
170
171   /**
172    * Returns the isVirtual.
173    * @return boolean
174    */

175   public boolean isVirtual() {
176     return isVirtual;
177   }
178
179   /**
180    * Returns the ordinal.
181    * @return int
182    */

183   public int getOrdinal() {
184     return ordinal;
185   }
186
187   /**
188    * Returns the structure.
189    * @return int
190    */

191   public int getStructure() {
192     return structure;
193   }
194
195   /**
196    * Returns the uniqueName.
197    * @return String
198    */

199   public String JavaDoc getUniqueName() {
200     return uniqueName;
201   }
202
203   /**
204    * Sets the allMember.
205    * @param allMember The allMember to set
206    */

207   public void setAllMember(String JavaDoc allMember) {
208     this.allMember = allMember;
209   }
210
211   /**
212    * Sets the caption.
213    * @param caption The caption to set
214    */

215   public void setCaption(String JavaDoc caption) {
216     this.caption = caption;
217   }
218
219   /**
220    * Sets the cardinality.
221    * @param cardinality The cardinality to set
222    */

223   public void setCardinality(int cardinality) {
224     this.cardinality = cardinality;
225   }
226
227   /**
228    * Sets the defaultMember.
229    * @param defaultMember The defaultMember to set
230    */

231   public void setDefaultMember(String JavaDoc defaultMember) {
232     this.defaultMember = defaultMember;
233   }
234
235   /**
236    * Sets the dimType.
237    * @param dimType The dimType to set
238    */

239   public void setDimType(int dimType) {
240     this.dimType = dimType;
241   }
242
243   /**
244    * Sets the dimUniqueName.
245    * @param dimUniqueName The dimUniqueName to set
246    */

247   public void setDimUniqueName(String JavaDoc dimUniqueName) {
248     this.dimUniqueName = dimUniqueName;
249   }
250
251   /**
252    * Sets the dimUniqueSettings.
253    * @param dimUniqueSettings The dimUniqueSettings to set
254    */

255   public void setDimUniqueSettings(int dimUniqueSettings) {
256     this.dimUniqueSettings = dimUniqueSettings;
257   }
258
259   /**
260    * Sets the isDimShared.
261    * @param isDimShared The isDimShared to set
262    */

263   public void setDimShared(boolean isDimShared) {
264     this.isDimShared = isDimShared;
265   }
266
267   /**
268    * Sets the isDimVisible.
269    * @param isDimVisible The isDimVisible to set
270    */

271   public void setDimVisible(boolean isDimVisible) {
272     this.isDimVisible = isDimVisible;
273   }
274
275   /**
276    * Sets the isReadWrite.
277    * @param isReadWrite The isReadWrite to set
278    */

279   public void setReadWrite(boolean isReadWrite) {
280     this.isReadWrite = isReadWrite;
281   }
282
283   /**
284    * Sets the isVirtual.
285    * @param isVirtual The isVirtual to set
286    */

287   public void setVirtual(boolean isVirtual) {
288     this.isVirtual = isVirtual;
289   }
290
291   /**
292    * Sets the ordinal.
293    * @param ordinal The ordinal to set
294    */

295   public void setOrdinal(int ordinal) {
296     this.ordinal = ordinal;
297   }
298
299   /**
300    * Sets the structure.
301    * @param structure The structure to set
302    */

303   public void setStructure(int structure) {
304     this.structure = structure;
305   }
306
307   /**
308    * Sets the uniqueName.
309    * @param uniqueName The uniqueName to set
310    */

311   public void setUniqueName(String JavaDoc uniqueName) {
312     this.uniqueName = uniqueName;
313   }
314
315   /**
316    * @see com.tonbeller.jpivot.olap.model.Hierarchy#getDimension()
317    */

318   public Dimension getDimension() {
319     return dimension;
320   }
321
322   /**
323    * @see com.tonbeller.jpivot.olap.model.Hierarchy#getLevels()
324    */

325   public Level[] getLevels() {
326     return (Level[]) aLevels.toArray(new XMLA_Level[0]);
327   }
328   /**
329    * @see com.tonbeller.jpivot.olap.model.Displayable#getLabel()
330    */

331   public String JavaDoc getLabel() {
332     return caption;
333   }
334
335   /**
336    * @see com.tonbeller.jpivot.olap.model.Visitable#accept(Visitor)
337    */

338   public void accept(Visitor visitor) {
339     visitor.visitHierarchy(this);
340   }
341
342   /**
343    * @see com.tonbeller.jpivot.olap.model.Decorator#getRootDecoree()
344    */

345   public Object JavaDoc getRootDecoree() {
346     return this;
347   }
348
349   /**
350    * Sets the dimension.
351    * @param dimension The dimension to set
352    */

353   public void setDimension(Dimension dimension) {
354     this.dimension = dimension;
355   }
356
357   /**
358    * add level for this hierarchy
359    * @param lev
360    */

361   public void addLevel(Level lev) {
362     aLevels.add(lev);
363   }
364
365   /**
366    *
367    * @param other
368    * @return boolean
369    */

370   public boolean isEqual(XMLA_Hierarchy other) {
371     return (this.getUniqueName().equals(other.getUniqueName()));
372   }
373
374   /**
375    * Returns the isMembersGotten.
376    * @return boolean
377    */

378   protected boolean isMembersGotten() {
379     return isMembersGotten;
380   }
381
382   /**
383    * Sets the isMembersGotten.
384    * @param isMembersGotten The isMembersGotten to set
385    */

386   protected void setMembersGotten(boolean isMembersGotten) {
387     this.isMembersGotten = isMembersGotten;
388   }
389
390   /**
391     * @return the unique name
392     */

393    public String JavaDoc toMdx() {
394      return this.uniqueName;
395    }
396
397    /**
398     * @see com.tonbeller.jpivot.olap.mdxparse.Exp#clone()
399     * probably not needed any more
400     */

401    public Object JavaDoc clone() {
402      String JavaDoc[] nameParts = StringUtil.splitUniqueName(uniqueName);
403      CompoundId clone = new CompoundId(nameParts[0], false);
404      for (int i = 1; i < nameParts.length; i++) {
405        clone.append(nameParts[i], false);
406      }
407      return clone;
408    }
409
410   /**
411     * @see com.tonbeller.jpivot.olap.mdxparse.Exp#accept
412     */

413    public void accept(ExpVisitor visitor) {
414      visitor.visitHierarchy(this);
415    }
416   public boolean hasAll() {
417     return allMember != null;
418   }
419 } // End XMLA_Hierarchy
420
Popular Tags