/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*
The Variant types as defined by Microsoft's COM. I * found this information in * http://www.marin.clara.net/COM/variant_type_definitions.htm.
* *In the variant types descriptions the following shortcuts are * used: [V] - may appear in a VARIANT, * [T] - may appear in a TYPEDESC, * [P] - may appear in an OLE property set, * [S] - may appear in a Safe Array.
* * @author Rainer Klute (klute@rainer-klute.de) * @version $Id$ * @since 2002-02-09 */ public class Variant { /** *[V][P] Nothing, i.e. not a single byte of data.
*/ public static final int VT_EMPTY = 0; /** *[V][P] SQL style Null.
*/ public static final int VT_NULL = 1; /** *[V][T][P][S] 2 byte signed int.
*/ public static final int VT_I2 = 2; /** *[V][T][P][S] 4 byte signed int.
*/ public static final int VT_I4 = 3; /** *[V][T][P][S] 4 byte real.
*/ public static final int VT_R4 = 4; /** *[V][T][P][S] 8 byte real.
*/ public static final int VT_R8 = 5; /** *[V][T][P][S] currency. How long is this? How is it to be * interpreted?
*/ public static final int VT_CY = 6; /** *[V][T][P][S] date. How long is this? How is it to be * interpreted?
*/ public static final int VT_DATE = 7; /** *[V][T][P][S] OLE Automation string. How long is this? How is it * to be interpreted?
*/ public static final int VT_BSTR = 8; /** *[V][T][P][S] IDispatch *. How long is this? How is it to be * interpreted?
*/ public static final int VT_DISPATCH = 9; /** *[V][T][S] SCODE. How * long is this? How is it to be interpreted?
*/ public static final int VT_ERROR = 10; /** *[V][T][P][S] True=-1, False=0.
*/ public static final int VT_BOOL = 11; /** *[V][T][P][S] VARIANT *. How long is this? How is it to be * interpreted?
*/ public static final int VT_VARIANT = 12; /** *[V][T][S] IUnknown *. How long is this? How is it to be * interpreted?
*/ public static final int VT_UNKNOWN = 13; /** *[V][T][S] 16 byte fixed point.
*/ public static final int VT_DECIMAL = 14; /** *[T] signed char.
*/ public static final int VT_I1 = 16; /** *[V][T][P][S] unsigned char.
*/ public static final int VT_UI1 = 17; /** *[T][P] unsigned short.
*/ public static final int VT_UI2 = 18; /** *[T][P] unsigned int.
*/ public static final int VT_UI4 = 19; /** *[T][P] signed 64-bit int.
*/ public static final int VT_I8 = 20; /** *[T][P] unsigned 64-bit int.
*/ public static final int VT_UI8 = 21; /** *[T] signed machine int.
*/ public static final int VT_INT = 22; /** *[T] unsigned machine int.
*/ public static final int VT_UINT = 23; /** *[T] C style void.
*/ public static final int VT_VOID = 24; /** *[T] Standard return type. How long is this? How is it to be * interpreted?
*/ public static final int VT_HRESULT = 25; /** *[T] pointer type. How long is this? How is it to be * interpreted?
*/ public static final int VT_PTR = 26; /** *[T] (use VT_ARRAY in VARIANT).
*/ public static final int VT_SAFEARRAY = 27; /** *[T] C style array. How long is this? How is it to be * interpreted?
*/ public static final int VT_CARRAY = 28; /** *[T] user defined type. How long is this? How is it to be * interpreted?
*/ public static final int VT_USERDEFINED = 29; /** *[T][P] null terminated string.
*/ public static final int VT_LPSTR = 30; /** *[T][P] wide (Unicode) null terminated string.
*/ public static final int VT_LPWSTR = 31; /** *[P] FILETIME. The FILETIME structure holds a date and time * associated with a file. The structure identifies a 64-bit * integer specifying the number of 100-nanosecond intervals which * have passed since January 1, 1601. This 64-bit value is split * into the two dwords stored in the structure.
*/ public static final int VT_FILETIME = 64; /** *[P] Length prefixed bytes.
*/ public static final int VT_BLOB = 65; /** *[P] Name of the stream follows.
*/ public static final int VT_STREAM = 66; /** *[P] Name of the storage follows.
*/ public static final int VT_STORAGE = 67; /** *[P] Stream contains an object. How long is this? How is it * to be interpreted?
*/ public static final int VT_STREAMED_OBJECT = 68; /** *[P] Storage contains an object. How long is this? How is it * to be interpreted?
*/ public static final int VT_STORED_OBJECT = 69; /** *[P] Blob contains an object. How long is this? How is it to be * interpreted?
*/ public static final int VT_BLOB_OBJECT = 70; /** *[P] Clipboard format. How long is this? How is it to be * interpreted?
*/ public static final int VT_CF = 71; /** *[P] A Class ID.
* *It consists of a 32 bit unsigned integer indicating the size * of the structure, a 32 bit signed integer indicating (Clipboard * Format Tag) indicating the type of data that it contains, and * then a byte array containing the data.
* *The valid Clipboard Format Tags are:
* *typedef struct tagCLIPDATA {
* // cbSize is the size of the buffer pointed to
* // by pClipData, plus sizeof(ulClipFmt)
* ULONG cbSize;
* long ulClipFmt;
* BYTE* pClipData;
* } CLIPDATA;
*
* See * msdn.microsoft.com/library/en-us/com/stgrstrc_0uwk.asp.
*/ public static final int VT_CLSID = 72; /** *[P] simple counted array. How long is this? How is it to be * interpreted?
*/ public static final int VT_VECTOR = 0x1000; /** *[V] SAFEARRAY*. How * long is this? How is it to be interpreted?
*/ public static final int VT_ARRAY = 0x2000; /** *[V] void* for local use. How long is this? How is it to be * interpreted?
*/ public static final int VT_BYREF = 0x4000; /** *FIXME (3): Document this!
*/ public static final int VT_RESERVED = 0x8000; /** *FIXME (3): Document this!
*/ public static final int VT_ILLEGAL = 0xFFFF; /** *FIXME (3): Document this!
*/ public static final int VT_ILLEGALMASKED = 0xFFF; /** *FIXME (3): Document this!
*/ public static final int VT_TYPEMASK = 0xFFF; /** *Maps the numbers denoting the variant types to their corresponding * variant type names.
*/ private static Map numberToName; private static Map numberToLength; /** *Denotes a variant type with a length that is unknown to HPSF yet.
*/ public static final Integer LENGTH_UNKNOWN = new Integer(-2); /** *Denotes a variant type with a variable length.
*/ public static final Integer LENGTH_VARIABLE = new Integer(-1); /** *Denotes a variant type with a length of 0 bytes.
*/ public static final Integer LENGTH_0 = new Integer(0); /** *Denotes a variant type with a length of 2 bytes.
*/ public static final Integer LENGTH_2 = new Integer(2); /** *Denotes a variant type with a length of 4 bytes.
*/ public static final Integer LENGTH_4 = new Integer(4); /** *Denotes a variant type with a length of 8 bytes.
*/ public static final Integer LENGTH_8 = new Integer(8); static { /* Initialize the number-to-name map: */ Map tm1 = new HashMap(); tm1.put(new Long(0), "VT_EMPTY"); tm1.put(new Long(1), "VT_NULL"); tm1.put(new Long(2), "VT_I2"); tm1.put(new Long(3), "VT_I4"); tm1.put(new Long(4), "VT_R4"); tm1.put(new Long(5), "VT_R8"); tm1.put(new Long(6), "VT_CY"); tm1.put(new Long(7), "VT_DATE"); tm1.put(new Long(8), "VT_BSTR"); tm1.put(new Long(9), "VT_DISPATCH"); tm1.put(new Long(10), "VT_ERROR"); tm1.put(new Long(11), "VT_BOOL"); tm1.put(new Long(12), "VT_VARIANT"); tm1.put(new Long(13), "VT_UNKNOWN"); tm1.put(new Long(14), "VT_DECIMAL"); tm1.put(new Long(16), "VT_I1"); tm1.put(new Long(17), "VT_UI1"); tm1.put(new Long(18), "VT_UI2"); tm1.put(new Long(19), "VT_UI4"); tm1.put(new Long(20), "VT_I8"); tm1.put(new Long(21), "VT_UI8"); tm1.put(new Long(22), "VT_INT"); tm1.put(new Long(23), "VT_UINT"); tm1.put(new Long(24), "VT_VOID"); tm1.put(new Long(25), "VT_HRESULT"); tm1.put(new Long(26), "VT_PTR"); tm1.put(new Long(27), "VT_SAFEARRAY"); tm1.put(new Long(28), "VT_CARRAY"); tm1.put(new Long(29), "VT_USERDEFINED"); tm1.put(new Long(30), "VT_LPSTR"); tm1.put(new Long(31), "VT_LPWSTR"); tm1.put(new Long(64), "VT_FILETIME"); tm1.put(new Long(65), "VT_BLOB"); tm1.put(new Long(66), "VT_STREAM"); tm1.put(new Long(67), "VT_STORAGE"); tm1.put(new Long(68), "VT_STREAMED_OBJECT"); tm1.put(new Long(69), "VT_STORED_OBJECT"); tm1.put(new Long(70), "VT_BLOB_OBJECT"); tm1.put(new Long(71), "VT_CF"); tm1.put(new Long(72), "VT_CLSID"); Map tm2 = new HashMap(tm1.size(), 1.0F); tm2.putAll(tm1); numberToName = Collections.unmodifiableMap(tm2); /* Initialize the number-to-length map: */ tm1.clear(); tm1.put(new Long(0), LENGTH_0); tm1.put(new Long(1), LENGTH_UNKNOWN); tm1.put(new Long(2), LENGTH_2); tm1.put(new Long(3), LENGTH_4); tm1.put(new Long(4), LENGTH_4); tm1.put(new Long(5), LENGTH_8); tm1.put(new Long(6), LENGTH_UNKNOWN); tm1.put(new Long(7), LENGTH_UNKNOWN); tm1.put(new Long(8), LENGTH_UNKNOWN); tm1.put(new Long(9), LENGTH_UNKNOWN); tm1.put(new Long(10), LENGTH_UNKNOWN); tm1.put(new Long(11), LENGTH_UNKNOWN); tm1.put(new Long(12), LENGTH_UNKNOWN); tm1.put(new Long(13), LENGTH_UNKNOWN); tm1.put(new Long(14), LENGTH_UNKNOWN); tm1.put(new Long(16), LENGTH_UNKNOWN); tm1.put(new Long(17), LENGTH_UNKNOWN); tm1.put(new Long(18), LENGTH_UNKNOWN); tm1.put(new Long(19), LENGTH_UNKNOWN); tm1.put(new Long(20), LENGTH_UNKNOWN); tm1.put(new Long(21), LENGTH_UNKNOWN); tm1.put(new Long(22), LENGTH_UNKNOWN); tm1.put(new Long(23), LENGTH_UNKNOWN); tm1.put(new Long(24), LENGTH_UNKNOWN); tm1.put(new Long(25), LENGTH_UNKNOWN); tm1.put(new Long(26), LENGTH_UNKNOWN); tm1.put(new Long(27), LENGTH_UNKNOWN); tm1.put(new Long(28), LENGTH_UNKNOWN); tm1.put(new Long(29), LENGTH_UNKNOWN); tm1.put(new Long(30), LENGTH_VARIABLE); tm1.put(new Long(31), LENGTH_UNKNOWN); tm1.put(new Long(64), LENGTH_8); tm1.put(new Long(65), LENGTH_UNKNOWN); tm1.put(new Long(66), LENGTH_UNKNOWN); tm1.put(new Long(67), LENGTH_UNKNOWN); tm1.put(new Long(68), LENGTH_UNKNOWN); tm1.put(new Long(69), LENGTH_UNKNOWN); tm1.put(new Long(70), LENGTH_UNKNOWN); tm1.put(new Long(71), LENGTH_UNKNOWN); tm1.put(new Long(72), LENGTH_UNKNOWN); tm2 = new HashMap(tm1.size(), 1.0F); tm2.putAll(tm1); numberToLength = Collections.unmodifiableMap(tm2); } /** *Returns the variant type name associated with a variant type * number.
* * @param variantType The variant type number * @return The variant type name or the string "unknown variant type" */ public static String getVariantName(final long variantType) { final String name = (String) numberToName.get(new Long(variantType)); return name != null ? name : "unknown variant type"; } /** *Returns a variant type's length.
* * @param variantType The variant type number * @return The length of the variant type's data in bytes. If the length is * variable, i.e. the length of a string, -1 is returned. If HPSF does not * know the length, -2 is returned. The latter usually indicates an * unsupported variant type. */ public static int getVariantLength(final long variantType) { final Long key = new Long((int) variantType); final Long length = (Long) numberToLength.get(key); if (length == null) return -2; return length.intValue(); } }