See the latest version of the OMG IDL/Java Language Mapping Specification for complete information about the following:
For example, an interface whose name is fooHelper or
fooHolder is mapped to
_fooHelper or
_fooHolder respectively, regardless of whether an interface named
foo exists. The helper and holder classes for interface
fooHelper are named
_fooHelperHelper and
_fooHelperHolder.
•
|
The Java class <type>Helper, where <type> is the name of an IDL user-defined type.
|
•
|
The Java class <type>Holder, where <type> is the name of an IDL user-defined type (with certain exceptions such as typedef aliases).
|
•
|
The Java classes <basicJavaType>Holder, where <basicJavaType> is one of the Java primitive data types that is used by one of the IDL basic data types.
|
•
|
The Java classes <interface> Operations, <interfaces> POA, and <interface>POATie, when <interface> is the name of an IDL interface type.
|
Holder classes support OUT and
INOUT parameter passing modes and are available for all the basic IDL data types in the
org.omg.CORBA package. Holder classes are generated for all named user-defined types except those defined by
typedefs. For more information, see the Java API Reference, VisiBroker APIs, org.omg.CORBA package section.
Each holder class has a constructor from an instance, a default constructor, and has a public instance member, value, which is the typed value. The default constructor sets the value field to the default value for the type as defined by the Java language:
•
|
0 for numeric and char types
|
•
|
null for object references
|
To support portable stubs and skeletons, Holder classes for user-defined types also implement the
org.omg.CORBA.portable.Streamable interface.
The Java null may only be used to represent null CORBA object references and valuetypes (including recursive valuetypes). For example, a zero length string, rather than
null must be used to represent the empty string. This is also true for arrays and any constructed type, except for valuetypes. If you attempt to pass a
null for a structure, it will raise a
NullPointerException.
The IDL type boolean is mapped to the Java type
boolean. The IDL constants
TRUE and
FALSE are mapped to the Java constants
true and
false.
The IDL wchar maps to the Java
char type.
The IDL type octet, an 8-bit quantity, is mapped to the Java type
byte.
The IDL type string, both bounded and unbounded variants, is mapped to the Java type
java.lang.String. Range checking for characters in the string as well as bounds checking of the string are done at marshal time.
The IDL type wstring, used to represent Unicode strings, is mapped to the Java type
java.lang.String. Bounds checking of the string is done at marshal time.
IDL short and
unsigned short map to Java type
short. IDL
long and
unsigned long map to Java type
int.
The IDL floating point types float and
double map to a Java class containing the corresponding data type.
All user-defined IDL types have an additional “helper” Java class with the suffix Helper appended to the type name generated. Several static methods needed to manipulate the type are supplied:
•
|
Any insert and extract operations for the type
|
For any user-defined IDL type <typename>, the following code sample is the Java code generated for the type. The helper class for a mapped IDL interface has a
narrow operation defined for it.
// generated Java helper
public class <typename>Helper {
public static void insert(org.omg.CORBA.Any a,
<typename> t);
public static
<typename> extract(org.omg.CORBA.Any a);
public static org.omg.CORBA.TypeCode type();
public static String id();
public static
<typename> read( org.omg.CORBA.portable.InputStream
istream);
{...}
public static void write(
org.omg.CORBA.portable.OutputStream ostream,
<typename> value)
{...}
// only for interface helpers
public static
<typename> narrow(org.omg.CORBA.Object obj);
Constants declared within an IDL interface are mapped to public static final fields in the Java interface
Operations class corresponding to the IDL interface.
IDL constructed types include enum,
struct,
union,
sequence, and
array. The types
sequence and
array are both mapped to the Java
array type. The IDL constructed types
enum,
struct, and
union are mapped to a Java class that implements the semantics of the IDL type. The Java class generated will have the same name as the original IDL type.
An IDL enum is mapped to a Java
final class with the same name as the enum type which declares a value method, two static data members per label, an integer conversion method, and a private constructor. The following code sample is an example of an IDL
enum mapped to a Java final class:
// Generated java
public final class <enum_name> {
//one pair for each label in the enum
public static final int _<
label> = <
value>;
public static final <
enum_name> <
label> =
new <enum_name>(_<
label>);
public int value() {...}
//get enum with specified value
public static <
enum_name> from_int(int value);
//constructor
protected <
enum_name>(int) {...}
}
One of the members is a public static final , which has the same name as the IDL
enum label. The other has an underscore (_) prepended and is used in
switch statements.
There will be only one instance of an enum. Since there is only one instance, pointer equality tests will work correctly; that is, the default
java.lang.Object implementation of
equals() and
hash() will automatically work correctly for an enumeration's singleton object.
The Java class for the enum has an additional method,
from_int(), which returns the
enum with the specified value.
The holder class for the enum is also generated. Its name is the enumeration's mapped Java classname with
Holder appended to it as follows:
public class <enum_name>Holder implements
org.omg.CORBA.portable.Streamable {
public
<enum_name> value;
public
<enum_name>Holder() {}
public
<enum_name>Holder(
<enum_name> initial) {...}
public void _read(org.omg.CORBA.portable.InputStream i)
{...}
public void _write(
org.omg.CORBA.portable.OutputStream o)
{...}
public org.omg.CORBA.TypeCode _type() {...}
}
An IDL struct is mapped to a final Java class with the same name that provides instance variables for the fields in IDL member ordering and a constructor for all values. A null constructor is also provided which allows the structure's fields to be initialized later. The
Holder class for the
struct is also generated. Its name is the
struct's mapped Java classname with
Holder appended to it as follows:
final public class <class>Holder implements
org.omg.CORBA.portable.Streamable {
public
<class> value;
public
<class>Holder() {}
public
<class>Holder(
<class> initial) {...}
public void _read(org.omg.CORBA.portable.InputStream i)
{...}
public void _write
(org.omg.CORBA.portable.OutputStream o)
{...}
public org.omg.CORBA.TypeCode _type() {...}
}
An IDL union is given the same name as the final Java class, and mapped to it. It provides the following:
If the branch corresponds to the default case label, then the modifier method sets the discriminant to a value that does not match any other case labels.
A default method _default() is created if there is no explicit default case label, and the set of case labels does not completely cover the possible values of the discriminant. It will set the value of the union to be an out-of-range value.
final public class <union_class>Holder
implements org.omg.CORBA.portable.Streamable {
public
<union_class> value;
public
<union_class>Holder() {}
public
<union_class>Holder(
<union_class> initial) {...}
public void _read(org.omg.CORBA.portable.InputStream i)
{...}
public void _write(
org.omg.CORBA.portable.OutputStream o)
{...}
public org.omg.CORBA.TypeCode _type() {...}
}
An IDL sequence is mapped to a Java array with the same name. In the mapping, anywhere the
sequence type is needed, an array of the mapped type of the sequence element is used.
final public class <sequence_class>Holder {
public
<sequence_element_type>[] value;
public
<sequence_class>Holder() {};
public
<sequence_class>Holder(
<sequence_element_type>[] initial) {...};
public void _read(org.omg.CORBA.portable.InputStream i)
{...}
public void _write
(org.omg.CORBA.portable.OutputStream o)
{...}
public org.omg.CORBA.TypeCode _type() {...}
}
final public class <array_class>Holder
implements org.omg.CORBA.portable.Streamable {
public
<array_element_type>[] value;
public
<array_class>Holder() {}
public
<array_class>Holder(
<array_element_type>[] initial) {...}
public void _read(org.omg.CORBA.portable.InputStream i)
{...}
public void _write
An additional “helper” Java class with the suffix Helper is appended to the interface name. The Java interface extends the mapped, base
org.omg.CORBA.Object interface.
The helper class declares a static narrow method that allows an instance of org.omg.CORBA.Object to be narrowed to the object reference of a more specific type. The IDL exception
CORBA::BAD_PARAM is thrown if the narrow fails because the object reference doesn't support the request type. A different system exception is raised to indicate other kinds of errors. Trying to narrow a null will always succeed with a return value of null.
There are no special “nil” object references. Java null can be passed freely wherever an object reference is expected.
final public class <interface_class>Holder
implements org.omg.CORBA.portable.Streamable {
public
<interface_class> value;
public
<interface_class>Holder() {}
public
<interface_class>Holder(
<interface_class> initial) {
value = initial;
An IDL local interface is mapped similarly to that of a non-local interface except that a local interface is marked by org.omg.CORBA.LocalInterface. A local interface may not be marshaled and its implementation must extend a special base
org.omg.CORBA.LocalObject and implement the generated signature interface. In Java mapping, the
LocalObject class is used as a base class of implementations of a local interface. Creating an instance of local interface implementation is the same as creating normal Java object; that is using the new Java operator.
IDL in parameters are mapped to normal Java actual parameters. The results of IDL operations are returned as the result of the corresponding Java method.
IDL out and
inout parameters cannot be mapped directly into the Java parameter passing mechanism. This mapping defines additional holder classes for all the IDL basic and user-defined types which are used to implement these parameter modes in Java. The client supplies an instance of the appropriate holder Java class that is passed (by value) for each IDL out or inout parameter. The contents of the holder instance (but not the instance itself) are modified by the invocation, and the client uses the (possibly) changed contents after the invocation returns.
This code sample shows the IN parameter mapping to Java actual parameters.
The POA class does not “truly” extend the IDL interface, meaning that POA is not a CORBA object. It is a CORBA servant and it can be used to create a “true” CORBA object. For more information on the POA class, go to the Java API Reference, VisiBroker APIs, org.omg.PortableServer package section. For more information about POAs, see
“Using POAs”.
The POA class itself is abstract and cannot be instantiated. To instantiate it, your implementation must implement its declared IDL interface operations.
/* From Bank.idl: */
module Bank {
interface
Account {
};
};
// Generated java
package
Bank;
public abstract class
AccountPOA extends org.omg.PortableServer.Servant implements
org.omg.CORBA.portable.InvokeHandler,
Bank.AccountOperations { ... }
// Linking an implementation to the ORB :
public class
AccountImpl extends Bank.AccountPOA { ... }
The delegated implementation must implement the Operation interface and has to be stored in a
Tie class instance. Storing the instance of the
Operation interface in the
Tie object is done through a constructor provided by the
Tie class. The code sample below shows an example of how delegation is used.
/* From Bank.idl: */
module Bank {
interface
AccountManager {
Account
open(in string name);
};
};
// Generated java
package
Bank;
public interface
AccountManagerOperations {
public Example.Account
open(java.lang.String name);
}
// Generated java
package
Bank;
public class
AccountManagerPOATie extends AccountManagerPOA {
public
AccountManagerPOATie (final Bank.AccountManagerOperations _delegate)
{ ... }
public
AccountManagerPOATie (final Bank.AccountManagerOperations _delegate,
final org.omg.PortableServer.POA _poa) { ... }
public Bank.AccountManagerOperations
_delegate () { ... }
public void
_delegate (final Bank.AccountManagerOperations delegate) { ... }
public org.omg.PortableServer.POA
_default_POA () { ... }
public float
open () { ... }
}
// Linking an implementation to the ORB :
User-defined exceptions are mapped to final Java classes that extend org.omg.CORBA.UserException and are otherwise mapped just like the IDL
struct type, including the generation of Helper and Holder classes.
The standard IDL system exceptions are mapped to final Java classes that extend org.omg.CORBA.SystemException and provide access to the IDL major and minor exception code, as well as a string describing the reason for the exception. There are no public constructors for
org.omg.CORBA.SystemException; only classes that extend it can be instantiated.
The Java class name for each standard IDL exception is the same as its IDL name and is declared to be in the org.omg.CORBA package. The default constructor supplies 0 for the minor code,
COMPLETED_NO for the completion code, and the empty string (““) for the reason string. There is also a constructor which takes the reason and uses defaults for the other fields, as well as one which requires all three parameters to be specified.
The IDL type Any maps to the Java class
org.omg.CORBA.Any. This class has all the necessary methods to insert and extract instances of predefined types. If the extraction operations have a mismatched type, the
CORBA::BAD_OPERATION exception is thrown.
Setting the typecode via the type() accessor wipes out the value. An attempt to extract before the value is set will result in a
CORBA::BAD_OPERATION exception being raised. This operation is provided primarily so that the type may be set properly for IDL
out parameters.
Holder classes are generated for sequence and array typedefs.