BEA Home | Events | Solutions | Partners | Products | Services | Download | Developer Center | WebSUPPORT
| WebLogic Server Doc Home | WebLogic jCOM Reference Guide | Previous Topic | Next Topic | Contents | View as PDF

Supported COM data types, and their Java Equivalents

WebLogic jCOM supports the full range of COM Automation types. Our philosophy has been to avoid introducing new Java classes in order to access COM types. This means that COM Variants map onto Objects (java.lang.Long, etc.), and Variants containing arrays map onto Java arrays. You won't find a com.bea.jcom.Variant class that you need to use, for example.

WebLogic jCOM also supports accessing some Java collection types as Visual Basic Collections.

Below you will find

- Accessing Java Objects as Visual Basic Collections

- How COM IDL types map to Java, and VC++

- How COM Variants containing different types map to Java

- Type conversions used during late-bound access from COM to Java

- Accessing COM VariantEnums from Java

Accessing Java Objects as Visual Basic Collections

Visual Basic has a built-in COM class called Collection. WebLogic jCOM provides support for accessing instances of java.util.Vector and java.util.List as VB Collections.

Example Visual BASIC code

>     Private Sub Form_Load()
>     Dim c As Collection
>     Set c = GetObject("firstjvm:java.util.LinkedList")
>     c.Add "hello" ' List is now: "hello"
>     c.Add Now, , "hello" ' List is now: , "hello"
>     c.Add "Goodbye", , , "hello" ' List is now: now, "hello", "Goodbye"
>     c.Add "Before", , 3 ' List is now: now, "hello", "Before", "Goodbye"
>     c.Add "After", , , 4 ' List is now: now, "hello", "Before",
>     "Goodbye", "After"
>     For Each e In c
>     MsgBox e
>     Next
>     c.Remove 2 ' List is now: now, "Before", "Goodbye", "After"
>     c.Remove "Goodbye" ' List is now: now, "Before", "After"
>     MsgBox c.Item(1)
>     MsgBox c.Count
>     End Sub

####

VB | Maps to java.util.Vector | Notes
Collection.Add(item) | aVector.addElement(item) |
Collection.Add(item, , before) | aVector.insertElementAt(before - 1, item) | if before is a number
Collection.Add(item, , before) | aVector.insertElementAt(aVector.indexOf(before), item) | if before is not a number
Collection.Add(item, , , after) | aVector.insertElementAt(after, item) | if after is not a number
Collection.Add(item, , , after) | aVector.insertElementAt(aVector.indexOf(after) + 1, item) | if after is a number
Collection.Count | aVector.size() |
Collection.Item(index) | aVector.elementAt(index - 1) | index must be a number
Collection.Remove(index) | aVector.removeElementAt(index - 1) | if index is a number
Collection.Remove(index) | aVector.removeElement(index) | if index is not a number
For Each x in aCollection | x will take on the value of each object in the aVector.elements() enumeration |

####

VB | Maps to java.util.List | Notes
Collection.Add(item) | aList.target.add(item) |
Collection.Add(item, , before) | aList.add(before - 1, item) | if before is a number
Collection.Add(item, , before) | aList.add(aVector.indexOf(before), item) | if before is not a number
Collection.Add(item, , , after) | aList.add(after, item) | if after is not a number
Collection.Add(item, , , after) | aList.add(aVector.indexOf(after) + 1, item) | if after is a number
Collection.Count | aList.size() |
Collection.Item(index) | aList.get(index - 1) | index must be a number
Collection.Remove(index) | aList.remove(index - 1) | if index is a number
Collection.Remove(index) | aList.remove(index) | if index is not a number
For Each x in aCollection | x will take on the value of each object in the aList.listIterator() iterator |

How COM IDL types map to Java, VB, and VC++

In the following table we show each IDL type, describing its use from Java, from Visual BASIC and from Visual C++.

Table 7-1

