KickJava   Java API By Example, From Geeks To Geeks.

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


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: A sub Record for Extern Sheet <P>
25  * Description: Defines a named range within a workbook. <P>
26  * REFERENCE: <P>
27  * @author Libin Roman (Vista Portal LDT. Developer)
28  * @version 1.0-pre
29  */

30
31 public class ExternSheetSubRecord extends Record {
32     public final static short sid = 0xFFF; // only here for conformance, doesn't really have an sid
33
private short field_1_index_to_supbook;
34     private short field_2_index_to_first_supbook_sheet;
35     private short field_3_index_to_last_supbook_sheet;
36     
37     
38     /** a Constractor for making new sub record
39      */

40     public ExternSheetSubRecord() {
41     }
42     
43     /**
44      * Constructs a Extern Sheet Sub Record record and sets its fields appropriately.
45      *
46      * @param id id must be 0x18 or an exception will be throw upon validation
47      * @param size the size of the data area of the record
48      * @param data data of the record (should not contain sid/len)
49      */

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

62     public ExternSheetSubRecord(short id, short size, byte[] data, int offset) {
63         super(id, size, data, offset);
64     }
65     
66     /** Sets the Index to the sup book
67      * @param index sup book index
68      */

69     public void setIndexToSupBook(short index){
70         field_1_index_to_supbook = index;
71     }
72     
73     /** gets the index to sup book
74      * @return sup book index
75      */

76     public short getIndexToSupBook(){
77         return field_1_index_to_supbook;
78     }
79     
80     /** sets the index to first sheet in supbook
81      * @param index index to first sheet
82      */

83     public void setIndexToFirstSupBook(short index){
84         field_2_index_to_first_supbook_sheet = index;
85     }
86     
87     /** gets the index to first sheet from supbook
88      * @return index to first supbook
89      */

90     public short getIndexToFirstSupBook(){
91         return field_2_index_to_first_supbook_sheet;
92     }
93     
94     /** sets the index to last sheet in supbook
95      * @param index index to last sheet
96      */

97     public void setIndexToLastSupBook(short index){
98         field_3_index_to_last_supbook_sheet = index;
99     }
100     
101     /** gets the index to last sheet in supbook
102      * @return index to last supbook
103      */

104     public short getIndexToLastSupBook(){
105         return field_3_index_to_last_supbook_sheet;
106     }
107     
108     /**
109      * called by constructor, should throw runtime exception in the event of a
110      * record passed with a differing ID.
111      *
112      * @param id alleged id for this record
113      */

114     protected void validateSid(short id) {
115         // do nothing
116
}
117     
118     /**
119      * called by the constructor, should set class level fields. Should throw
120      * runtime exception for bad/icomplete data.
121      *
122      * @param data raw data
123      * @param size size of data
124      * @param offset of the record's data (provided a big array of the file)
125      */

126     protected void fillFields(byte [] data, short size, int offset) {
127         field_1_index_to_supbook = LittleEndian.getShort(data, 0 + offset);
128         field_2_index_to_first_supbook_sheet = LittleEndian.getShort(data, 2 + offset);
129         field_3_index_to_last_supbook_sheet = LittleEndian.getShort(data, 4 + offset);
130     }
131     
132     
133     public String JavaDoc toString() {
134         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
135         buffer.append(" supbookindex =").append(getIndexToSupBook()).append('\n');
136         buffer.append(" 1stsbindex =").append(getIndexToFirstSupBook()).append('\n');
137         buffer.append(" lastsbindex =").append(getIndexToLastSupBook()).append('\n');
138         return buffer.toString();
139     }
140     
141     /**
142      * called by the class that is responsible for writing this sucker.
143      * Subclasses should implement this so that their data is passed back in a
144      * byte array.
145      *
146      * @param offset to begin writing at
147      * @param data byte array containing instance data
148      * @return number of bytes written
149      */

150     public int serialize(int offset, byte [] data) {
151         LittleEndian.putShort(data, 0 + offset, getIndexToSupBook());
152         LittleEndian.putShort(data, 2 + offset, getIndexToFirstSupBook());
153         LittleEndian.putShort(data, 4 + offset, getIndexToLastSupBook());
154         
155         return getRecordSize();
156     }
157     
158     
159     /** returns the record size
160      */

161     public int getRecordSize() {
162         return 6;
163     }
164     
165     /**
166      * return the non static version of the id for this record.
167      */

168     public short getSid() {
169         return this.sid;
170     }
171 }
172
Popular Tags