KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > mondrian > MondrianCell


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.mondrian;
14
15 import org.apache.log4j.Logger;
16
17 import com.tonbeller.jpivot.olap.model.NumberFormat;
18 import com.tonbeller.jpivot.olap.model.impl.CellBase;
19 import com.tonbeller.jpivot.util.NumSeparators;
20
21 /**
22  * Cell Inplementation for Mondrian
23  */

24 public class MondrianCell extends CellBase {
25
26   static Logger logger = Logger.getLogger(MondrianModel.class);
27
28   private mondrian.olap.Cell monCell;
29   private MondrianModel model;
30
31   private boolean isGrouping = false;
32   private boolean isPercent = false;
33   private int fractionDigits = 0;
34
35   /**
36    * Constructor
37    */

38   protected MondrianCell(mondrian.olap.Cell monCell, MondrianModel model) {
39     this.monCell = monCell;
40     this.model = model;
41
42     /*
43      mondrian.olap.Member measure = monCell.getMeasure();
44      Exp formatExp = (Exp) measure.getPropertyValue(mondrian.olap.Property.PROPERTY_FORMAT_EXP);
45      String formatString = "Standard";
46      if (formatExp != null && formatExp instanceof mondrian.olap.Literal) {
47      Literal lit = (mondrian.olap.Literal) formatExp;
48      if (lit.getType() == Category.String) {
49      formatString = (String) lit.getValue();
50      }
51      }
52      
53      // Format is not very useful
54      Format format = Format.get(formatString, model.getLocale());
55      
56      numberFormat = new NumberFormat() {
57      public boolean isGrouping() {
58      return isGrouping;
59      }
60      public int getFractionDigits() {
61      return fractionDigits;
62      }
63      };
64      */

65   }
66
67   /**
68    * @see com.tonbeller.jpivot.olap.model.Cell#getValue()
69    */

70   public Object JavaDoc getValue() {
71     return monCell.getValue();
72   }
73
74   /**
75    * @see com.tonbeller.jpivot.olap.model.Cell#isNull()
76    */

77   public boolean isNull() {
78     return monCell.isNull();
79   }
80
81   /* determine formatting properties
82    * @see com.tonbeller.jpivot.olap.model.Cell#getFormat()
83    */

84   public NumberFormat getFormat() {
85     if (monCell.isNull())
86       return null;
87
88     Object JavaDoc o = monCell.getValue();
89     if (o instanceof Number JavaDoc) {
90       // continue
91
} else
92       return null;
93
94     isPercent = formattedValue.indexOf('%') >= 0;
95     NumSeparators sep = NumSeparators.instance(model.getLocale());
96
97     fractionDigits = 0;
98     if (formattedValue.indexOf(sep.thouSep) >= 0)
99       isGrouping = true;
100     int i = formattedValue.indexOf(sep.decimalSep);
101     if (i > 0) {
102       while (++i < formattedValue.length() && Character.isDigit(formattedValue.charAt(i)))
103         ++fractionDigits;
104     }
105
106     return new NumberFormat() {
107       public boolean isGrouping() {
108         return isGrouping;
109       }
110
111       public int getFractionDigits() {
112         return fractionDigits;
113       }
114
115       public boolean isPercent() {
116         return isPercent;
117       }
118     };
119
120   }
121
122   /**
123    * @return
124    */

125   public mondrian.olap.Cell getMonCell() {
126     return this.monCell;
127   }
128 } // End MondrianCell
129
Popular Tags