KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > test > olap > TestMemberProperties


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  *
12  */

13 package com.tonbeller.jpivot.test.olap;
14
15 import java.util.ArrayList JavaDoc;
16 import java.util.HashMap JavaDoc;
17 import java.util.HashSet JavaDoc;
18 import java.util.Iterator JavaDoc;
19 import java.util.List JavaDoc;
20 import java.util.Set JavaDoc;
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 /**
29  * @author av
30  */

31 public class TestMemberProperties extends TestExtensionSupport implements MemberProperties {
32   boolean initialized = false;
33   boolean levelScope;
34
35   public String JavaDoc getId() {
36     return MemberProperties.ID;
37   }
38
39   /** maps level -> LevelProps */
40   HashMap JavaDoc levelMap = new HashMap JavaDoc();
41   static class LevelProps {
42     Set JavaDoc names = new HashSet JavaDoc();
43     List JavaDoc metas = new ArrayList JavaDoc();
44     boolean contains(String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc getPropertyScope(Member m) {
102     if (levelScope)
103       return m.getLevel().getLabel();
104     return m.getLevel().getHierarchy().getLabel();
105   }
106
107   /**
108    * @return
109    */

110   public boolean isLevelScope() {
111     return levelScope;
112   }
113
114   /**
115    * @param b
116    */

117   public void setLevelScope(boolean b) {
118     levelScope = b;
119   }
120
121   public void setVisibleProperties(MemberPropertyMeta[] props) {
122   }
123
124 }
125
Popular Tags