KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hdf > generator > HDFFieldIterator


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.hdf.generator;
20
21 import org.apache.poi.generator.FieldIterator;
22 import org.apache.poi.generator.RecordUtil;
23
24 /**
25  * This class overrides FieldIterator to handle HDF specific types
26  */

27 public class HDFFieldIterator extends FieldIterator
28 {
29
30     public HDFFieldIterator()
31     {
32     }
33
34     public String JavaDoc fillDecoder(String JavaDoc size, String JavaDoc type)
35     {
36
37         String JavaDoc result = "";
38
39         if (type.equals("short[]"))
40             result = "LittleEndian.getSimpleShortArray(data, 0x" + Integer.toHexString(offset) + " + offset," + size + ")";
41         else if (type.equals("byte[]"))
42             result = "LittleEndian.getByteArray(data, 0x" + Integer.toHexString(offset) + " + offset," + size + ")";
43         else if (type.equals("BorderCode"))
44             result = "new BorderCode(data, 0x" + Integer.toHexString(offset) + " + offset)";
45         else if (type.equals("DateAndTime"))
46             result = "new DateAndTime(data, 0x" + Integer.toHexString(offset) + " + offset)";
47         else if (size.equals("2"))
48             result = "LittleEndian.getShort(data, 0x" + Integer.toHexString(offset) + " + offset)";
49         else if (size.equals("4"))
50             result = "LittleEndian.getInt(data, 0x" + Integer.toHexString(offset) + " + offset)";
51         else if (size.equals("1"))
52             result = "data[ 0x" + Integer.toHexString(offset) + " + offset ]";
53         else if (type.equals("double"))
54             result = "LittleEndian.getDouble(data, 0x" + Integer.toHexString(offset) + " + offset)";
55
56         try
57         {
58             offset += Integer.parseInt(size);
59         }
60         catch (NumberFormatException JavaDoc ignore)
61         {
62         }
63         return result;
64     }
65
66     public String JavaDoc serialiseEncoder( int fieldNumber, String JavaDoc fieldName, String JavaDoc size, String JavaDoc type)
67     {
68         //String javaType = RecordUtil.getType(size, type, 0);
69
String JavaDoc javaFieldName = RecordUtil.getFieldName(fieldNumber,fieldName,0);
70
71         String JavaDoc result = "";
72
73
74         if (type.equals("short[]"))
75             result = "LittleEndian.putShortArray(data, 0x" + Integer.toHexString(offset) + " + offset, " + javaFieldName + ");";
76         else if (type.equals("byte[]"))
77             result = "System.arraycopy(" + javaFieldName + ", 0, data, 0x" + Integer.toHexString(offset) + " + offset, " + javaFieldName + ".length);";
78         else if (type.equals("BorderCode"))
79             result = javaFieldName + ".serialize(data, 0x" + Integer.toHexString(offset) + " + offset);";
80         else if (type.equals("DateAndTime"))
81            result = javaFieldName + ".serialize(data, 0x" + Integer.toHexString(offset) + " + offset);";
82         else if (size.equals("2"))
83           result = "LittleEndian.putShort(data, 0x" + Integer.toHexString(offset) + " + offset, (short)" + javaFieldName + ");";
84         else if (size.equals("4"))
85           result = "LittleEndian.putInt(data, 0x" + Integer.toHexString(offset) + " + offset, " + javaFieldName + ");";
86         else if (size.equals("1"))
87             result = "data[ 0x" + Integer.toHexString(offset) + " + offset] = " + javaFieldName + ";";
88         else if (type.equals("double"))
89             result = "LittleEndian.putDouble(data, 0x" + Integer.toHexString(offset) + " + offset, " + javaFieldName + ");";
90
91         try
92         {
93             offset += Integer.parseInt(size);
94         }
95         catch (NumberFormatException JavaDoc ignore)
96         {
97         }
98         return result;
99
100     }
101
102 }
103
Popular Tags