1 13 package com.tonbeller.jpivot.mondrian; 14 15 import java.util.ArrayList ; 16 import java.util.Collections ; 17 import java.util.Iterator ; 18 import java.util.List ; 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 33 public class MondrianPlaceMembers extends MondrianPlaceHierarchies implements PlaceMembersOnAxes { 34 35 38 public MondrianPlaceMembers() { 39 setId(PlaceMembersOnAxes.ID); 40 } 41 42 46 public Object createMemberExpression(List members) { 47 ArrayList memberList = new ArrayList (); 48 for (Iterator iter = members.iterator(); iter.hasNext();) { 49 MondrianMember mem = (MondrianMember) iter.next(); 50 memberList.add(mem.getMonMember()); 51 } 52 return memberList; 53 } 54 55 59 public List findVisibleMembers(Hierarchy hier) { 60 List memberList = null; 61 62 MondrianModel model = (MondrianModel) getModel(); 63 MondrianQueryAdapter adapter = (MondrianQueryAdapter) model.getQueryAdapter(); 64 65 Quax quax = adapter.findQuax(hier.getDimension()); 67 if (quax == null) 68 return Collections.EMPTY_LIST; 70 int iDim = quax.dimIdx(hier.getDimension()); 71 72 77 Result res = null; 78 memberList = new ArrayList (); 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 int iAx = quax.getOrdinal(); 89 if (adapter.isSwapAxes()) 90 iAx = (iAx + 1) % 2; 91 Axis axis = res.getAxes()[iAx]; 92 List positions = axis.getPositions(); 93 for (Iterator 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 } | Popular Tags |