com.jacob.com
Class VariantUtilities

java.lang.Object
  extended by com.jacob.com.VariantUtilities

public final class VariantUtilities
extends Object

A utility class used to convert between Java objects and Variants


Method Summary
protected static Variant[] objectsToVariants(Object[] arrayOfObjectsToBeConverted)
          converts an array of objects into an array of Variants by repeatedly calling obj2Variant(Object)
protected static Variant objectToVariant(Object objectToBeMadeIntoVariant)
          Map arguments based on msdn documentation.
protected static void populateVariant(Variant targetVariant, Object pValueObject, boolean fByRef)
          Populates a variant object from a java object.
static BigDecimal roundToMSDecimal(BigDecimal sourceDecimal)
          Rounds the scale and bit length so that it will pass validateDecimalScaleBits().
protected static void validateDecimalMinMax(BigDecimal in)
          Does any validation that couldn't have been fixed by rounding or scale modification.
protected static void validateDecimalScaleAndBits(BigDecimal in)
          Verifies that we have a scale 0 <= x <= 28 and now more than 96 bits of data.
protected static Object variantToObject(Variant sourceData)
          Convert a JACOB Variant value to a Java object (type conversions).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

populateVariant

protected static void populateVariant(Variant targetVariant,
                                      Object pValueObject,
                                      boolean fByRef)
Populates a variant object from a java object. This method attempts to figure out the appropriate Variant type

Parameters:
targetVariant -
pValueObject -
fByRef -

objectToVariant

protected static Variant objectToVariant(Object objectToBeMadeIntoVariant)
Map arguments based on msdn documentation. This method relies on the variant constructor except for arrays.

Parameters:
objectToBeMadeIntoVariant -
Returns:
Variant that represents the object

objectsToVariants

protected static Variant[] objectsToVariants(Object[] arrayOfObjectsToBeConverted)
converts an array of objects into an array of Variants by repeatedly calling obj2Variant(Object)

Parameters:
arrayOfObjectsToBeConverted -
Returns:
Variant[]

variantToObject

protected static Object variantToObject(Variant sourceData)
Convert a JACOB Variant value to a Java object (type conversions). provided in Sourceforge feature request 959381. A fix was done to handle byRef bug report 1607878.

Unlike other toXXX() methods, it does not do a type conversion except for special data types (it shouldn't do any!)

Converts Variant.VariantArray types to SafeArrays

Returns:
Corresponding Java object of the type matching the Variant type.
Throws:
IllegalStateException - if no underlying windows data structure
NotImplementedException - if unsupported conversion is requested
JacobException - if the calculated result was a JacobObject usually as a result of error

validateDecimalScaleAndBits

protected static void validateDecimalScaleAndBits(BigDecimal in)
Verifies that we have a scale 0 <= x <= 28 and now more than 96 bits of data. The roundToMSDecimal method will attempt to adjust a BigDecimal to pass this set of tests

Parameters:
in -
Throws:
IllegalArgumentException - if out of bounds

validateDecimalMinMax

protected static void validateDecimalMinMax(BigDecimal in)
Does any validation that couldn't have been fixed by rounding or scale modification.

Parameters:
in - The BigDecimal to be validated
Throws:
IllegalArgumentException - if the number is too large or too small or null

roundToMSDecimal

public static BigDecimal roundToMSDecimal(BigDecimal sourceDecimal)
Rounds the scale and bit length so that it will pass validateDecimalScaleBits(). Developers should call this method if they really want MS Decimal and don't want to lose precision.

Changing the scale on a number that can fit in an MS Decimal can change the number's representation enough that it will round to a number too large to be represented by an MS VT_DECIMAL

Parameters:
sourceDecimal -
Returns:
BigDecimal a new big decimal that was rounded to fit in an MS VT_DECIMAL


http://jacob-project.sourceforge.net