KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > tags > MondrianOlapModelTag


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  *
12  */

13 package com.tonbeller.jpivot.tags;
14
15 import java.io.IOException JavaDoc;
16 import java.net.URL JavaDoc;
17
18 import javax.servlet.jsp.JspException JavaDoc;
19
20 import org.xml.sax.SAXException JavaDoc;
21
22 import com.tonbeller.jpivot.mondrian.MondrianModel;
23 import com.tonbeller.jpivot.olap.model.OlapException;
24 import com.tonbeller.jpivot.olap.model.OlapModel;
25 import com.tonbeller.jpivot.tags.MondrianModelFactory.Config;
26 import com.tonbeller.tbutils.res.Resources;
27 import com.tonbeller.wcf.controller.RequestContext;
28
29 /**
30  * jsp tag that defines a mondrian query
31  */

32 public class MondrianOlapModelTag extends OlapModelTag {
33
34   String JavaDoc dataSource;
35   String JavaDoc jdbcDriver;
36   String JavaDoc jdbcUser;
37   String JavaDoc jdbcPassword;
38   String JavaDoc jdbcUrl;
39   String JavaDoc catalogUri;
40   String JavaDoc config;
41   String JavaDoc role;
42   String JavaDoc dynResolver;
43   String JavaDoc dynLocale;
44   String JavaDoc connectionPooling;
45   String JavaDoc dataSourceChangeListener;
46   
47   Resources res = Resources.instance();
48
49   protected OlapModel getOlapModel(RequestContext context) throws JspException JavaDoc, OlapException, SAXException JavaDoc, IOException JavaDoc {
50     MondrianModelFactory.Config cfg = new MondrianModelFactory.Config();
51     URL JavaDoc schemaUrl;
52     if (catalogUri.startsWith("/"))
53       schemaUrl = pageContext.getServletContext().getResource(catalogUri);
54     else
55       schemaUrl = new URL JavaDoc(catalogUri);
56     if (schemaUrl == null)
57       throw new JspException JavaDoc("could not find Catalog \"" + catalogUri + "\"");
58
59
60     cfg.setMdxQuery(getBodyContent().getString());
61     // Add the schema URL. Enclose the value in quotes to permit
62
// schema URLs that include things like ;jsessionid values.
63
cfg.setSchemaUrl("\"" + schemaUrl.toExternalForm() + "\"");
64     cfg.setJdbcUrl(jdbcUrl);
65     cfg.setJdbcDriver(jdbcDriver);
66     cfg.setJdbcUser(jdbcUser);
67     cfg.setJdbcPassword(jdbcPassword);
68     cfg.setDataSource(dataSource);
69     cfg.setRole(role);
70     cfg.setDynResolver(dynResolver);
71     cfg.setDynLocale(dynLocale);
72     cfg.setConnectionPooling(connectionPooling);
73     cfg.setDataSourceChangeListener(dataSourceChangeListener);
74
75     allowOverride(context, cfg);
76
77     URL JavaDoc url;
78     if (config == null)
79       url = getDefaultConfig();
80     else
81       url = pageContext.getServletContext().getResource(config);
82
83     MondrianModel mm = MondrianModelFactory.instance(url, cfg);
84     OlapModel om = (OlapModel) mm.getTopDecorator();
85     om.setLocale(context.getLocale());
86     om.setServletContext(context.getSession().getServletContext());
87     return om;
88   }
89
90   /**
91    * default implementation delegates to {@link Config#allowOverride(RequestContext)}
92    */

93   protected void allowOverride(RequestContext context, Config cfg) {
94     cfg.allowOverride(context);
95   }
96
97   protected URL JavaDoc getDefaultConfig() {
98     return MondrianOlapModelTag.class.getResource("/com/tonbeller/jpivot/mondrian/config.xml");
99   }
100
101
102   /**
103    * Returns the catalogUri.
104    *
105    * @return String
106    */

107   public String JavaDoc getCatalogUri() {
108     return catalogUri;
109   }
110
111   /**
112    * Returns the jdbcDriver.
113    *
114    * @return String
115    */

116   public String JavaDoc getJdbcDriver() {
117     return jdbcDriver;
118   }
119
120   /**
121    * Returns the jdbcUrl.
122    *
123    * @return String
124    */

125   public String JavaDoc getJdbcUrl() {
126     return jdbcUrl;
127   }
128
129   /**
130    * Sets the catalogUri.
131    *
132    * @param catalogUri
133    * The catalogUri to set
134    */

135   public void setCatalogUri(String JavaDoc catalogUri) {
136     this.catalogUri = catalogUri;
137   }
138
139   /**
140    * Sets the jdbcDriver.
141    *
142    * @param jdbcDriver
143    * The jdbcDriver to set
144    */

145   public void setJdbcDriver(String JavaDoc jdbcDriver) {
146     this.jdbcDriver = jdbcDriver;
147   }
148
149   /**
150    * Sets the jdbcUrl.
151    *
152    * @param jdbcUrl
153    * The jdbcUrl to set
154    */

155   public void setJdbcUrl(String JavaDoc jdbcUrl) {
156     this.jdbcUrl = jdbcUrl;
157   }
158
159   /**
160    * Returns the jdbcPassword.
161    *
162    * @return String
163    */

164   public String JavaDoc getJdbcPassword() {
165     return jdbcPassword;
166   }
167
168   /**
169    * Returns the jdbcUser.
170    *
171    * @return String
172    */

173   public String JavaDoc getJdbcUser() {
174     return jdbcUser;
175   }
176
177   /**
178    * Sets the jdbcPassword.
179    *
180    * @param jdbcPassword
181    * The jdbcPassword to set
182    */

183   public void setJdbcPassword(String JavaDoc jdbcPassword) {
184     this.jdbcPassword = jdbcPassword;
185   }
186
187   /**
188    * Sets the jdbcUser.
189    *
190    * @param jdbcUser
191    * The jdbcUser to set
192    */

193   public void setJdbcUser(String JavaDoc jdbcUser) {
194     this.jdbcUser = jdbcUser;
195   }
196
197   /**
198    * Returns the config.
199    *
200    * @return String
201    */

202   public String JavaDoc getConfig() {
203     return config;
204   }
205
206   /**
207    * Sets the config.
208    *
209    * @param config
210    * The config to set
211    */

212   public void setConfig(String JavaDoc config) {
213     this.config = config;
214   }
215
216   /**
217    * @param string
218    */

219   public void setDataSource(String JavaDoc string) {
220     dataSource = string;
221   }
222
223   /**
224    * @param role
225    * The role to set.
226    */

227   public void setRole(String JavaDoc role) {
228     this.role = role;
229   }
230
231   /**
232    * @return the dynamic variable resolver class name
233    */

234   public String JavaDoc getDynResolver() {
235     return dynResolver;
236   }
237
238   /**
239    * @param dynresolver - the dynamic variable resolver class name
240    */

241   public void setDynResolver(String JavaDoc dynResolver) {
242     this.dynResolver = dynResolver;
243   }
244
245   /**
246    * @param connectionPooling - "false" : Mondrian must not pool JDBC connections
247    */

248   public void setConnectionPooling(String JavaDoc connectionPooling) {
249     this.connectionPooling = connectionPooling;
250   }
251
252   /**
253    * @return "false" if Mondrion must not pool JDBC connections
254    */

255   public String JavaDoc getConnectionPooling() {
256     return connectionPooling;
257   }
258   public String JavaDoc getDataSource() {
259     return dataSource;
260   }
261   public String JavaDoc getRole() {
262     return role;
263   }
264 /**
265  * Getter for property locale.
266  * @return Value of property locale.
267  */

268   public String JavaDoc getDynLocale() {
269       return this.dynLocale;
270   }
271   /**
272    * Setter for property locale.
273    * @param locale New value of property locale.
274    */

275   public void setDynLocale(String JavaDoc dynLocale) {
276       this.dynLocale = dynLocale;
277   }
278
279 /**
280  * @return Returns the dataSourceChangeListener.
281  */

282 public String JavaDoc getDataSourceChangeListener() {
283     return dataSourceChangeListener;
284 }
285
286 /**
287  * @param dataSourceChangeListener The dataSourceChangeListener to set.
288  */

289 public void setDataSourceChangeListener(String JavaDoc dataSourceChangeListener) {
290     this.dataSourceChangeListener = dataSourceChangeListener;
291 }
292
293     
294 }
295
Popular Tags