KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > read > biff > BaseSharedFormulaRecord


1 /*********************************************************************
2 *
3 * Copyright (C) 2002 Andrew Khan
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ***************************************************************************/

19
20 package jxl.read.biff;
21
22 import jxl.biff.FormattingRecords;
23 import jxl.biff.FormulaData;
24 import jxl.biff.WorkbookMethods;
25 import jxl.biff.formula.FormulaParser;
26 import jxl.biff.formula.ExternalSheet;
27 import jxl.biff.formula.FormulaException;
28
29 /**
30  * A base class for shared formula records
31  */

32 public abstract class BaseSharedFormulaRecord extends CellValue
33   implements FormulaData
34 {
35   /**
36    * The formula as an excel string
37    */

38   private String JavaDoc formulaString;
39
40   /**
41    * The position of the next record in the file. Used when looking for
42    * for subsequent records eg. a string value
43    */

44   private int filePos;
45
46   /**
47    * The array of parsed tokens
48    */

49   private byte[] tokens;
50
51   /**
52    * The external sheet
53    */

54   private ExternalSheet externalSheet;
55
56   /**
57    * The name table
58    */

59   private WorkbookMethods nameTable;
60
61   /**
62    * Constructs this number
63    *
64    * @param t the record
65    * @param fr the formatting records
66    * @param es the external sheet
67    * @param nt the name table
68    * @param si the sheet
69    * @param pos the position of the next record in the file
70    */

71   public BaseSharedFormulaRecord(Record t,
72                                  FormattingRecords fr,
73                                  ExternalSheet es,
74                                  WorkbookMethods nt,
75                                  SheetImpl si,
76                                  int pos)
77   {
78     super(t, fr, si);
79     externalSheet = es;
80     nameTable = nt;
81     filePos = pos;
82   }
83
84   /**
85    * Gets the formula as an excel string
86    *
87    * @return the formula as an excel string
88    * @exception FormulaException
89    */

90   public String JavaDoc getFormula() throws FormulaException
91   {
92     if (formulaString == null)
93     {
94       FormulaParser fp = new FormulaParser
95         (tokens, this, externalSheet, nameTable,
96          getSheet().getWorkbook().getSettings());
97       fp.parse();
98       formulaString = fp.getFormula();
99     }
100
101     return formulaString;
102   }
103
104   /**
105    * Called by the shared formula record to set the tokens for
106    * this formula
107    *
108    * @param t the tokens
109    */

110   void setTokens(byte[] t)
111   {
112     tokens = t;
113   }
114
115   /**
116    * Accessor for the tokens which make up this formula
117    *
118    * @return the tokens
119    */

120   protected final byte[] getTokens()
121   {
122     return tokens;
123   }
124
125   /**
126    * Access for the external sheet
127    *
128    * @return the external sheet
129    */

130   protected final ExternalSheet getExternalSheet()
131   {
132     return externalSheet;
133   }
134
135   /**
136    * Access for the name table
137    *
138    * @return the name table
139    */

140   protected final WorkbookMethods getNameTable()
141   {
142     return nameTable;
143   }
144
145   /**
146    * In case the shared formula is not added for any reason, we need
147    * to expose the raw record data , in order to try again
148    *
149    * @return the record data from the base class
150    */

151   public Record getRecord()
152   {
153     return super.getRecord();
154   }
155
156   /**
157    * Accessor for the position of the next record
158    *
159    * @return the position of the next record
160    */

161   final int getFilePos()
162   {
163     return filePos;
164   }
165 }
166
167
168
169
170
171
172
173
174
175
Popular Tags