KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.tonbeller.jpivot.olap.model.Hierarchy;
16 import com.tonbeller.jpivot.olap.model.impl.LevelImpl;
17
18 /**
19  * Created on 22.10.2002
20  *
21  * @author av
22  */

23 public class DimensionBuilder {
24   String JavaDoc hierName;
25   String JavaDoc[] levelNames;
26   int[] childCount;
27
28   LevelImpl[] levels;
29
30   public TestDimension build(String JavaDoc hierName, String JavaDoc[] levelNames, int[] childCount) {
31     this.hierName = hierName;
32     this.levelNames = levelNames;
33     this.childCount = childCount;
34
35     // build the dim / hier / levels
36
TestDimension dim = new TestDimension();
37     dim.setLabel(hierName);
38     TestHierarchy hier = new TestHierarchy();
39     hier.setLabel(hierName);
40     hier.setDimension(dim);
41     dim.setHierarchies(new Hierarchy[] { hier });
42
43     levels = new LevelImpl[levelNames.length];
44     for (int i = 0; i < levels.length; i++) {
45       TestLevel level = new TestLevel();
46       level.setLabel(levelNames[i]);
47       level.setHierarchy(hier);
48       levels[i] = level;
49     }
50     hier.setLevels(levels);
51
52     // build the members
53
TestMember[] roots = buildRoots();
54     hier.rootMembers = roots;
55
56     return dim;
57   }
58
59   TestMember[] buildRoots() {
60     TestMember[] members = new TestMember[childCount[0]];
61     for (int i = 0; i < childCount[0]; i++) {
62       TestMember member = new TestMember();
63       member.setLabel(levelNames[0] + "[" + i + "]");
64       member.setLevel(levels[0]);
65       member.setVisible(true);
66       appendChildren(member, 1);
67       members[i] = member;
68     }
69     return members;
70   }
71
72
73   void appendChildren(TestMember parent, int levelIndex) {
74     if (levelIndex >= childCount.length)
75       return;
76
77     for (int i = 0; i < childCount[levelIndex]; i++) {
78       TestMember member = new TestMember();
79       member.setLabel(levelNames[levelIndex] + "[" + i + "]");
80       member.setParentMember(parent);
81       member.setLevel(levels[levelIndex]);
82       member.setRootDistance(levelIndex);
83       parent.addChildMember(member);
84       appendChildren(member, levelIndex + 1);
85     }
86   }
87
88 }
89
Popular Tags