KickJava   Java API By Example, From Geeks To Geeks.

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


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.net.URL JavaDoc;
16 import java.util.StringTokenizer JavaDoc;
17
18 import javax.servlet.jsp.JspException JavaDoc;
19
20 import com.tonbeller.jpivot.core.ModelFactory;
21 import com.tonbeller.jpivot.olap.model.OlapModel;
22 import com.tonbeller.jpivot.test.olap.TestAxis;
23 import com.tonbeller.jpivot.test.olap.TestDimension;
24 import com.tonbeller.jpivot.test.olap.TestOlapModel;
25 import com.tonbeller.jpivot.test.olap.TestOlapModelUtils;
26 import com.tonbeller.wcf.controller.RequestContext;
27
28 /**
29  * @author andreas
30  */

31 public class TestOlapModelTag extends OlapModelTag {
32   String JavaDoc onColumns = "Measures";
33   String JavaDoc onRows = "Products";
34   String JavaDoc config = null;
35   
36   /**
37    * creates a test olap model
38    */

39   protected OlapModel getOlapModel(RequestContext context) throws Exception JavaDoc {
40     URL JavaDoc url;
41     if (config == null)
42       url = getDefaultConfig();
43     else
44       url = pageContext.getServletContext().getResource(config);
45     TestOlapModel model = (TestOlapModel) ModelFactory.instance(url);
46     model.setAxis(0, createAxis(model, onColumns));
47     model.setAxis(1, createAxis(model, onRows));
48     return model;
49   }
50
51   /**
52    * @return
53    */

54   protected URL JavaDoc getDefaultConfig() {
55     return getClass().getResource("/com/tonbeller/jpivot/test/olap/config.xml");
56   }
57
58   TestAxis createAxis(TestOlapModel tom, String JavaDoc names) throws JspException JavaDoc {
59     StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(names);
60     TestAxis a = createAxis1(tom, st.nextToken());
61     while (st.hasMoreTokens()) {
62       TestAxis b = createAxis1(tom, st.nextToken());
63       a = TestOlapModelUtils.crossJoin(a, b);
64     }
65     return a;
66   }
67   
68   TestAxis createAxis1(TestOlapModel tom, String JavaDoc name) throws JspException JavaDoc {
69     TestDimension dim = (TestDimension)tom.getDimension(name);
70     if (dim == null)
71       throw new JspException JavaDoc("Dimension " + name + " not found");
72     return TestOlapModelUtils.createAxis(dim);
73   }
74
75   
76   /**
77    * Returns the onColumns.
78    * @return String
79    */

80   public String JavaDoc getOnColumns() {
81     return onColumns;
82   }
83
84   /**
85    * Returns the onRows.
86    * @return String
87    */

88   public String JavaDoc getOnRows() {
89     return onRows;
90   }
91
92   /**
93    * Sets the onColumns.
94    * @param onColumns The onColumns to set
95    */

96   public void setOnColumns(String JavaDoc onColumns) {
97     this.onColumns = onColumns;
98   }
99
100   /**
101    * Sets the onRows.
102    * @param onRows The onRows to set
103    */

104   public void setOnRows(String JavaDoc onRows) {
105     this.onRows = onRows;
106   }
107
108   /**
109    * Returns the config.
110    * @return String
111    */

112   public String JavaDoc getConfig() {
113     return config;
114   }
115
116   /**
117    * Sets the config.
118    * @param config The config to set
119    */

120   public void setConfig(String JavaDoc config) {
121     this.config = config;
122   }
123
124 }
125
Popular Tags