KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > mondrian > MondrianPlaceMembers


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.mondrian;
14
15 import java.util.ArrayList JavaDoc;
16 import java.util.Collections JavaDoc;
17 import java.util.Iterator JavaDoc;
18 import java.util.List JavaDoc;
19
20 import com.tonbeller.jpivot.olap.model.Axis;
21 import com.tonbeller.jpivot.olap.model.Hierarchy;
22 import com.tonbeller.jpivot.olap.model.Member;
23 import com.tonbeller.jpivot.olap.model.OlapException;
24 import com.tonbeller.jpivot.olap.model.Position;
25 import com.tonbeller.jpivot.olap.model.Result;
26 import com.tonbeller.jpivot.olap.navi.PlaceMembersOnAxes;
27 import com.tonbeller.jpivot.olap.query.Quax;
28
29 /**
30  *
31  * @author hh
32  */

33 public class MondrianPlaceMembers extends MondrianPlaceHierarchies implements PlaceMembersOnAxes {
34
35   /**
36    * Constructor for MondrianPlaceMembers.
37    */

38   public MondrianPlaceMembers() {
39     setId(PlaceMembersOnAxes.ID);
40   }
41
42   /**
43    * return List of Mondrian members
44    * @see com.tonbeller.jpivot.olap.navi.PlaceMembersOnAxes#createMemberExpression(List)
45    */

46   public Object JavaDoc createMemberExpression(List JavaDoc members) {
47     ArrayList JavaDoc memberList = new ArrayList JavaDoc();
48     for (Iterator JavaDoc iter = members.iterator(); iter.hasNext();) {
49       MondrianMember mem = (MondrianMember) iter.next();
50       memberList.add(mem.getMonMember());
51     }
52     return memberList;
53   }
54
55   /**
56    * find all members of an hierarchy
57    * @see com.tonbeller.jpivot.olap.navi.PlaceMembersOnAxes#findVisibleMembers(Hierarchy)
58    */

59   public List JavaDoc findVisibleMembers(Hierarchy hier) {
60     List JavaDoc memberList = null;
61
62     MondrianModel model = (MondrianModel) getModel();
63     MondrianQueryAdapter adapter = (MondrianQueryAdapter) model.getQueryAdapter();
64
65     // find the Quax for this hier
66
Quax quax = adapter.findQuax(hier.getDimension());
67     if (quax == null)
68       return Collections.EMPTY_LIST; // should not occur
69

70     int iDim = quax.dimIdx(hier.getDimension());
71
72     // use result
73
// problem: if NON EMPTY is on the axis then a member, which is excluded by Non Empty,
74
// will not be visible.
75
// It would be possible to add it (again) to the axis, which must be avoided
76

77     Result res = null;
78     memberList = new ArrayList JavaDoc();
79     try {
80       res = model.getResult();
81     } catch (OlapException e) {
82       e.printStackTrace();
83       logger.error("findVisibleMembers: unexpected failure of getResult", e);
84       return Collections.EMPTY_LIST;
85     }
86
87     // locate the appropriate result axis
88
int iAx = quax.getOrdinal();
89     if (adapter.isSwapAxes())
90       iAx = (iAx + 1) % 2;
91     Axis axis = res.getAxes()[iAx];
92     List JavaDoc positions = axis.getPositions();
93     for (Iterator JavaDoc iter = positions.iterator(); iter.hasNext();) {
94       Position pos = (Position) iter.next();
95       Member[] members = pos.getMembers();
96       MondrianMember mem = (MondrianMember) members[iDim];
97       if (mem != null && !memberList.contains(mem))
98         memberList.add(mem);
99     }
100
101     return memberList;
102   }
103
104 } // End MondrianPlaceMembers
105
Popular Tags