1 11 package com.tonbeller.jpivot.mondrian; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 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 26 public class MondrianAxis implements Axis { 27 28 private mondrian.olap.Axis monAxis = null; 29 private MondrianModel model = null; 30 private ArrayList aPositions = null; 31 private MondrianHierarchy[] hierarchies = null; 32 private int ordinal; 34 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 (); 44 45 if (iOrdinal >= 0) { 46 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 monPositions = monAxis.getPositions(); 59 Iterator 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 68 if (i == 0) { 69 List l = new ArrayList (); 72 Iterator 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 89 public List getPositions() { 90 return aPositions; 91 } 92 93 96 public Hierarchy[] getHierarchies() { 97 return hierarchies; 98 } 99 100 103 public void accept(Visitor visitor) { 104 visitor.visitAxis(this); 105 } 106 107 public Object getRootDecoree() { 108 return this; 109 } 110 111 115 public int getOrdinal() { 116 return ordinal; 117 } 118 119 } | Popular Tags |