KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
22  * Subrecords are part of the OBJ class.
23  */

24 abstract public class SubRecord
25         extends Record
26 {
27     public SubRecord()
28     {
29     }
30
31     public SubRecord( short id, short size, byte[] data )
32     {
33         super( id, size, data );
34     }
35
36     public SubRecord( short id, short size, byte[] data, int offset )
37     {
38         super( id, size, data, offset );
39     }
40
41     public static Record createSubRecord( short subRecordSid, short size, byte[] data, int offset )
42     {
43         Record r = null;
44
45         short adjustedSize = size;
46         if ( size < 0 )
47         {
48             adjustedSize = 0;
49         }
50         else if ( offset + size > data.length )
51         {
52             adjustedSize = (short) ( data.length - offset );
53             if ( adjustedSize > 4 )
54             {
55                 adjustedSize -= 4;
56             }
57         }
58
59         switch ( subRecordSid )
60         {
61             case CommonObjectDataSubRecord.sid:
62                 r = new CommonObjectDataSubRecord( subRecordSid, adjustedSize, data, offset );
63                 break;
64             case GroupMarkerSubRecord.sid:
65                 r = new GroupMarkerSubRecord( subRecordSid, adjustedSize, data, offset );
66                 break;
67             case EndSubRecord.sid:
68                 r = new EndSubRecord( subRecordSid, adjustedSize, data, offset );
69                 break;
70             default:
71                 r = new UnknownRecord( subRecordSid, adjustedSize, data, offset );
72         }
73
74         return r;
75     }
76 }
77
Popular Tags