Java Programming  «Prev  Next»
Lesson 5 Constants and typedefs
Objective Describe the mapping of IDL constants and typedefs in Java.

Corba Constants and Typedefs

Constants and typedefs are probably the simplest constructs in IDL. A constant is a primitive value bound to a name. A typedef is an aliasing of a type name to allow better semantic description in the IDL definition as well as to provide a little bit of change management functionality.
const within an IDL interface
If you define a constant (const) within an IDL interface, it is mapped as a public static final variable in the generated Java interface. However, constants are more often defined within a module scope rather than within an interface. In this case, there is no Java class or interface in which a static variable can be defined. If you define a constant in a module, a class is generated for that variable in the package generated for that module. Each constant defined gets its very own class, and the name of that class is the name of the constant. The value is assigned to a public static final variable named value. The following series of images below shows the IDL interface const mapping to the value public static final variable in Java:

Mapped Constant and Typedef code using Corba


1) The IDL compiler does not generate the cllient code
All elements defined in a module are in the same package. The IDL compiler does not generate the client code, so it can be placed in any package specified by the implementer.
2) The interface definition results in a class for the interface containing all the elements defined in the IDL interface
The interface definition results in a class for the interface containing all the elements defined in the IDL interface. The Java interface extends from the common object reference interface org.omg.CORBA.Object.

3) The constant gets its own class in the modules package with the name of the constant as the name of the class
The constant gets its own class in the package of the module with the name of the constant as the name of the class. The constant value is assigned to a static variable named value.

4) Constants defined in interfaces are declared as static variables in the Java interface already generated for the IDL interface.
Constants defined in interfaces are declared as static variables in the Java interface already generated for the IDL interface



typedef Declaration

The design philosophy with which Java was created specifically excludes type aliasing. Under Java, IDL typedefs mostly disappear. You are expected to use the underlying element type rather than the alias name. A typedef declaration does not completely disappear, though. The helper classes are still created for the type name even though a new class is not created for it. In the next lesson, you will learn how to describe the mapping of methods in IDL interfaces in Java and how to execute remote methods.

pseudo object types that ORB implementations

CORBA defines a set of pseudo object types that ORB implementations use when mapping IDL to a programming language. These object types have interfaces defined in IDL but do not have to follow the normal IDL mapping for interfaces and are not generally available in your IDL specifications. You can use only the following pseudo object types as attribute or operation parameter types in an IDL specification:
CORBA::NamedValue
CORBA::TypeCode

To use these types in an IDL specification, include the file orb.idl in the IDL file as follows:
#include <orb.idl>
//...
This statement tells the IDL compiler to allow types NamedValue and TypeCode.

IDL Java Mapping - Quiz

Click the Quiz link below to take a quiz on IDL-to-Java mapping.
IDL Java Mapping - Quiz

SEMrush Software