KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hpsf > Variant


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 package org.apache.poi.hpsf;
19
20 import java.util.Collections JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.Map JavaDoc;
23
24 /**
25  * <p>The <em>Variant</em> types as defined by Microsoft's COM. I
26  * found this information in <a
27  * HREF="http://www.marin.clara.net/COM/variant_type_definitions.htm">
28  * http://www.marin.clara.net/COM/variant_type_definitions.htm</a>.</p>
29  *
30  * <p>In the variant types descriptions the following shortcuts are
31  * used: <strong> [V]</strong> - may appear in a VARIANT,
32  * <strong>[T]</strong> - may appear in a TYPEDESC,
33  * <strong>[P]</strong> - may appear in an OLE property set,
34  * <strong>[S]</strong> - may appear in a Safe Array.</p>
35  *
36  * @author Rainer Klute (klute@rainer-klute.de)
37  * @version $Id: Variant.java,v 1.10 2004/04/09 13:05:16 glens Exp $
38  * @since 2002-02-09
39  */

40 public class Variant
41 {
42
43     /**
44      * <p>[V][P] Nothing, i.e. not a single byte of data.</p>
45      */

46     public static final int VT_EMPTY = 0;
47
48     /**
49      * <p>[V][P] SQL style Null.</p>
50      */

51     public static final int VT_NULL = 1;
52
53     /**
54      * <p>[V][T][P][S] 2 byte signed int.</p>
55      */

56     public static final int VT_I2 = 2;
57
58     /**
59      * <p>[V][T][P][S] 4 byte signed int.</p>
60      */

61     public static final int VT_I4 = 3;
62
63     /**
64      * <p>[V][T][P][S] 4 byte real.</p>
65      */

66     public static final int VT_R4 = 4;
67
68     /**
69      * <p>[V][T][P][S] 8 byte real.</p>
70      */

71     public static final int VT_R8 = 5;
72
73     /**
74      * <p>[V][T][P][S] currency. <span style="background-color:
75      * #ffff00">How long is this? How is it to be
76      * interpreted?</span></p>
77      */

78     public static final int VT_CY = 6;
79
80     /**
81      * <p>[V][T][P][S] date. <span style="background-color:
82      * #ffff00">How long is this? How is it to be
83      * interpreted?</span></p>
84      */

85     public static final int VT_DATE = 7;
86
87     /**
88      * <p>[V][T][P][S] OLE Automation string. <span
89      * style="background-color: #ffff00">How long is this? How is it
90      * to be interpreted?</span></p>
91      */

92     public static final int VT_BSTR = 8;
93
94     /**
95      * <p>[V][T][P][S] IDispatch *. <span style="background-color:
96      * #ffff00">How long is this? How is it to be
97      * interpreted?</span></p>
98      */

99     public static final int VT_DISPATCH = 9;
100
101     /**
102      * <p>[V][T][S] SCODE. <span style="background-color: #ffff00">How
103      * long is this? How is it to be interpreted?</span></p>
104      */

105     public static final int VT_ERROR = 10;
106
107     /**
108      * <p>[V][T][P][S] True=-1, False=0.</p>
109      */

110     public static final int VT_BOOL = 11;
111
112     /**
113      * <p>[V][T][P][S] VARIANT *. <span style="background-color:
114      * #ffff00">How long is this? How is it to be
115      * interpreted?</span></p>
116      */

117     public static final int VT_VARIANT = 12;
118
119     /**
120      * <p>[V][T][S] IUnknown *. <span style="background-color:
121      * #ffff00">How long is this? How is it to be
122      * interpreted?</span></p>
123      */

124     public static final int VT_UNKNOWN = 13;
125
126     /**
127      * <p>[V][T][S] 16 byte fixed point.</p>
128      */

129     public static final int VT_DECIMAL = 14;
130
131     /**
132      * <p>[T] signed char.</p>
133      */

134     public static final int VT_I1 = 16;
135
136     /**
137      * <p>[V][T][P][S] unsigned char.</p>
138      */

139     public static final int VT_UI1 = 17;
140
141     /**
142      * <p>[T][P] unsigned short.</p>
143      */

144     public static final int VT_UI2 = 18;
145
146     /**
147      * <p>[T][P] unsigned int.</p>
148      */

149     public static final int VT_UI4 = 19;
150
151     /**
152      * <p>[T][P] signed 64-bit int.</p>
153      */

154     public static final int VT_I8 = 20;
155
156     /**
157      * <p>[T][P] unsigned 64-bit int.</p>
158      */

159     public static final int VT_UI8 = 21;
160
161     /**
162      * <p>[T] signed machine int.</p>
163      */

164     public static final int VT_INT = 22;
165
166     /**
167      * <p>[T] unsigned machine int.</p>
168      */

169     public static final int VT_UINT = 23;
170
171     /**
172      * <p>[T] C style void.</p>
173      */

174     public static final int VT_VOID = 24;
175
176     /**
177      * <p>[T] Standard return type. <span style="background-color:
178      * #ffff00">How long is this? How is it to be
179      * interpreted?</span></p>
180      */

181     public static final int VT_HRESULT = 25;
182
183     /**
184      * <p>[T] pointer type. <span style="background-color:
185      * #ffff00">How long is this? How is it to be
186      * interpreted?</span></p>
187      */

188     public static final int VT_PTR = 26;
189
190     /**
191      * <p>[T] (use VT_ARRAY in VARIANT).</p>
192      */

193     public static final int VT_SAFEARRAY = 27;
194
195     /**
196      * <p>[T] C style array. <span style="background-color:
197      * #ffff00">How long is this? How is it to be
198      * interpreted?</span></p>
199      */

200     public static final int VT_CARRAY = 28;
201
202     /**
203      * <p>[T] user defined type. <span style="background-color:
204      * #ffff00">How long is this? How is it to be
205      * interpreted?</span></p>
206      */

207     public static final int VT_USERDEFINED = 29;
208
209     /**
210      * <p>[T][P] null terminated string.</p>
211      */

212     public static final int VT_LPSTR = 30;
213
214     /**
215      * <p>[T][P] wide (Unicode) null terminated string.</p>
216      */

217     public static final int VT_LPWSTR = 31;
218
219     /**
220      * <p>[P] FILETIME. The FILETIME structure holds a date and time
221      * associated with a file. The structure identifies a 64-bit
222      * integer specifying the number of 100-nanosecond intervals which
223      * have passed since January 1, 1601. This 64-bit value is split
224      * into the two dwords stored in the structure.</p>
225      */

226     public static final int VT_FILETIME = 64;
227
228     /**
229      * <p>[P] Length prefixed bytes.</p>
230      */

231     public static final int VT_BLOB = 65;
232
233     /**
234      * <p>[P] Name of the stream follows.</p>
235      */

236     public static final int VT_STREAM = 66;
237
238     /**
239      * <p>[P] Name of the storage follows.</p>
240      */

241     public static final int VT_STORAGE = 67;
242
243     /**
244      * <p>[P] Stream contains an object. <span
245      * style="background-color: #ffff00"> How long is this? How is it
246      * to be interpreted?</span></p>
247      */

248     public static final int VT_STREAMED_OBJECT = 68;
249
250     /**
251      * <p>[P] Storage contains an object. <span
252      * style="background-color: #ffff00"> How long is this? How is it
253      * to be interpreted?</span></p>
254      */

255     public static final int VT_STORED_OBJECT = 69;
256
257     /**
258      * <p>[P] Blob contains an object. <span style="background-color:
259      * #ffff00">How long is this? How is it to be
260      * interpreted?</span></p>
261      */

262     public static final int VT_BLOB_OBJECT = 70;
263
264     /**
265      * <p>[P] Clipboard format. <span style="background-color:
266      * #ffff00">How long is this? How is it to be
267      * interpreted?</span></p>
268      */

269     public static final int VT_CF = 71;
270
271     /**
272      * <p>[P] A Class ID.</p>
273      *
274      * <p>It consists of a 32 bit unsigned integer indicating the size
275      * of the structure, a 32 bit signed integer indicating (Clipboard
276      * Format Tag) indicating the type of data that it contains, and
277      * then a byte array containing the data.</p>
278      *
279      * <p>The valid Clipboard Format Tags are:</p>
280      *
281      * <ul>
282      * <li>{@link Thumbnail#CFTAG_WINDOWS}</li>
283      * <li>{@link Thumbnail#CFTAG_MACINTOSH}</li>
284      * <li>{@link Thumbnail#CFTAG_NODATA}</li>
285      * <li>{@link Thumbnail#CFTAG_FMTID}</li>
286      * </ul>
287      *
288      * <pre>typedef struct tagCLIPDATA {
289      * // cbSize is the size of the buffer pointed to
290      * // by pClipData, plus sizeof(ulClipFmt)
291      * ULONG cbSize;
292      * long ulClipFmt;
293      * BYTE* pClipData;
294      * } CLIPDATA;</pre>
295      *
296      * <p>See <a
297      * HREF="msdn.microsoft.com/library/en-us/com/stgrstrc_0uwk.asp"
298      * target="_blank">
299      * msdn.microsoft.com/library/en-us/com/stgrstrc_0uwk.asp</a>.</p>
300      */

301     public static final int VT_CLSID = 72;
302
303     /**
304      * <p>[P] simple counted array. <span style="background-color:
305      * #ffff00">How long is this? How is it to be
306      * interpreted?</span></p>
307      */

308     public static final int VT_VECTOR = 0x1000;
309
310     /**
311      * <p>[V] SAFEARRAY*. <span style="background-color: #ffff00">How
312      * long is this? How is it to be interpreted?</span></p>
313      */

314     public static final int VT_ARRAY = 0x2000;
315
316     /**
317      * <p>[V] void* for local use. <span style="background-color:
318      * #ffff00">How long is this? How is it to be
319      * interpreted?</span></p>
320      */

321     public static final int VT_BYREF = 0x4000;
322
323     /**
324      * <p>FIXME (3): Document this!</p>
325      */

326     public static final int VT_RESERVED = 0x8000;
327
328     /**
329      * <p>FIXME (3): Document this!</p>
330      */

331     public static final int VT_ILLEGAL = 0xFFFF;
332
333     /**
334      * <p>FIXME (3): Document this!</p>
335      */

336     public static final int VT_ILLEGALMASKED = 0xFFF;
337
338     /**
339      * <p>FIXME (3): Document this!</p>
340      */

341     public static final int VT_TYPEMASK = 0xFFF;
342
343
344
345     /**
346      * <p>Maps the numbers denoting the variant types to their corresponding
347      * variant type names.</p>
348      */

349     private static Map JavaDoc numberToName;
350
351     private static Map JavaDoc numberToLength;
352
353     /**
354      * <p>Denotes a variant type with a length that is unknown to HPSF yet.</p>
355      */

356     public static final Integer JavaDoc LENGTH_UNKNOWN = new Integer JavaDoc(-2);
357
358     /**
359      * <p>Denotes a variant type with a variable length.</p>
360      */

361     public static final Integer JavaDoc LENGTH_VARIABLE = new Integer JavaDoc(-1);
362
363     /**
364      * <p>Denotes a variant type with a length of 0 bytes.</p>
365      */

366     public static final Integer JavaDoc LENGTH_0 = new Integer JavaDoc(0);
367
368     /**
369      * <p>Denotes a variant type with a length of 2 bytes.</p>
370      */

371     public static final Integer JavaDoc LENGTH_2 = new Integer JavaDoc(2);
372
373     /**
374      * <p>Denotes a variant type with a length of 4 bytes.</p>
375      */

376     public static final Integer JavaDoc LENGTH_4 = new Integer JavaDoc(4);
377
378     /**
379      * <p>Denotes a variant type with a length of 8 bytes.</p>
380      */

381     public static final Integer JavaDoc LENGTH_8 = new Integer JavaDoc(8);
382
383
384
385     static
386     {
387         /* Initialize the number-to-name map: */
388         Map JavaDoc tm1 = new HashMap JavaDoc();
389         tm1.put(new Long JavaDoc(0), "VT_EMPTY");
390         tm1.put(new Long JavaDoc(1), "VT_NULL");
391         tm1.put(new Long JavaDoc(2), "VT_I2");
392         tm1.put(new Long JavaDoc(3), "VT_I4");
393         tm1.put(new Long JavaDoc(4), "VT_R4");
394         tm1.put(new Long JavaDoc(5), "VT_R8");
395         tm1.put(new Long JavaDoc(6), "VT_CY");
396         tm1.put(new Long JavaDoc(7), "VT_DATE");
397         tm1.put(new Long JavaDoc(8), "VT_BSTR");
398         tm1.put(new Long JavaDoc(9), "VT_DISPATCH");
399         tm1.put(new Long JavaDoc(10), "VT_ERROR");
400         tm1.put(new Long JavaDoc(11), "VT_BOOL");
401         tm1.put(new Long JavaDoc(12), "VT_VARIANT");
402         tm1.put(new Long JavaDoc(13), "VT_UNKNOWN");
403         tm1.put(new Long JavaDoc(14), "VT_DECIMAL");
404         tm1.put(new Long JavaDoc(16), "VT_I1");
405         tm1.put(new Long JavaDoc(17), "VT_UI1");
406         tm1.put(new Long JavaDoc(18), "VT_UI2");
407         tm1.put(new Long JavaDoc(19), "VT_UI4");
408         tm1.put(new Long JavaDoc(20), "VT_I8");
409         tm1.put(new Long JavaDoc(21), "VT_UI8");
410         tm1.put(new Long JavaDoc(22), "VT_INT");
411         tm1.put(new Long JavaDoc(23), "VT_UINT");
412         tm1.put(new Long JavaDoc(24), "VT_VOID");
413         tm1.put(new Long JavaDoc(25), "VT_HRESULT");
414         tm1.put(new Long JavaDoc(26), "VT_PTR");
415         tm1.put(new Long JavaDoc(27), "VT_SAFEARRAY");
416         tm1.put(new Long JavaDoc(28), "VT_CARRAY");
417         tm1.put(new Long JavaDoc(29), "VT_USERDEFINED");
418         tm1.put(new Long JavaDoc(30), "VT_LPSTR");
419         tm1.put(new Long JavaDoc(31), "VT_LPWSTR");
420         tm1.put(new Long JavaDoc(64), "VT_FILETIME");
421         tm1.put(new Long JavaDoc(65), "VT_BLOB");
422         tm1.put(new Long JavaDoc(66), "VT_STREAM");
423         tm1.put(new Long JavaDoc(67), "VT_STORAGE");
424         tm1.put(new Long JavaDoc(68), "VT_STREAMED_OBJECT");
425         tm1.put(new Long JavaDoc(69), "VT_STORED_OBJECT");
426         tm1.put(new Long JavaDoc(70), "VT_BLOB_OBJECT");
427         tm1.put(new Long JavaDoc(71), "VT_CF");
428         tm1.put(new Long JavaDoc(72), "VT_CLSID");
429         Map JavaDoc tm2 = new HashMap JavaDoc(tm1.size(), 1.0F);
430         tm2.putAll(tm1);
431         numberToName = Collections.unmodifiableMap(tm2);
432
433         /* Initialize the number-to-length map: */
434         tm1.clear();
435         tm1.put(new Long JavaDoc(0), LENGTH_0);
436         tm1.put(new Long JavaDoc(1), LENGTH_UNKNOWN);
437         tm1.put(new Long JavaDoc(2), LENGTH_2);
438         tm1.put(new Long JavaDoc(3), LENGTH_4);
439         tm1.put(new Long JavaDoc(4), LENGTH_4);
440         tm1.put(new Long JavaDoc(5), LENGTH_8);
441         tm1.put(new Long JavaDoc(6), LENGTH_UNKNOWN);
442         tm1.put(new Long JavaDoc(7), LENGTH_UNKNOWN);
443         tm1.put(new Long JavaDoc(8), LENGTH_UNKNOWN);
444         tm1.put(new Long JavaDoc(9), LENGTH_UNKNOWN);
445         tm1.put(new Long JavaDoc(10), LENGTH_UNKNOWN);
446         tm1.put(new Long JavaDoc(11), LENGTH_UNKNOWN);
447         tm1.put(new Long JavaDoc(12), LENGTH_UNKNOWN);
448         tm1.put(new Long JavaDoc(13), LENGTH_UNKNOWN);
449         tm1.put(new Long JavaDoc(14), LENGTH_UNKNOWN);
450         tm1.put(new Long JavaDoc(16), LENGTH_UNKNOWN);
451         tm1.put(new Long JavaDoc(17), LENGTH_UNKNOWN);
452         tm1.put(new Long JavaDoc(18), LENGTH_UNKNOWN);
453         tm1.put(new Long JavaDoc(19), LENGTH_UNKNOWN);
454         tm1.put(new Long JavaDoc(20), LENGTH_UNKNOWN);
455         tm1.put(new Long JavaDoc(21), LENGTH_UNKNOWN);
456         tm1.put(new Long JavaDoc(22), LENGTH_UNKNOWN);
457         tm1.put(new Long JavaDoc(23), LENGTH_UNKNOWN);
458         tm1.put(new Long JavaDoc(24), LENGTH_UNKNOWN);
459         tm1.put(new Long JavaDoc(25), LENGTH_UNKNOWN);
460         tm1.put(new Long JavaDoc(26), LENGTH_UNKNOWN);
461         tm1.put(new Long JavaDoc(27), LENGTH_UNKNOWN);
462         tm1.put(new Long JavaDoc(28), LENGTH_UNKNOWN);
463         tm1.put(new Long JavaDoc(29), LENGTH_UNKNOWN);
464         tm1.put(new Long JavaDoc(30), LENGTH_VARIABLE);
465         tm1.put(new Long JavaDoc(31), LENGTH_UNKNOWN);
466         tm1.put(new Long JavaDoc(64), LENGTH_8);
467         tm1.put(new Long JavaDoc(65), LENGTH_UNKNOWN);
468         tm1.put(new Long JavaDoc(66), LENGTH_UNKNOWN);
469         tm1.put(new Long JavaDoc(67), LENGTH_UNKNOWN);
470         tm1.put(new Long JavaDoc(68), LENGTH_UNKNOWN);
471         tm1.put(new Long JavaDoc(69), LENGTH_UNKNOWN);
472         tm1.put(new Long JavaDoc(70), LENGTH_UNKNOWN);
473         tm1.put(new Long JavaDoc(71), LENGTH_UNKNOWN);
474         tm1.put(new Long JavaDoc(72), LENGTH_UNKNOWN);
475         tm2 = new HashMap JavaDoc(tm1.size(), 1.0F);
476         tm2.putAll(tm1);
477         numberToLength = Collections.unmodifiableMap(tm2);
478     }
479
480
481
482     /**
483      * <p>Returns the variant type name associated with a variant type
484      * number.</p>
485      *
486      * @param variantType The variant type number
487      * @return The variant type name or the string "unknown variant type"
488      */

489     public static String JavaDoc getVariantName(final long variantType)
490     {
491         final String JavaDoc name = (String JavaDoc) numberToName.get(new Long JavaDoc(variantType));
492         return name != null ? name : "unknown variant type";
493     }
494
495     /**
496      * <p>Returns a variant type's length.</p>
497      *
498      * @param variantType The variant type number
499      * @return The length of the variant type's data in bytes. If the length is
500      * variable, i.e. the length of a string, -1 is returned. If HPSF does not
501      * know the length, -2 is returned. The latter usually indicates an
502      * unsupported variant type.
503      */

504     public static int getVariantLength(final long variantType)
505     {
506         final Long JavaDoc key = new Long JavaDoc((int) variantType);
507         final Long JavaDoc length = (Long JavaDoc) numberToLength.get(key);
508         if (length == null)
509             return -2;
510         return length.intValue();
511     }
512
513 }
514
Popular Tags