IDL | Java | Visual BASIC | Visual C++
--- | --- | --- | ---
[in] VARIANT_BOOL | boolean | ByVal boolean | VARIANT_BOOL
[in, out] or [out] VARIANT_BOOL* | boolean[] single element array | boolean | VARIANT_BOOL*
[in] unsigned char | byte | ByVal byte | unsigned char
[in, out] or [out] unsigned char* | byte[] single element array | byte | unsigned char*
[in] double | double | ByVal Double | double
[in, out] or [out] double* | double[] single element array | double | double*
[in] float | float | ByVal Single | float
[in, out] or [out] float* | float[] single element array | Single | float*
[in] long | int IDL long is 32 bits | ByVal Long> | long>
[in, out] or [out] long* | int[] single element array | Long> | long*
[in] short | short | ByVal Integer> | short>
[in, out] or [out] short* | short[] single element array | Integer | short*
[in] BSTR | java.lang.String | ByVal String | BSTR
[in, out] or [out] BSTR* | java.lang.String[] single element array | String | BSTR*
[in] CY | long CY is fixed point, 64 bit | ByVal Currency | CURRENCY
[in, out] or [out] CY* | long[] single element array | Currency | CURRENCY*
[in] DATE | java.util.Date | ByVal Date | DATE
[in, out] or [out] DATE* | java.util.Date[] | Date | DATE*
[in] IDispatch* | java.lang.Object | ByVal Object | IDispatch*
[in, out] or [out] IDispatch** | java.lang.Object[] single element array | Object | IDispatch**
[in] ISomeInterface* | ISomeInterface Generated Java Interface | ByVal ISomeInterface | ISomeInterface*
[in, out] or [out] ISomeInterface** | ISomeInterface[] single element array | ISomeInterface | ISomeInterface**
[in] SomeClass* | SomeClass Generated Java Class | ByVal SomeClass | SomeClass*
[in, out] or [out] SomeClass** | SomeClass[] single element array | SomeClass | SomeClass**
[in] IUnknown* | java.lang.Object | Specific class/interface | IUnknown*
[in] Variant | java.lang.Object | ByVal Variant | VARIANT
[in, out] or [out] Variant* | java.lang.Object[] single element array | Variant | VARIANT*
[in] SAFEARRAY(unsigned char) | byte[] | not supported by VB | SAFEARRAY*
[in, out] or [out] SAFEARRAY(unsigned char)* | byte[][] | not supported by VB | SAFEARRAY**
[in] SAFEARRAY(VARIANT_BOOL) | boolean[] | not supported by VB | SAFEARRAY*
[in, out] or [out] SAFEARRAY(VARIANT_BOOL)* | boolean[][] | not supported by VB | SAFEARRAY**
[in] SAFEARRAY(short) | short[] | not supported by VB | SAFEARRAY*
[in, out] or [out] SAFEARRAY(short)* | short[][] | not supported by VB | SAFEARRAY**
[in] SAFEARRAY(long) | int[] | not supported by VB | SAFEARRAY*
[in, out] or [out] SAFEARRAY(long)* | int[][] | not supported by VB | SAFEARRAY**
[in] SAFEARRAY(float) | float[] | not supported by VB | SAFEARRAY*
[in, out] or [out] SAFEARRAY(float)* | float[][] | not supported by VB | SAFEARRAY**
[in] SAFEARRAY(double) | double[] | not supported by VB | SAFEARRAY*
[in, out] or [out] SAFEARRAY(double)* | double[][] | not supported by VB | SAFEARRAY**
[in] SAFEARRAY(CURRENCY) | long[] | not supported by VB | SAFEARRAY*
[in, out] or [out] SAFEARRAY(CURRENCY)* | long[][] | not supported by VB | SAFEARRAY**
[in] SAFEARRAY(DATE) | java.util.Date[] | not supported by VB | SAFEARRAY*
[in, out] or [out] SAFEARRAY(DATE)* | java.util.Date[][] | not supported by VB | SAFEARRAY**
[in] SAFEARRAY(BSTR) | String[] | not supported by VB | SAFEARRAY*
[in, out] or [out] SAFEARRAY(BSTR)* | String[][] | not supported by VB | SAFEARRAY**
[in] SAFEARRAY(LPDISPATCH) | Object[] | not supported by VB | SAFEARRAY*
[in, out] or [out] SAFEARRAY(LPDISPATCH)* | Object[][] | not supported by VB | SAFEARRAY**
[in] SAFEARRAY(VARIANT) | Object | not supported by VB | SAFEARRAY*
[in, out] or [out] SAFEARRAY(VARIANT)* | Object[][] | not supported by VB | SAFEARRAY**
[in] SAFEARRAY(LPUNKNOWN) | Object | not supported by VB | SAFEARRAY*
[in, out] or [out] SAFEARRAY(LPUNKNOWN)* | Object[][] | not supported by VB | SAFEARRAY**

