﻿ Typecasts


Previous Next

Arguments passed in RDMI methods often need to be typecast to an appropriate Java type. Typecasts serve to convert method call arguments to the appropriate Java types. They are applied in physical method definitions in RDMI component definitions. For example, one could pass a string containing an integer to a Java method in one of the following ways, in the RDMI physical method definition:

new java.math.BigDecimal("10.123" )

In the case above, the constructor method of BigDecimal is invoked to accept a string.

new java.math.BigDecimal( (double)"10.123")

In this case the constructor method of BigDecimal is invoked to accept a double. The typecast (double) converted the string "10.123" to a double and is passed as a double precision floating point number to the BigDecimal constructor.

More complex typecasts are also used. For example, consider a physical constructor that deploys a hashtable:

my_hashtable=new java.util.Hashtable()

Whenever the hashtable itself is passed as an argument, either in a subsequent call to a Java method in the constructor or in another RDMI physical method definition, the argument has to be typecasted. The reason for this is that the newly created object my_hashtable is known to the RDMI system as a generic object and not as a hashtable. So in a subsequent call to a Java method, the  my_hashtable object would be accessed and passed as in the following example, taken from the physical method of an RDMI component for the invocation of an enterprise Java bean:

my_hashtable=new java.util.Hashtable()  



ctx = new javax.naming.InitialContext((Hashtable)my_hashtable)

In this case, my_hashtable is created, populated and typecast and passed in the last line. Whether the typecast is needed depends on the argument definition in the invoked Java method, it may accept an Object, it may only accept a specific class. Note that :0 and :1 refer to the first and second RDMI arguments.

The RDMI Java Invoker (internally this software package had the name "joker") software has a table with common typecasts and aliases for common typecasts. For example, a typecast (java.lang.Integer) is in this table but also the alias: (Integer) and (I). The basic typecast (int) has alias (i).

The Definer/RDMI/J2EE method lookup wizard automatically inserts the appropriate typecasts.

The predefined typecasts can be listed using the following invocation:


To show the typecast list, this line can be added as a physical method to an RDMI component in the definer and the RDMI component method can be invoked in an application. Alternatively, the JVM Off The Shelf component contains a generic method to invoke methods in an application, Thus, adding JVM to a test application allows application time invocations of Java methods as shown in the following examples that can be run in SQL Command:

SELECT jvm.call( 'com.usoft.joker.Joker.showCasts() U' );

Where the "U" at the end denotes that the result is supposed to be casted to a string, otherwise a Java Object would be returned.

It is possible to add typecasts to the typecast table, typically this would be applicable in a constructor of an RDMI component that uses the user-defined cast in one of its (physical) method definitions.

com.usoft.joker.Joker.addCast( user defined cast specification )

For example, to add a typecast (my_string), type the following statement in SQL Command:

SELECT jvm.call ('com.usoft.joker.Joker.addCast("my_string:java.lang.String")');

SELECT jvm.call ('com.usoft.joker.Joker.showCast("my_string") U')

To look up all casts associated with strings, using a regular expression, type the following in SQL Command:

SELECT jvm.call ('com.usoft.joker.Joker.showCast(".*ring.*") U')