KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > mondrian > script > ScriptableMondrianDrillThrough


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 package com.tonbeller.jpivot.mondrian.script;
12
13 import mondrian.olap.Util.PropertyList;
14 import mondrian.rolap.RolapConnectionProperties;
15
16 import com.tonbeller.jpivot.core.ExtensionSupport;
17 import com.tonbeller.jpivot.mondrian.MondrianCell;
18 import com.tonbeller.jpivot.mondrian.MondrianModel;
19 import com.tonbeller.jpivot.olap.model.Cell;
20 import com.tonbeller.jpivot.olap.navi.DrillThrough;
21 import com.tonbeller.wcf.table.TableModel;
22 /**
23  * @author Engineering Ingegneria Informatica S.p.A. - Luca Barozzi
24  *
25  * Implementation of the DrillExpand Extension for Mondrian Data Source.
26  */

27 public class ScriptableMondrianDrillThrough extends ExtensionSupport implements DrillThrough {
28
29   private boolean extendedContext = true;
30
31   /**
32    * Constructor sets ID
33    */

34   public ScriptableMondrianDrillThrough() {
35     super.setId(DrillThrough.ID);
36   }
37
38   /**
39    * drill through is possible if <code>member</code> is not calculated
40    */

41   public boolean canDrillThrough(Cell cell) {
42     return ((MondrianCell) cell).getMonCell().canDrillThrough();
43     //String sql = ((MondrianCell) cell).getMonCell().getDrillThroughSQL(extendedContext);
44
//return sql != null;
45
}
46
47   /**
48    * does a drill through, retrieves data that makes up the selected Cell
49    */

50   public TableModel drillThrough(Cell cell) {
51     String JavaDoc sql = ((MondrianCell) cell).getMonCell().getDrillThroughSQL(extendedContext);
52     if (sql == null) { throw new NullPointerException JavaDoc("DrillThroughSQL returned null"); }
53     ScriptableMondrianDrillThroughTableModel dtm = new ScriptableMondrianDrillThroughTableModel();
54     dtm.setSql(sql);
55     String JavaDoc connectString = getConnection().getConnectString();
56     PropertyList connectInfo = mondrian.olap.Util.parseConnectString(connectString);
57     String JavaDoc jdbcUrl = connectInfo.get(RolapConnectionProperties.Jdbc.name());
58     dtm.setJdbcUrl(jdbcUrl);
59     String JavaDoc jdbcUser = connectInfo.get(RolapConnectionProperties.JdbcUser.name());
60     dtm.setJdbcUser(jdbcUser);
61     String JavaDoc jdbcPassword = connectInfo.get(RolapConnectionProperties.JdbcPassword.name());
62     dtm.setJdbcPassword(jdbcPassword);
63     String JavaDoc dataSourceName = connectInfo.get(RolapConnectionProperties.DataSource.name());
64     dtm.setDataSourceName(dataSourceName);
65     String JavaDoc catalog = connectInfo.get(RolapConnectionProperties.Catalog.name());
66     String JavaDoc catalogExtension = catalog.replaceFirst(".*/", "").replaceFirst("\\.xml$", ".ext.xml");
67     dtm.setCatalogExtension(catalogExtension);
68     return dtm;
69   }
70
71   /**
72    * gets the mondrian connection
73    * @return
74    */

75   public mondrian.olap.Connection getConnection() {
76     MondrianModel model = (MondrianModel) getModel();
77     return model.getConnection();
78   }
79
80   public boolean isExtendedContext() {
81     return extendedContext;
82   }
83
84   public void setExtendedContext(boolean extendedContext) {
85     this.extendedContext = extendedContext;
86   }
87
88 }
89
Popular Tags