1 13 14 package com.tonbeller.jpivot.xmla; 15 16 import java.util.ArrayList ; 17 import java.util.Iterator ; 18 import java.util.List ; 19 20 import org.apache.log4j.Logger; 21 22 import com.tonbeller.jpivot.core.ExtensionSupport; 23 import com.tonbeller.jpivot.olap.mdxparse.FunCall; 24 import com.tonbeller.jpivot.olap.mdxparse.ParsedQuery; 25 import com.tonbeller.jpivot.olap.model.Axis; 26 import com.tonbeller.jpivot.olap.model.Member; 27 import com.tonbeller.jpivot.olap.model.OlapException; 28 import com.tonbeller.jpivot.olap.model.Position; 29 import com.tonbeller.jpivot.olap.model.Result; 30 import com.tonbeller.jpivot.olap.navi.ChangeSlicer; 31 import com.tonbeller.jpivot.olap.query.MDXElement; 32 import com.tonbeller.jpivot.util.ArrayUtil; 33 34 37 public class XMLA_ChangeSlicer extends ExtensionSupport implements ChangeSlicer { 38 39 static Logger logger = Logger.getLogger(XMLA_ChangeSlicer.class); 40 41 44 public XMLA_ChangeSlicer() { 45 super.setId(ChangeSlicer.ID); 46 } 47 48 51 public Member[] getSlicer() { 52 53 XMLA_Model model = (XMLA_Model) getModel(); 54 Result res = null; 56 try { 57 res = model.getResult(); 58 } catch (OlapException ex) { 59 return new Member[0]; 61 } 62 63 Axis slicer = res.getSlicer(); 64 List positions = slicer.getPositions(); 65 List members = new ArrayList (); 66 for (Iterator iter = positions.iterator(); iter.hasNext();) { 67 Position pos = (Position) iter.next(); 68 Member[] posMembers = pos.getMembers(); 69 for (int i = 0; i < posMembers.length; i++) { 70 if (!members.contains(posMembers[i])) 71 members.add(posMembers[i]); 72 } 73 } 74 75 return (Member[]) members.toArray(new Member[0]); 76 } 77 78 81 public void setSlicer(Member[] members) { 82 XMLA_Model model = (XMLA_Model) getModel(); 83 XMLA_QueryAdapter adapter = (XMLA_QueryAdapter) model.getQueryAdapter(); 84 ParsedQuery pq = adapter.getParsedQuery(); 85 86 boolean logInfo = logger.isInfoEnabled(); 87 88 if (members.length == 0) { 89 pq.setSlicer(null); if (logInfo) 92 logger.info("slicer set to null"); 93 } else { 94 FunCall f = new FunCall("()",(XMLA_Member[]) ArrayUtil.naturalCast(members), FunCall.TypeParentheses); 95 pq.setSlicer(f); 96 if (logInfo) { 97 StringBuffer sb = new StringBuffer ("slicer=("); 98 for (int i = 0; i < members.length; i++) { 99 if (i > 0) 100 sb.append(","); 101 sb.append(((MDXElement)members[i]).getUniqueName()); 102 } 103 sb.append(")"); 104 logger.info(sb.toString()); 105 } 106 } 107 108 model.fireModelChanged(); 109 } 110 111 } | Popular Tags |