How COM Variants containing different types map to Java

The following table shows how Variants are mapped to Java types.

####

Variant Containing a | Maps to Java type
--- | ---
VARIANT_BOOL | java.lang.Boolean
VARIANT_BOOL* | java.lang.Boolean[] single element array
unsigned char | java.lang.Byte
unsigned char* | java.lang.Byte[] single elment array
double | java.lang.Double
double* | java.lang.Double[] single element array
float | java.lang.Float
float* | java.lang.Float[] single element array
long | java.lang.Integer IDL long is 32 bits
long* | java.lang.Integer[] single element array
short | java.lang.Short
short* | java.lang.Short[] single element array
BSTR | java.lang.String
BSTR* | java.lang.String[]single element array
CY | java.lang.Long
CY* | java.lang.Long[]single element array
Decimal | java.math.BigDecimal
Decimal* | java.math.BigDecimal[]single element array
DATE | java.util.Date
DATE* | java.util.Date[]
SCODE | java.lang.Long
SCODE* | java.lang.Long[] single element array
IDispatch* | java.lang.Object
IUnknown* | java.lang.Object
Single dimensional array of VARIANT_BOOLs | boolean[]
Single dimensional array of unsigned chars | byte[]
Single dimensional array of doubles | double[]
Single dimensional array of floats | float[]
Single dimensional array of longs | int[] IDL long is 32 bits</TD
Single dimensional array of shorts | short[]
Single dimensional array of BSTRs | java.lang.String[]
Single dimensional array of CYs | long[]
Single dimensional array of DATEs | java.util.Date[]
Single dimensional array of SCODEs | long[]
Single dimensional array of IDispatch*s | java.lang.Object[]
Single dimensional array of IUnknown*s | java.lang.Object[]
Single dimensional array of Variants | java.lang.Object[]
Two dimensional array of Variants | java.lang.Object[][]

You can also pass a Variant of type VT_EMPTY or VT_NULL by passing com.bea.jcom.EmptyVariant.TYPE and com.bea.jcom.NullVariant.TYPE.

Type conversions used during late-bound access from COM to Java

These tables show the Java expression used to convert a VB value 'vb' of the VB type on the left to the Java type at the top. Note that conversions marked with a * can also raise Type Mismatch Error.

Java boolean, byte, short and int

Java(across) VB (down) | boolean | byte | short | int
--- | --- | --- | --- | ---
Boolean | natural | vb ? 1 : 0 | vb ? 1 : 0 | vb ? 1 : 0
Byte(0..255) | vb != 0 | new Integer(vb).byteValue() | new Integer(vb).shortValue() | new Integer(vb).intValue()
Integer(16 bit) | vb != 0 | new Short(vb).byteValue() | natural | new Short(vb).intValue()
Long(32 bit) | vb != 0 | new Integer(vb).byteValue() | new Integer(vb).shortValue() | natural
Single | vb != 0.0F | new Float(vb).byteValue() | new Float(vb).shortValue() | new Float(vb).intValue()
Double | vb != 0.0 | new Double(vb).byteValue() | new Double(vb).shortValue() | new Double(vb).intValue()
Currency(64 bit) | vb != 0 | new Long(vb).byteValue() | new Long(vb).shortValue() | new Long(vb).intValue()
String | new Boolean(vb).booleanValue() | new Long(vb).byteValue()* | new Long(vb).shortValue()* | new Long(vb).intValue()*
Date | Type Mismatch Error | Type Mismatch Error | Type Mismatch Error | Type Mismatch Error
Object | Type Mismatch Error | Type Mismatch Error | Type Mismatch Error | Type Mismatch Error
Variants | As above depending on content |  |  |

Java long, char, float and double

