1 28 package net.sf.jasperreports.olap.xmla; 29 30 import java.util.ArrayList ; 31 import java.util.List ; 32 33 import org.apache.commons.logging.Log; 34 import org.apache.commons.logging.LogFactory; 35 36 import net.sf.jasperreports.olap.result.JROlapHierarchy; 37 import net.sf.jasperreports.olap.result.JROlapHierarchyLevel; 38 39 40 44 public class JRXmlaHierarchy implements JROlapHierarchy 45 { 46 47 private final static Log log = LogFactory.getLog(JRXmlaHierarchy.class); 48 49 private final String dimensionName; 50 private final List levels; 51 private JRXmlaHierarchyLevel[] levelArray; 52 53 public JRXmlaHierarchy(String dimensionName) 54 { 55 this.dimensionName = dimensionName; 56 this.levels = new ArrayList (); 57 } 58 59 public String getDimensionName() 60 { 61 return dimensionName; 62 } 63 64 public JROlapHierarchyLevel[] getLevels() 65 { 66 return ensureLevelArray(); 67 } 68 69 public void setLevel(String levelName, int depth) 70 { 71 int levelCount = levels.size(); 72 if (depth >= levelCount) 73 { 74 for (int i = levelCount; i <= depth; ++i) 75 { 76 levels.add(null); 77 } 78 } 79 80 JRXmlaHierarchyLevel level = (JRXmlaHierarchyLevel) levels.get(depth); 81 if (level == null) 82 { 83 level = new JRXmlaHierarchyLevel(levelName, depth); 84 levels.set(depth, level); 85 } 86 else if (!levelName.equals(level.getName())) 87 { 88 if (log.isWarnEnabled()) 89 { 90 log.warn("Different level name \"" + levelName + "\" found for level \"" + level.getName() + "\" at depth " + depth); 91 } 92 } 93 94 resetLevelArray(); 95 } 96 97 protected JRXmlaHierarchyLevel[] ensureLevelArray() 98 { 99 if (levelArray == null) 100 { 101 levelArray = new JRXmlaHierarchyLevel[levels.size()]; 102 levelArray = (JRXmlaHierarchyLevel[]) levels.toArray(levelArray); 103 } 104 return levelArray; 105 } 106 107 protected void resetLevelArray() 108 { 109 levelArray = null; 110 } 111 } 112 | Popular Tags |