001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hssf.record;
019:
020: import org.apache.poi.util.LittleEndian;
021:
022: /**
023: * Title: A sub Record for Extern Sheet <P>
024: * Description: Defines a named range within a workbook. <P>
025: * REFERENCE: <P>
026: * @author Libin Roman (Vista Portal LDT. Developer)
027: * @version 1.0-pre
028: */
029:
030: public class ExternSheetSubRecord extends Record {
031: public final static short sid = 0xFFF; // only here for conformance, doesn't really have an sid
032: private short field_1_index_to_supbook;
033: private short field_2_index_to_first_supbook_sheet;
034: private short field_3_index_to_last_supbook_sheet;
035:
036: /** a Constractor for making new sub record
037: */
038: public ExternSheetSubRecord() {
039: }
040:
041: /**
042: * Constructs a Extern Sheet Sub Record record and sets its fields appropriately.
043: *
044: * @param in the RecordInputstream to read the record from
045: */
046: public ExternSheetSubRecord(RecordInputStream in) {
047: super (in);
048: }
049:
050: /** Sets the Index to the sup book
051: * @param index sup book index
052: */
053: public void setIndexToSupBook(short index) {
054: field_1_index_to_supbook = index;
055: }
056:
057: /** gets the index to sup book
058: * @return sup book index
059: */
060: public short getIndexToSupBook() {
061: return field_1_index_to_supbook;
062: }
063:
064: /** sets the index to first sheet in supbook
065: * @param index index to first sheet
066: */
067: public void setIndexToFirstSupBook(short index) {
068: field_2_index_to_first_supbook_sheet = index;
069: }
070:
071: /** gets the index to first sheet from supbook
072: * @return index to first supbook
073: */
074: public short getIndexToFirstSupBook() {
075: return field_2_index_to_first_supbook_sheet;
076: }
077:
078: /** sets the index to last sheet in supbook
079: * @param index index to last sheet
080: */
081: public void setIndexToLastSupBook(short index) {
082: field_3_index_to_last_supbook_sheet = index;
083: }
084:
085: /** gets the index to last sheet in supbook
086: * @return index to last supbook
087: */
088: public short getIndexToLastSupBook() {
089: return field_3_index_to_last_supbook_sheet;
090: }
091:
092: /**
093: * called by constructor, should throw runtime exception in the event of a
094: * record passed with a differing ID.
095: *
096: * @param id alleged id for this record
097: */
098: protected void validateSid(short id) {
099: // do nothing
100: }
101:
102: /**
103: * @param in the RecordInputstream to read the record from
104: */
105: protected void fillFields(RecordInputStream in) {
106: field_1_index_to_supbook = in.readShort();
107: field_2_index_to_first_supbook_sheet = in.readShort();
108: field_3_index_to_last_supbook_sheet = in.readShort();
109: }
110:
111: public String toString() {
112: StringBuffer buffer = new StringBuffer();
113: buffer.append(" supbookindex =").append(getIndexToSupBook())
114: .append('\n');
115: buffer.append(" 1stsbindex =").append(
116: getIndexToFirstSupBook()).append('\n');
117: buffer.append(" lastsbindex =").append(
118: getIndexToLastSupBook()).append('\n');
119: return buffer.toString();
120: }
121:
122: /**
123: * called by the class that is responsible for writing this sucker.
124: * Subclasses should implement this so that their data is passed back in a
125: * byte array.
126: *
127: * @param offset to begin writing at
128: * @param data byte array containing instance data
129: * @return number of bytes written
130: */
131: public int serialize(int offset, byte[] data) {
132: LittleEndian.putShort(data, 0 + offset, getIndexToSupBook());
133: LittleEndian.putShort(data, 2 + offset,
134: getIndexToFirstSupBook());
135: LittleEndian
136: .putShort(data, 4 + offset, getIndexToLastSupBook());
137:
138: return getRecordSize();
139: }
140:
141: /** returns the record size
142: */
143: public int getRecordSize() {
144: return 6;
145: }
146:
147: /**
148: * return the non static version of the id for this record.
149: */
150: public short getSid() {
151: return sid;
152: }
153: }
|