KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > mondrian > MondrianAxis


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 package com.tonbeller.jpivot.mondrian;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
16
17 import com.tonbeller.jpivot.olap.model.Axis;
18 import com.tonbeller.jpivot.olap.model.Hierarchy;
19 import com.tonbeller.jpivot.olap.model.Visitor;
20 import mondrian.olap.AxisOrdinal;
21 import mondrian.olap.Position;
22
23 /**
24  * MondrianAxis is an adapter class for the Result Mondrian Axis.
25  */

26 public class MondrianAxis implements Axis {
27
28   private mondrian.olap.Axis monAxis = null;
29   private MondrianModel model = null;
30   private ArrayList JavaDoc aPositions = null;
31   private MondrianHierarchy[] hierarchies = null;
32   private int ordinal; // -1 for slicer
33

34   /**
35    * Constructor
36    * @param monAxis Axis as defined in Mondrian
37    */

38   public MondrianAxis(int iOrdinal, mondrian.olap.Axis monAxis, MondrianModel model) {
39     this.ordinal = iOrdinal;
40     this.monAxis = monAxis;
41     this.model = model;
42
43     aPositions = new ArrayList JavaDoc();
44
45     if (iOrdinal >= 0) {
46       // it is not the slicer
47
// get hierarchies from mondrian query, rather than from result, which can be empty
48

49       MondrianQueryAdapter adapter = (MondrianQueryAdapter) model.getQueryAdapter();
50       mondrian.olap.Hierarchy[] monHiers = adapter.getMonQuery().getMdxHierarchiesOnAxis(
51         AxisOrdinal.forLogicalOrdinal(iOrdinal));
52       hierarchies = new MondrianHierarchy[monHiers.length];
53       for (int j = 0; j < hierarchies.length; j++) {
54         hierarchies[j] = model.lookupHierarchy(monHiers[j].getUniqueName());
55       }
56     }
57
58     List JavaDoc monPositions = monAxis.getPositions();
59     Iterator JavaDoc pit = monPositions.iterator();
60     int i = 0;
61     while (pit.hasNext()) {
62       Position monPosition = (Position) pit.next();
63       MondrianPosition position = new MondrianPosition(monPosition, iOrdinal, model);
64       aPositions.add(position);
65       if (iOrdinal == -1) {
66         // for the slicer, extract the hierarchies from the members
67

68         if (i == 0) {
69           // first position only, as all positions have same hierarchies
70
// create the hierarchies array
71
List JavaDoc l = new ArrayList JavaDoc();
72           Iterator JavaDoc mit = monPosition.iterator();
73           while (mit.hasNext()) {
74             mondrian.olap.Member monMember = (mondrian.olap.Member) mit.next();
75             l.add(model.lookupHierarchy(monMember.getHierarchy().getUniqueName()));
76           }
77           hierarchies = (MondrianHierarchy[])
78                 l.toArray(new MondrianHierarchy[l.size()]);
79         }
80       }
81       i++;
82     }
83
84   }
85
86   /**
87    * @see com.tonbeller.jpivot.olap.model.Axis#getPositions()
88    */

89   public List JavaDoc getPositions() {
90     return aPositions;
91   }
92
93   /**
94    * @see com.tonbeller.jpivot.olap.model.Axis#getHierarchies()
95    */

96   public Hierarchy[] getHierarchies() {
97     return hierarchies;
98   }
99
100   /**
101    * @see com.tonbeller.jpivot.olap.model.Visitable#accept(Visitor)
102    */

103   public void accept(Visitor visitor) {
104     visitor.visitAxis(this);
105   }
106
107   public Object JavaDoc getRootDecoree() {
108     return this;
109   }
110
111   /**
112    * Returns the ordinal.
113    * @return int
114    */

115   public int getOrdinal() {
116     return ordinal;
117   }
118
119 } // MondrianAxis
120
Popular Tags