KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openi > xmla > XMLAQueryTag


1 /*********************************************************************************
2  * The contents of this file are subject to the OpenI Public License Version 1.0
3  * ("License"); You may not use this file except in compliance with the
4  * License. You may obtain a copy of the License at
5  * http://www.openi.org/docs/LICENSE.txt
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is: OpenI Open Source
12  *
13  * The Initial Developer of the Original Code is Loyalty Matrix, Inc.
14  * Portions created by Loyalty Matrix, Inc. are
15  * Copyright (C) 2005 Loyalty Matrix, Inc.; All Rights Reserved.
16  *
17  * Contributor(s): ______________________________________.
18  *
19  ********************************************************************************/

20 package org.openi.xmla;
21
22 import com.tonbeller.jpivot.core.Model;
23 import com.tonbeller.jpivot.core.ModelFactory;
24 import com.tonbeller.jpivot.olap.model.OlapException;
25 import com.tonbeller.jpivot.olap.model.OlapModel;
26 import com.tonbeller.jpivot.olap.navi.ClickableExtension;
27 import com.tonbeller.jpivot.olap.navi.ClickableExtensionImpl;
28 import com.tonbeller.jpivot.table.ClickableMember;
29 import com.tonbeller.jpivot.tags.OlapModelProxy;
30 import com.tonbeller.jpivot.xmla.XMLA_Model;
31 import com.tonbeller.jpivot.xmla.XMLA_OlapModelTag;
32 import com.tonbeller.wcf.controller.RequestContext;
33 import org.apache.log4j.Logger;
34 import org.xml.sax.SAXException JavaDoc;
35 import java.io.IOException JavaDoc;
36 import java.net.URL JavaDoc;
37 import java.net.URLEncoder JavaDoc;
38 import java.util.ArrayList JavaDoc;
39 import java.util.List JavaDoc;
40
41
42 /**
43  * JSP tag for XMLA Olap Model
44  */

45 public class XMLAQueryTag extends XMLA_OlapModelTag {
46     private static Logger logger = Logger.getLogger(XMLAQueryTag.class);
47     private List JavaDoc clickables;
48     private String JavaDoc user = null;
49     private String JavaDoc password = null;
50     private String JavaDoc mdxQuery = null;
51     private String JavaDoc queryName;
52     private boolean stackMode;
53
54     public void addClickable(ClickableMember clickable) {
55         clickables.add(clickable);
56     }
57
58     protected OlapModel getOlapModel(RequestContext context)
59         throws SAXException JavaDoc, IOException JavaDoc, OlapException {
60         URL JavaDoc url;
61
62         if (getConfig() == null) {
63             url = getClass().getResource("config.xml");
64         } else {
65             url = pageContext.getServletContext().getResource(getConfig());
66         }
67
68         // let Digester create a model from config input
69
// the config input stream MUST refer to the XMLA_Model class
70
// <model class="com.tonbeller.bii.xmla.XMLA_Model"> is required
71
Model model = ModelFactory.instance(url);
72
73         if (!(model instanceof XMLA_Model)) {
74             throw new com.tonbeller.jpivot.olap.model.OlapException(
75                 "invalid class attribute for model tag, resource="
76                 + getConfig());
77         }
78
79         XMLA_Model xm = (XMLA_Model) model;
80         xm.setUri(getUri());
81         xm.setDataSource(getDataSource());
82         xm.setCatalog(getCatalog());
83         // xm.setMdxQuery(getBodyContent().getString());
84
xm.setUser(URLEncoder.encode(user, "UTF-8"));
85         xm.setPassword(URLEncoder.encode(password, "UTF-8"));
86         xm.setMdxQuery(mdxQuery);
87
88         return xm;
89     }
90
91     public void init(RequestContext context) throws Exception JavaDoc {
92         long start = System.currentTimeMillis();
93         // logger.debug("init'ing XMLAQueryTag using context params: " + context.getParameters());
94
clickables = new ArrayList JavaDoc();
95
96         OlapModel om = getOlapModel(context);
97         om = (OlapModel) om.getTopDecorator();
98         om.setLocale(context.getLocale());
99         om.setID(id);
100
101         ClickableExtension ext = (ClickableExtension) om.getExtension(ClickableExtension.ID);
102
103         if (ext == null) {
104             ext = new ClickableExtensionImpl();
105             om.addExtension(ext);
106         }
107
108         ext.setClickables(clickables);
109
110         OlapModelProxy omp = OlapModelProxy.instance(id, context.getSession(),
111                 stackMode);
112
113         if (queryName != null) {
114             omp.initializeAndShow(queryName, om);
115         } else {
116             omp.initializeAndShow(om);
117         }
118
119         logger.info("init completed in: "
120             + (System.currentTimeMillis() - start) + " ms");
121     }
122
123     public String JavaDoc getMdxQuery() {
124         return mdxQuery;
125     }
126
127     public void setMdxQuery(String JavaDoc mdxquery) {
128         mdxQuery = mdxquery;
129     }
130
131     public String JavaDoc getUser() {
132         return user;
133     }
134
135     public String JavaDoc getPassword() {
136         return password;
137     }
138
139     public void setUser(String JavaDoc user) {
140         this.user = user;
141     }
142
143     public void setPassword(String JavaDoc password) {
144         this.password = password;
145     }
146
147     public void setQueryName(String JavaDoc queryName) {
148         this.queryName = queryName;
149     }
150
151     public void setStackMode(boolean stackMode) {
152         this.stackMode = stackMode;
153     }
154 }
155
Popular Tags