1 13 package com.tonbeller.jpivot.mondrian; 14 15 import org.apache.log4j.Logger; 16 17 import com.tonbeller.jpivot.core.ExtensionSupport; 18 import com.tonbeller.jpivot.olap.navi.NonEmpty; 19 20 25 public class MondrianNonEmpty extends ExtensionSupport implements NonEmpty { 26 27 static Logger logger = Logger.getLogger(MondrianNonEmpty.class); 28 29 32 public MondrianNonEmpty() { 33 super.setId(NonEmpty.ID); 34 } 35 36 39 public boolean isNonEmpty() { 40 41 MondrianModel m = (MondrianModel)getModel(); 42 MondrianQueryAdapter adapter = (MondrianQueryAdapter) m.getQueryAdapter(); 43 if (adapter == null) 44 return false; 46 mondrian.olap.Query monQuery = adapter.getMonQuery(); 47 48 52 for (int i = 0; i < monQuery.getAxes().length; i++) { 53 mondrian.olap.QueryAxis qAxis = monQuery.getAxes()[i]; 54 58 if (qAxis.isNonEmpty()) 59 return true; 60 } 61 return false; 63 } 64 65 68 public void setNonEmpty(boolean nonEmpty) { 69 70 MondrianModel m = (MondrianModel)getModel(); 71 MondrianQueryAdapter adapter = (MondrianQueryAdapter) m.getQueryAdapter(); 72 if (adapter == null) { 73 logger.error("setNonEmpty query adapter=null"); 74 return; } 76 77 mondrian.olap.Query monQuery = adapter.getMonQuery(); 78 79 82 boolean bChange = false; 83 for (int i = 0; i < monQuery.getAxes().length; i++) { 84 mondrian.olap.QueryAxis qAxis = monQuery.getAxes()[i]; 85 89 if (qAxis.isNonEmpty() != nonEmpty) { 90 qAxis.setNonEmpty(nonEmpty); 91 bChange = true; 92 } 93 } 94 95 if (bChange && logger.isInfoEnabled()) 96 logger.info("Non Empty =" + nonEmpty); 97 98 if (bChange) 99 ((MondrianModel)getModel()).fireModelChanged(); 100 101 } 102 103 106 131 132 } | Popular Tags |