VB/Java | long | char | float | double
--- | --- | --- | --- | ---
Boolean | vb ? 1 : 0 | vb ? (char)1 : (char)0 | vb ? 1.0F : 0.0F | vb ? 1.0 : 0.0
Byte(0..255) | new Integer(vb).longValue() | (char)(new Integer(vb).intValue()) | new Integer(vb).floatValue() | new Integer(vb).doubleValue()
Integer(16 bit) | new Short(vb).longValue() | (char)(new Short(vb).intValue()) | new Short(vb).floatValue() | new Short(vb).doubleValue()
Long(32 bit) | new Integer(vb).longValue() | (char)(new Integer(vb).byteValue()) | new Integer(vb).floatValue() | new Integer(vb).doubleValue()
Single | new Float(vb).longValue() | (char)(new Float(vb).intValue()) | natural | new Float(vb).doubleValue()
Double | new Double(vb).longValue() | (char)(new Double(vb).intValue()) | new Double(vb).floatValue() | natural
Currency(64 bit) | natural | (char)(new Long(vb).intValue()) | new Long(vb).floatValue() | new Long(vb).doubleValue()
String | new Long(vb).longValue() | (char)(new Long(vb).intValue()) | new Long(vb).floatValue() | new Long(vb).doubleValue()
Date | Type Mismatch Error | Type Mismatch Error | Type Mismatch Error | Type Mismatch Error
Object | Error | Error | Error | Error
Variants | As above depending on content |  |  |

Java String, Date and Object

VB/Java | String | Date | Object
--- | --- | --- | ---
Boolean | vb + "" | Error | new Boolean(vb)
Byte(0..255) | vb + "" | Error | new Byte(vb)
Integer(16 bit) | vb + "" | Error | new Short(vb)
Long(32 bit) | vb + "" | Error | new Integer(vb)
Single | vb + "" | Error | new Float(vb)
Double | vb + "" | Error | new Double(vb)
Currency | vb + "" | Error | new Long(vb)
String | natural | new Date(vb) | vb (as String_
Date | vb.toString() | Natural | vb (as Date)
Object | vb.toString | Error | vb
Variant | As above depending on content |  |

Arrays

If a Java method has a parameter which is an array, then if you pass a VB parameter by value to that method you will get an error. If you pass a value by reference, and if the type matches precisely (see below), the Java method will receive a single element array whose single element can be modified to change the corresponding VB parameter. If you pass an array, and if the array content type matches precisely, the Java method will receive an array whose elements can be modified to change the corresponding VB parameter.

####

Java type | VB pass by reference match
--- | ---
boolean[] | Boolean passed by reference
byte[] | Byte passed by reference
short[] | Short passed by reference
int[] | Long passed by reference
long[] | Currency passed by reference
float[] | Single passed by reference
double[] | Double passed by reference
String[] | String passed by reference
java.util.Date[] | Date passed by reference

Arrays:

####

Java type | Parameter of this VB type will match
--- | ---
boolean[] | Dim anArray(n) as Boolean
byte[] | Dim anArray(n) as Byte
short[] | Dim anArray(n) as Short
int[] | Dim anArray(n) as Long
long[] | Dim anArray(n) as Currency
float[] | Dim anArray(n) as Single
double[] | Dim anArray(n) as Double
String[] | Dim anArray(n) as String
java.util.Date[] | Dim anArray(n) as Date
Object[] | Dim anArray(n) as String
Object[] | Dim anArray(n) as Date
Object[] | Dim anArray(n) as Object
Object[] | Dim anArray(n) as Variant

Accessing COM VariantEnums from Java

Some COM methods return a COM VariantEnumeration type. WebLogic jCOM's java2com tool automatically converts the returned type into a standard Java java.lang.Enumeration. There isn't a perfect match though, since COM Enumerations have no equivalent to the 'hasMoreElements()' call, meaning that you have to keep on doing 'nextElement' until you get a 'NoSuchElementException'.

We do provide a workaround -- if you set the JCOM_PREFETCH_ENUMS Java property, WebLogic jCOM will pre-fetch the next element behind the scenes, and thus allow the 'hasMoreElements()' method to work properly.

Copyright © 2001 BEA Systems, Inc. All rights reserved. Required browser: Netscape 4.0 or higher, or Microsoft Internet Explorer 4.0 or higher.