KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > xmla > XMLA_PlaceHierarchies


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.xmla;
15
16 import java.util.ArrayList JavaDoc;
17 import java.util.List JavaDoc;
18
19 import org.apache.log4j.Logger;
20
21 import com.tonbeller.jpivot.core.ExtensionSupport;
22 import com.tonbeller.jpivot.olap.mdxparse.Exp;
23 import com.tonbeller.jpivot.olap.mdxparse.FunCall;
24 import com.tonbeller.jpivot.olap.model.Axis;
25 import com.tonbeller.jpivot.olap.model.Hierarchy;
26 import com.tonbeller.jpivot.olap.navi.PlaceHierarchiesOnAxes;
27 import com.tonbeller.jpivot.olap.query.Quax;
28 import com.tonbeller.jpivot.olap.query.QueryAdapter;
29
30 /**
31  * XMLA Place Hierarchies
32  */

33 public class XMLA_PlaceHierarchies extends ExtensionSupport implements PlaceHierarchiesOnAxes {
34
35   private boolean expandAllMember = false;
36   ArrayList JavaDoc aMemberSet = null;
37   static Logger logger = Logger.getLogger(XMLA_PlaceHierarchies.class);
38
39   /**
40    * Constructor sets ID
41    */

42   public XMLA_PlaceHierarchies() {
43     super.setId(PlaceHierarchiesOnAxes.ID);
44   }
45
46   /**
47    * @see com.tonbeller.jpivot.olap.navi.PlaceHierarchiesOnAxes#createMemberExpression(Hierarchy)
48    */

49   public Object JavaDoc createMemberExpression(Hierarchy hier) {
50     // if the query does not contain the hier,
51
// just return the highest level
52
QueryAdapter.QueryAdapterHolder model = (QueryAdapter.QueryAdapterHolder) getModel();
53     XMLA_QueryAdapter adapter = (XMLA_QueryAdapter) model.getQueryAdapter();
54
55     // find the Quax for this hier
56
Quax quax = adapter.findQuax(hier.getDimension());
57     if (quax == null) {
58       // the hierarchy was not found on any axis
59
return XMLA_Util.topLevelMembers(hier, expandAllMember); // return top level members of the hierarchy
60
}
61
62     // the member expression is the list of members plus the list of FunCalls
63
// for this dimension
64
int iDimension = quax.dimIdx(hier.getDimension());
65     return quax.genExpForDim(iDimension);
66   }
67
68   /**
69    * @see com.tonbeller.jpivot.olap.navi.PlaceHierarchiesOnAxes#setQueryAxis(Axis, Object[])
70    */

71   public void setQueryAxis(Axis target, Object JavaDoc[] memberExpressions) {
72
73     XMLA_Model model = (XMLA_Model) getModel();
74     XMLA_QueryAdapter adapter = (XMLA_QueryAdapter) model.getQueryAdapter();
75
76     // locate the appropriate query axis
77
int iQuax = ((XMLA_Axis) target).getOrdinal();
78     if (adapter.isSwapAxes())
79       iQuax = (iQuax + 1) % 2;
80     Quax quax = adapter.getQuaxes()[iQuax];
81
82     int nDimension = memberExpressions.length;
83
84     // if any of the member expressions is a memberlist from PlaceMembers
85
// we will have to reset sorting
86
Object JavaDoc[] sets = new Object JavaDoc[nDimension];
87     boolean changedMemberSet = false;
88     for (int i = 0; i < nDimension; i++) {
89       if (memberExpressions[i] instanceof List JavaDoc) {
90         List JavaDoc memberList = (List JavaDoc) memberExpressions[i];
91         Exp[] members = (Exp[]) memberList.toArray(new Exp[0]);
92         if (members.length == 1)
93           sets[i] = members[0];
94         else
95           sets[i] = new FunCall("{}", members, FunCall.TypeBraces);
96         changedMemberSet = true;
97       } else {
98         // we already have an Exp generated by createMemberExpression
99
sets[i] = memberExpressions[i];
100       }
101     }
102
103     // generate the crossjoins
104
quax.regeneratePosTree(sets, true);
105
106     if (logger.isInfoEnabled()) {
107       String JavaDoc changed = "";
108       if (changedMemberSet)
109         changed = " changed by navi";
110       logger.info("setQueryAxis axis=" + quax.getOrdinal() + " nDimension=" + nDimension + changed);
111       logger.info("Expression for Axis=" + quax.toString());
112     }
113
114     // tell listeners, that the axis was changed.
115
quax.changed(this, changedMemberSet);
116
117     model.fireModelChanged();
118   }
119
120   /**
121    * @see PlaceHierarchiesOnAxes.setExpandAllMember
122    */

123   public void setExpandAllMember(boolean expandAllMember) {
124     this.expandAllMember = expandAllMember;
125   }
126
127   /**
128    * @see PlaceHierarchiesOnAxes.getExpandAllMember
129    */

130   public boolean getExpandAllMember() {
131     return expandAllMember;
132   }
133   
134 } // End XMLA_PlaceHierarchies
135
Popular Tags