1 13 package com.tonbeller.jpivot.test.olap; 14 15 import java.util.ArrayList ; 16 import java.util.HashMap ; 17 import java.util.HashSet ; 18 import java.util.Iterator ; 19 import java.util.List ; 20 import java.util.Set ; 21 22 import com.tonbeller.jpivot.olap.model.Level; 23 import com.tonbeller.jpivot.olap.model.Member; 24 import com.tonbeller.jpivot.olap.model.MemberPropertyMeta; 25 import com.tonbeller.jpivot.olap.model.Property; 26 import com.tonbeller.jpivot.olap.navi.MemberProperties; 27 28 31 public class TestMemberProperties extends TestExtensionSupport implements MemberProperties { 32 boolean initialized = false; 33 boolean levelScope; 34 35 public String getId() { 36 return MemberProperties.ID; 37 } 38 39 40 HashMap levelMap = new HashMap (); 41 static class LevelProps { 42 Set names = new HashSet (); 43 List metas = new ArrayList (); 44 boolean contains(String name) { 45 return names.contains(name); 46 } 47 void add(MemberPropertyMeta m) { 48 names.add(m.getName()); 49 metas.add(m); 50 } 51 MemberPropertyMeta[] toArray() { 52 return (MemberPropertyMeta[]) metas.toArray(new MemberPropertyMeta[metas.size()]); 53 } 54 } 55 56 void initialize() { 57 initialized = true; 58 for (int i = 0; i < model().getDimensions().length; i++) { 59 TestDimension dim = (TestDimension) model().getDimensions()[i]; 60 for (int j = 0; j < dim.getHierarchies().length; j++) { 61 TestHierarchy th = (TestHierarchy) dim.getHierarchies()[j]; 62 for (int k = 0; k < th.getRootMembers().length; k++) { 63 recurse(th.getRootMembers()[k]); 64 } 65 } 66 } 67 } 68 69 private void recurse(TestMember member) { 70 Property[] p = member.getProperties(); 71 String scope = getPropertyScope(member); 72 Level level = member.getLevel(); 73 LevelProps levelProps = (LevelProps) levelMap.get(level); 74 if (levelProps == null) { 75 levelProps = new LevelProps(); 76 levelMap.put(level, levelProps); 77 } 78 79 for (int i = 0; i < p.length; i++) { 80 if (!levelProps.contains(p[i].getName())) { 81 MemberPropertyMeta pm = new MemberPropertyMeta(); 82 pm.setName(p[i].getName()); 83 pm.setLabel(p[i].getName()); 84 pm.setScope(scope); 85 levelProps.add(pm); 86 } 87 } 88 89 for (Iterator it = member.getChildMember().iterator(); it.hasNext();) 90 recurse((TestMember) it.next()); 91 } 92 93 public MemberPropertyMeta[] getMemberPropertyMetas(Level level) { 94 if (!initialized) { 95 initialize(); 96 } 97 LevelProps levelProps = (LevelProps) levelMap.get(level); 98 return levelProps.toArray(); 99 } 100 101 public String getPropertyScope(Member m) { 102 if (levelScope) 103 return m.getLevel().getLabel(); 104 return m.getLevel().getHierarchy().getLabel(); 105 } 106 107 110 public boolean isLevelScope() { 111 return levelScope; 112 } 113 114 117 public void setLevelScope(boolean b) { 118 levelScope = b; 119 } 120 121 public void setVisibleProperties(MemberPropertyMeta[] props) { 122 } 123 124 } 125 | Popular Tags |