KickJava   Java API By Example, From Geeks To Geeks.

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


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
14   package com.tonbeller.jpivot.mondrian;
15
16   import mondrian.olap.Exp;
17   import mondrian.olap.Syntax;
18 import mondrian.mdx.UnresolvedFunCall;
19 import mondrian.mdx.MemberExpr;
20
21 import org.apache.log4j.Logger;
22
23   import com.tonbeller.jpivot.olap.model.Member;
24   import com.tonbeller.jpivot.olap.model.OlapException;
25   import com.tonbeller.jpivot.util.TreeNode;
26
27   /**
28    * support old stuff as of MDX version 2 (Memento) for a while
29    * HHTASK: remove, when old Bookmarks are replaced
30    */

31
32   public class MondrianOldStuff {
33
34     static Logger logger = Logger.getLogger(MondrianModel.class);
35
36     /**
37      * create Position Tree from old Member Sets
38      * @param quax
39      * @param quaxBean
40      */

41     static void handleQubonMode(
42       MondrianQuax quax,
43       MondrianQuaxBean quaxBean,
44       MondrianModel model) {
45
46       MondrianMemberSetBean[] msbs = quaxBean.getMemberSets();
47
48       // Qubon mode: create Position Tree from member sets
49
TreeNode rootNode = new TreeNode(null);
50       TreeNode currentNode = rootNode;
51       for (int j = 0; j < msbs.length; j++) {
52         int msbType = msbs[j].getType();
53         TreeNode node = null;
54         switch (msbType) {
55           case 0 : // member list
56
String JavaDoc[] memberList = msbs[j].getMemberList();
57             MemberExpr[] monMembers = new MemberExpr[memberList.length];
58             for (int k = 0; k < monMembers.length; k++) {
59               MondrianMember m = (MondrianMember) model.lookupMemberByUName(memberList[k]);
60               if (m == null) {
61                 logger.error(
62                   "old Memento Object is invalid, Axis "
63                     + quax.getOrdinal()
64                     + " #Member could not be found "
65                     + memberList[k]);
66                 return;
67               }
68               monMembers[k] = new MemberExpr(m.getMonMember());
69             }
70             UnresolvedFunCall fSet = new UnresolvedFunCall("{}", Syntax.Braces, monMembers);
71             node = new TreeNode(fSet);
72             currentNode.addChildNode(node);
73             break;
74           case 1 : // member children
75
memberList = msbs[j].getMemberList();
76
77             MondrianMember m = (MondrianMember) model.lookupMemberByUName(memberList[0]);
78             if (m == null) {
79               logger.error(
80                 "old Memento Object is invalid, Axis "
81                   + quax.getOrdinal()
82                   + " #Member could not be found "
83                   + memberList[0]);
84               return;
85             }
86             final mondrian.olap.Member monMember = m.getMonMember();
87
88             UnresolvedFunCall fChildren = new UnresolvedFunCall("Children", Syntax.Property, new Exp[] { new MemberExpr(monMember) });
89             node = new TreeNode(fChildren);
90             currentNode.addChildNode(node);
91             break;
92           default :
93             logger.error(
94               "old Memento Object is invalid, Axis "
95                 + quax.getOrdinal()
96                 + " unexpected member set type "
97                 + msbType);
98             return;
99         }
100
101         currentNode = node;
102       } // for member sets
103

104       quax.setPosTreeRoot(rootNode, true);
105     }
106
107     /**
108      * apply old DrillExes to quax
109      * @param quax
110      * @param quaxBean
111      */

112     static void handleDrillExMode(
113       MondrianQuax quax,
114       MondrianQuaxBean quaxBean,
115       MondrianModel model) {
116
117       try {
118         // quax position tree must be initialized here
119
model.getResult();
120       } catch (OlapException e) {
121         logger.error("old Memento Object , Axis " + quax.getOrdinal() + " Exception getResult");
122         e.printStackTrace();
123         return;
124       }
125       MondrianDrillExBean[] drillExes = quaxBean.getDrillExes();
126       for (int j = 0; j < drillExes.length; j++) {
127         String JavaDoc[] pathMembers = drillExes[j].getPathMembers();
128
129         Member[] members = new Member[pathMembers.length];
130         for (int k = 0; k < members.length; k++) {
131           Member m = model.lookupMemberByUName(pathMembers[k]);
132           if (m == null) {
133             logger.error(
134               "old Memento Object is invalid, Axis "
135                 + quax.getOrdinal()
136                 + " drillex Member could not be found "
137                 + pathMembers[k]);
138             return;
139           }
140           members[k] = m;
141
142         } // for path members
143

144         if (quax.canExpand(members))
145           quax.expand(members);
146
147       } // for drillExes
148
}
149
150   } // MondrianOldStuff
151
Popular Tags