KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > record > formula > FuncPtg


1 /* ====================================================================
2    Copyright 2003-2004 Apache Software Foundation
3
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7
8        http://www.apache.org/licenses/LICENSE-2.0
9
10    Unless required by applicable law or agreed to in writing, software
11    distributed under the License is distributed on an "AS IS" BASIS,
12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    See the License for the specific language governing permissions and
14    limitations under the License.
15 ==================================================================== */

16
17
18 package org.apache.poi.hssf.record.formula;
19 import org.apache.poi.util.LittleEndian;
20
21 /**
22  * @author aviks
23  * @author Jason Height (jheight at chariot dot net dot au)
24  * @author Danny Mui (dmui at apache dot org) (Leftover handling)
25  */

26 public class FuncPtg extends AbstractFunctionPtg{
27     
28     public final static byte sid = 0x21;
29     public final static int SIZE = 3;
30     private int numParams=0;
31     
32     /**
33      * FuncPtgs are defined to be 4 bytes but the actual FuncPtg uses only 2 bytes.
34      * If we have leftOvers that are read from the file we should serialize them back out.
35      * <p>
36      * If the leftovers are removed, a prompt "Warning: Data may have been lost occurs in Excel"
37      */

38     //protected byte[] leftOvers = null;
39

40     private FuncPtg() {
41       //Required for clone methods
42
}
43
44     /**Creates new function pointer from a byte array
45      * usually called while reading an excel file.
46      */

47     public FuncPtg(byte[] data, int offset) {
48         offset++;
49         //field_1_num_args = data[ offset + 0 ];
50
field_2_fnc_index = LittleEndian.getShort(data,offset + 0 );
51         
52       /*
53         if (data.length - offset > 2) { //save left overs if there are any
54             leftOvers = new byte[2];
55             System.arraycopy(data, offset+1, leftOvers, 0, leftOvers.length);
56         }
57         */

58         try {
59             numParams = ( (Integer JavaDoc)functionData[field_2_fnc_index][2]).intValue();
60         } catch (NullPointerException JavaDoc npe) {
61             numParams=0;
62         }
63         
64     }
65     
66      public void writeBytes(byte[] array, int offset) {
67         array[offset+0]= (byte) (sid + ptgClass);
68         //array[offset+1]=field_1_num_args;
69
LittleEndian.putShort(array,offset+1,field_2_fnc_index);
70         /**if (leftOvers != null) {
71             System.arraycopy(leftOvers, 0, array, offset+2, leftOvers.length);
72         }**/

73     }
74     
75      public int getNumberOfOperands() {
76         return numParams;
77     }
78
79     public Object JavaDoc clone() {
80       FuncPtg ptg = new FuncPtg();
81       //ptg.field_1_num_args = field_1_num_args;
82
ptg.field_2_fnc_index = field_2_fnc_index;
83       ptg.setClass(ptgClass);
84      return ptg;
85     }
86     
87     public int getSize() {
88         return SIZE;
89     }
90     
91     public String JavaDoc toString() {
92         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
93         buffer
94         .append("<FunctionPtg>").append("\n")
95         .append(" numArgs(internal)=").append(this.numParams).append("\n")
96         .append(" name =").append(lookupName(field_2_fnc_index)).append("\n")
97         .append(" field_2_fnc_index=").append(field_2_fnc_index).append("\n")
98         .append("</FunctionPtg>");
99         return buffer.toString();
100     }
101 }
Popular Tags