1 28 package net.sf.jasperreports.olap.xmla; 29 30 import java.util.ArrayList ; 31 import java.util.Iterator ; 32 import java.util.List ; 33 34 import net.sf.jasperreports.olap.result.JROlapHierarchy; 35 import net.sf.jasperreports.olap.result.JROlapMemberTuple; 36 import net.sf.jasperreports.olap.result.JROlapResultAxis; 37 38 39 43 public class JRXmlaResultAxis implements JROlapResultAxis 44 { 45 46 private final String axisName; 47 private final List hierarchyList; 48 private JRXmlaHierarchy[] hierarchies; 49 private final List tuples; 50 51 public JRXmlaResultAxis(String axisName) 52 { 53 this.axisName = axisName; 54 this.hierarchyList = new ArrayList (); 55 this.tuples = new ArrayList (); 56 } 57 58 public String getAxisName() 59 { 60 return axisName; 61 } 62 63 public JROlapHierarchy[] getHierarchiesOnAxis() 64 { 65 return ensureHierarchyArray(); 66 } 67 68 public JROlapMemberTuple getTuple(int index) 69 { 70 if (index < 0 || index >= tuples.size()) 71 { 72 throw new IndexOutOfBoundsException ("Index: " + index + ", Size: " + tuples.size()); 73 } 74 75 return (JROlapMemberTuple) tuples.get(index); 76 } 77 78 public int getTupleCount() 79 { 80 return tuples.size(); 81 } 82 83 public void addHierarchy(JRXmlaHierarchy hierarchy) 84 { 85 hierarchyList.add(hierarchy); 86 resetHierarchyArray(); 87 } 88 89 public void addTuple(JRXmlaMemberTuple tuple) 90 { 91 tuples.add(tuple); 92 93 copyLevelInfo(tuple); 94 } 95 96 protected void copyLevelInfo(JRXmlaMemberTuple tuple) 97 { 98 JRXmlaMember[] members = tuple.getXmlaMembers(); 99 int idx = 0; 100 for (Iterator it = hierarchyList.iterator(); it.hasNext() && idx < members.length; ++idx) 101 { 102 JRXmlaHierarchy hierarchy = (JRXmlaHierarchy) it.next(); 103 JRXmlaMember member = members[idx]; 104 if (hierarchy.getDimensionName().equals(member.getDimensionName())) 105 { 106 hierarchy.setLevel(member.getLevelName(), member.getDepth()); 107 } 108 } 109 110 } 111 112 protected JRXmlaHierarchy[] ensureHierarchyArray() 113 { 114 if (hierarchies == null) 115 { 116 hierarchies = new JRXmlaHierarchy[hierarchyList.size()]; 117 hierarchies = (JRXmlaHierarchy[]) hierarchyList.toArray(hierarchies); 118 } 119 return hierarchies; 120 } 121 122 protected void resetHierarchyArray() 123 { 124 hierarchies = null; 125 } 126 127 } 128 | Popular Tags |