KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > record > SupBookRecord


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

17         
18
19 package org.apache.poi.hssf.record;
20
21 import org.apache.poi.util.LittleEndian;
22
23 /**
24  * Title: Sup Book <P>
25  * Description: A Extrenal Workbook Deciption (Sup Book)
26  * Its only a dummy record for making new ExternSheet Record <P>
27  * REFERENCE: <P>
28  * @author Libin Roman (Vista Portal LDT. Developer)
29  * @author Andrew C. Oliver (acoliver@apache.org)
30  *
31  */

32 public class SupBookRecord extends Record
33 {
34     public final static short sid = 0x1AE;
35     private short field_1_number_of_sheets;
36     private short field_2_flag;
37
38
39     public SupBookRecord()
40     {
41         setFlag((short)0x401);
42     }
43
44     /**
45      * Constructs a Extern Sheet record and sets its fields appropriately.
46      *
47      * @param id id must be 0x16 or an exception will be throw upon validation
48      * @param size the size of the data area of the record
49      * @param data data of the record (should not contain sid/len)
50      */

51     public SupBookRecord(short id, short size, byte[] data)
52     {
53         super(id, size, data);
54     }
55
56     /**
57      * Constructs a Extern Sheet record and sets its fields appropriately.
58      *
59      * @param id id must be 0x1ae or an exception will be throw upon validation
60      * @param size the size of the data area of the record
61      * @param data data of the record (should not contain sid/len)
62      * @param offset of the record's data
63      */

64     public SupBookRecord(short id, short size, byte[] data, int offset)
65     {
66         super(id, size, data, offset);
67     }
68
69     protected void validateSid(short id)
70     {
71         if (id != sid)
72         {
73             throw new RecordFormatException("NOT An Supbook RECORD");
74         }
75     }
76
77     /**
78      * called by the constructor, should set class level fields. Should throw
79      * runtime exception for bad/icomplete data.
80      *
81      * @param data raw data
82      * @param size size of data
83      * @param offset of the record's data (provided a big array of the file)
84      */

85     protected void fillFields(byte [] data, short size, int offset)
86     {
87         //For now We use it only for one case
88
//When we need to add an named range when no named ranges was
89
//before it
90
field_1_number_of_sheets = LittleEndian.getShort(data,offset+0);
91         field_2_flag = LittleEndian.getShort(data,offset+2);
92     }
93
94
95     public String JavaDoc toString()
96     {
97         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
98         buffer.append("[SUPBOOK]\n");
99         buffer.append("numberosheets = ").append(getNumberOfSheets()).append('\n');
100         buffer.append("flag = ").append(getFlag()).append('\n');
101         buffer.append("[/SUPBOOK]\n");
102         return buffer.toString();
103     }
104
105     /**
106      * called by the class that is responsible for writing this sucker.
107      * Subclasses should implement this so that their data is passed back in a
108      * byte array.
109      *
110      * @param offset to begin writing at
111      * @param data byte array containing instance data
112      * @return number of bytes written
113      */

114     public int serialize(int offset, byte [] data)
115     {
116         LittleEndian.putShort(data, 0 + offset, sid);
117         LittleEndian.putShort(data, 2 + offset, (short) 4);
118         LittleEndian.putShort(data, 4 + offset, field_1_number_of_sheets);
119         LittleEndian.putShort(data, 6 + offset, field_2_flag);
120
121         return getRecordSize();
122     }
123
124     public void setNumberOfSheets(short number){
125         field_1_number_of_sheets = number;
126     }
127
128     public short getNumberOfSheets(){
129         return field_1_number_of_sheets;
130     }
131
132     public void setFlag(short flag){
133         field_2_flag = flag;
134     }
135
136     public short getFlag() {
137         return field_2_flag;
138     }
139
140     public int getRecordSize()
141     {
142         return 4 + 4;
143     }
144
145     public short getSid()
146     {
147         return this.sid;
148     }
149 }
150
Popular Tags