KickJava   Java API By Example, From Geeks To Geeks.

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


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
20 package org.apache.poi.hssf.record;
21
22
23
24 import org.apache.poi.util.*;
25
26 /**
27  * The units record describes units.
28  * NOTE: This source is automatically generated please do not modify this file. Either subclass or
29  * remove the record in src/records/definitions.
30
31  * @author Glen Stampoultzis (glens at apache.org)
32  */

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

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

69
70     public UnitsRecord(short id, short size, byte [] data, int offset)
71     {
72         super(id, size, data, offset);
73     
74     }
75
76     /**
77      * Checks the sid matches the expected side for this record
78      *
79      * @param id the expected sid.
80      */

81     protected void validateSid(short id)
82     {
83         if (id != sid)
84         {
85             throw new RecordFormatException("Not a Units record");
86         }
87     }
88
89     protected void fillFields(byte [] data, short size, int offset)
90     {
91
92         int pos = 0;
93         field_1_units = LittleEndian.getShort(data, pos + 0x0 + offset);
94
95     }
96
97     public String JavaDoc toString()
98     {
99         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
100
101         buffer.append("[UNITS]\n");
102         buffer.append(" .units = ")
103             .append("0x").append(HexDump.toHex( getUnits ()))
104             .append(" (").append( getUnits() ).append(" )");
105         buffer.append(System.getProperty("line.separator"));
106
107         buffer.append("[/UNITS]\n");
108         return buffer.toString();
109     }
110
111     public int serialize(int offset, byte[] data)
112     {
113         int pos = 0;
114
115         LittleEndian.putShort(data, 0 + offset, sid);
116         LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
117
118         LittleEndian.putShort(data, 4 + offset + pos, field_1_units);
119
120         return getRecordSize();
121     }
122
123     /**
124      * Size of record (exluding 4 byte header)
125      */

126     public int getRecordSize()
127     {
128         return 4 + 2;
129     }
130
131     public short getSid()
132     {
133         return this.sid;
134     }
135
136     public Object JavaDoc clone() {
137         UnitsRecord rec = new UnitsRecord();
138     
139         rec.field_1_units = field_1_units;
140         return rec;
141     }
142
143
144
145
146     /**
147      * Get the units field for the Units record.
148      */

149     public short getUnits()
150     {
151         return field_1_units;
152     }
153
154     /**
155      * Set the units field for the Units record.
156      */

157     public void setUnits(short field_1_units)
158     {
159         this.field_1_units = field_1_units;
160     }
161
162
163 } // END OF CLASS
164

165
166
167
168
Popular Tags