KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > xmla > XMLA_Cell


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.xmla;
14
15 import com.tonbeller.jpivot.olap.model.NumberFormat;
16 import com.tonbeller.jpivot.olap.model.impl.CellBase;
17 import com.tonbeller.jpivot.util.NumSeparators;
18
19 /**
20  * Cell Implementation for XMLA
21  */

22 public class XMLA_Cell extends CellBase {
23
24   private Object JavaDoc value = null;
25   private int ordinal;
26   private XMLA_Model model;
27
28   // dsf add model to the constructor
29
public XMLA_Cell(int ordinal,XMLA_Model model) {
30     this.model = model;
31     this.ordinal = ordinal;
32     formattedValue = "(null)";
33   }
34  
35   /**
36    * @see com.tonbeller.jpivot.olap.model.Cell#getValue()
37    */

38   public Object JavaDoc getValue() {
39     return value;
40   }
41
42   /**
43    * Sets the value.
44    * @param value The value to set
45    */

46   public void setValue(Object JavaDoc value) {
47     this.value = value;
48   }
49
50   /**
51    * Returns the ordinal.
52    * @return int
53    */

54   public int getOrdinal() {
55     return ordinal;
56   }
57
58   /**
59     * @see com.tonbeller.jpivot.olap.model.Cell#isNull()
60     */

61   public boolean isNull() {
62     return (value == null);
63   }
64
65   /**
66    * @see com.tonbeller.jpivot.olap.model.Cell#getFormat()
67    */

68   public NumberFormat getFormat() {
69       // NumberFormat retVal = null;
70

71       if (this.getValue()==null)
72           return null;
73
74         if (this.getValue() instanceof Number JavaDoc) {
75           // continue
76
} else
77           return null;
78
79         boolean isPercent = formattedValue.indexOf('%') >= 0;
80         boolean isGrouping = false;
81         NumSeparators sep = NumSeparators.instance(model.getLocale());
82
83         int fractionDigits = 0;
84         if (formattedValue.indexOf(sep.thouSep) >= 0)
85           isGrouping = true;
86         int i = formattedValue.indexOf(sep.decimalSep);
87         if (i > 0) {
88           while (++i < formattedValue.length() && Character.isDigit(formattedValue.charAt(i)))
89             ++fractionDigits;
90         }
91         
92         return new NumFmt(isGrouping, fractionDigits, isPercent);
93         
94   }
95
96 /**
97  * @return Returns the model.
98  */

99 public XMLA_Model getModel() {
100     return model;
101 }
102 /**
103  * @param model The model to set.
104  */

105 public void setModel(XMLA_Model model) {
106     this.model = model;
107 }
108 } // XMLA_Cell
109

110 /**
111  *
112  * TODO Should make public accessors and use this instead: com.tonbeller.olap.model.impl.NumberFormatImpl?
113  */

114 class NumFmt implements NumberFormat{
115     
116     private boolean isGrouping;
117     private int fractionDigits;
118     private boolean isPercent;
119     public NumFmt(boolean isGrouping, int fractionDigits, boolean isPercent) {
120         this.isGrouping = isGrouping;
121         this.fractionDigits = fractionDigits;
122         this.isPercent = isPercent;
123     }
124
125
126     public int getFractionDigits() {
127         return fractionDigits;
128     }
129
130     public void setFractionDigits(int fractionDigits) {
131         this.fractionDigits = fractionDigits;
132     }
133
134     public boolean isGrouping() {
135         return isGrouping;
136     }
137
138     public void setGrouping(boolean isGrouping) {
139         this.isGrouping = isGrouping;
140     }
141
142     public boolean isPercent() {
143         return isPercent;
144     }
145
146     public void setPercent(boolean isPercent) {
147         this.isPercent = isPercent;
148     }
149 }
Popular Tags