KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > olap > model > impl > ScalarOlapModel


1 package com.tonbeller.jpivot.olap.model.impl;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Collections JavaDoc;
5 import java.util.List JavaDoc;
6
7 import javax.servlet.ServletContext JavaDoc;
8
9 import com.tonbeller.jpivot.core.ModelSupport;
10 import com.tonbeller.jpivot.olap.model.Axis;
11 import com.tonbeller.jpivot.olap.model.Dimension;
12 import com.tonbeller.jpivot.olap.model.Member;
13 import com.tonbeller.jpivot.olap.model.OlapException;
14 import com.tonbeller.jpivot.olap.model.OlapModel;
15 import com.tonbeller.jpivot.olap.model.Result;
16 import com.tonbeller.jpivot.olap.model.Visitor;
17
18 /**
19  * A ScalarOlapModel is an OlapModel that contains a single cell.
20  * It is 1-dimensional with Measures as its only dimension.
21  * <p />
22  * Properties:
23  * <dl>
24  * <dt>caption</dt><dd>Caption of the only measure</dd>
25  * <dt>result.value</dt><dd>value of the single cell</dd>
26  * <dt>result.formattedValue</dt><dd>formatted value of the single cell</dd>
27  * </dl>
28  *
29  * @author av
30  * @since 21.04.2005
31  */

32 public class ScalarOlapModel extends ModelSupport implements OlapModel, Result {
33   private static final String JavaDoc MEASURES = "Measures";
34   private static final String JavaDoc MEASURE = "Measure";
35
36   MemberImpl measure;
37   MemberImpl[] measures;
38   LevelImpl level;
39   HierarchyImpl hierarchy;
40   DimensionImpl dimension;
41   DimensionImpl[] dimensions;
42   String JavaDoc ID;
43
44   CellImpl cell;
45   List JavaDoc cells;
46   Axis[] axes;
47   Axis slicer;
48
49   boolean overflowOccured;
50
51   public ScalarOlapModel() {
52     measure = new MemberImpl();
53     measures = new MemberImpl[] { measure};
54     level = new LevelImpl();
55     level.setLabel(MEASURES);
56     measure.setLevel(level);
57     hierarchy = new HierarchyImpl();
58     hierarchy.setLabel(MEASURES);
59     hierarchy.setLevels(new LevelImpl[] { level});
60     level.setHierarchy(hierarchy);
61     dimension = new DimensionImpl();
62     dimension.setLabel(MEASURES);
63     dimension.setHierarchies(new HierarchyImpl[] { hierarchy});
64     hierarchy.setDimension(dimension);
65     dimensions = new DimensionImpl[] { dimension};
66
67     PositionImpl pos = new PositionImpl();
68     pos.setMembers(new Member[] { measure});
69     List JavaDoc posns = new ArrayList JavaDoc(1);
70     posns.add(pos);
71     AxisImpl axis = new AxisImpl();
72     axis.setPositions(posns);
73     axes = new Axis[] { axis};
74
75     cell = new CellImpl();
76     List JavaDoc list = new ArrayList JavaDoc(1);
77     list.add(cell);
78     cells = Collections.unmodifiableList(list);
79     
80     slicer = new AxisImpl();
81     
82     // some initial data
83
setCaption(MEASURE);
84     setValue(new Double JavaDoc(0));
85     setFormattedValue("0.00");
86   }
87
88   /**
89    * returns a collection containing a single cell
90    */

91   public List JavaDoc getCells() {
92     return cells;
93   }
94
95   /**
96    * returns one axis (measures)
97    */

98   public Axis[] getAxes() {
99     return axes;
100   }
101
102   /**
103    * returns an empty axis
104    */

105   public Axis getSlicer() {
106     return slicer;
107   }
108
109   public void accept(Visitor visitor) {
110     visitor.visitResult(this);
111   }
112
113   public Object JavaDoc getRootDecoree() {
114     return this;
115   }
116
117   /**
118    * returns the formatted value of the single cell
119    */

120   public String JavaDoc getFormattedValue() {
121     return cell.getFormattedValue();
122   }
123
124   /**
125    * sets the formatted value of the single cell
126    */

127   public void setFormattedValue(String JavaDoc formattedValue) {
128     cell.setFormattedValue(formattedValue);
129     fireModelChanged();
130   }
131
132   /**
133    * returns the overflow property
134    */

135   public boolean isOverflowOccured() {
136     return overflowOccured;
137   }
138
139   /**
140    * sets the overflow property
141    */

142   public void setOverflowOccured(boolean overflowOccured) {
143     this.overflowOccured = overflowOccured;
144     fireModelChanged();
145   }
146
147   /**
148    * returns the value of the single cell
149    */

150   public Object JavaDoc getValue() {
151     return cell.getValue();
152   }
153
154   /**
155    * sets the value of the single cell
156    */

157   public void setValue(Object JavaDoc value) {
158     cell.setValue(value);
159     fireModelChanged();
160   }
161
162   /**
163    * sets the caption of the only measure
164    */

165   public void setCaption(String JavaDoc caption) {
166     measure.setLabel(caption);
167     fireModelChanged();
168   }
169
170   /**
171    * returns the caption of the only measure
172    */

173   public String JavaDoc getCaption() {
174     return measure.getLabel();
175   }
176
177   public Result getResult() throws OlapException {
178     return this;
179   }
180
181   public Dimension[] getDimensions() {
182     return dimensions;
183   }
184
185   public Member[] getMeasures() {
186     return measures;
187   }
188
189   /**
190    * does nothing
191    */

192   public void initialize() throws OlapException {
193   }
194
195   /**
196    * does nothing
197    */

198   public void setServletContext(ServletContext JavaDoc servletContext) {
199   }
200
201   public String JavaDoc getID() {
202     return ID;
203   }
204
205   public void setID(String JavaDoc id) {
206     ID = id;
207   }
208
209 }
210
Popular Tags