1 13 package com.tonbeller.jpivot.mondrian; 14 15 import java.util.ArrayList ; 16 import java.util.List ; 17 18 import mondrian.olap.Exp; 19 import mondrian.olap.Member; 20 import mondrian.olap.SchemaReader; 21 import mondrian.olap.Syntax; 22 import mondrian.mdx.UnresolvedFunCall; 23 import mondrian.mdx.MemberExpr; 24 25 import org.apache.log4j.Logger; 26 27 import com.tonbeller.jpivot.core.ExtensionSupport; 28 import com.tonbeller.jpivot.olap.model.Axis; 29 import com.tonbeller.jpivot.olap.model.Hierarchy; 30 import com.tonbeller.jpivot.olap.navi.PlaceHierarchiesOnAxes; 31 import com.tonbeller.jpivot.olap.query.Quax; 32 33 36 public class MondrianPlaceHierarchies extends ExtensionSupport implements PlaceHierarchiesOnAxes { 37 38 private boolean expandAllMember = false; 39 ArrayList aMemberSet = null; 40 static Logger logger = Logger.getLogger(MondrianPlaceHierarchies.class); 41 42 45 public MondrianPlaceHierarchies() { 46 super.setId(PlaceHierarchiesOnAxes.ID); 47 } 48 49 52 public Object createMemberExpression(Hierarchy hier) { 53 54 mondrian.olap.Hierarchy monHier = ((MondrianHierarchy) hier).getMonHierarchy(); 55 56 MondrianModel model = (MondrianModel) getModel(); 59 MondrianQueryAdapter adapter = (MondrianQueryAdapter) model.getQueryAdapter(); 60 61 Quax quax = adapter.findQuax(hier.getDimension()); 63 if (quax == null) { 64 SchemaReader scr = ((MondrianModel) getModel()).getMonConnection().getSchemaReader(); 66 return MondrianUtil.topLevelMembers(monHier, expandAllMember, scr); 67 } 69 70 int iDimension = quax.dimIdx(hier.getDimension()); 73 return quax.genExpForDim(iDimension); 74 } 75 76 79 public void setQueryAxis(Axis target, Object [] memberExpressions) { 80 81 MondrianModel model = (MondrianModel) getModel(); 82 MondrianQueryAdapter adapter = (MondrianQueryAdapter) model.getQueryAdapter(); 83 84 int iQuax = ((MondrianAxis) target).getOrdinal(); 86 if (adapter.isSwapAxes()) 87 iQuax = (iQuax + 1) % 2; 88 Quax quax = adapter.getQuaxes()[iQuax]; 89 90 int nDimension = 0; 91 for (int i = 0; i < memberExpressions.length; i++) { 92 if (memberExpressions[i] != null) 93 ++nDimension; 94 } 95 96 Object [] sets = new Object [nDimension]; 99 boolean changedMemberSet = false; 100 int j = 0; 101 for (int i = 0; i < memberExpressions.length; i++) { 102 if (memberExpressions[i] instanceof List ) { 104 List memberList = (List ) memberExpressions[i]; 105 Exp[] members = new Exp[memberList.size()]; 106 for (int k = 0; k < members.length; k++) { 107 members[k] = new MemberExpr((Member) memberList.get(k)); 108 } 109 if (members.length == 1) 110 sets[j++] = members[0]; 111 else 112 sets[j++] = new UnresolvedFunCall("{}", Syntax.Braces, members); 113 changedMemberSet = true; 114 } else if (memberExpressions[i] != null) { 115 sets[j++] = memberExpressions[i]; 117 } 118 } 119 120 quax.regeneratePosTree(sets, true); 122 123 if (logger.isInfoEnabled()) { 124 String changed = ""; 125 if (changedMemberSet) 126 changed = " changed by navi"; 127 logger.info("setQueryAxis axis=" + quax.getOrdinal() + " nDimension=" + nDimension + changed); 128 logger.info("Expression for Axis=" + quax.toString()); 129 } 130 131 quax.changed(this, changedMemberSet); 133 134 model.fireModelChanged(); 135 } 136 137 140 public void setExpandAllMember(boolean expandAllMember) { 141 this.expandAllMember = expandAllMember; 142 } 143 144 147 public boolean getExpandAllMember() { 148 return expandAllMember; 149 } 150 151 } | Popular Tags |