| 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.
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
The Slide Show below shows the IDL interface
const mapping to the
value public static final variable in Java:
- All elements defined in a module are in the same package.
- The interface definition results in a class for the interface containing all the elements defined in the IDL interface.
- The constant gets its own class in the package of the module with the name of the constant as the name of the class.
- Constants defined in interfaces are declared as static variables in the Java interface already generated for the IDL interface
Mapped Constant Typedef Code
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.
IDL Java Mapping - Quiz
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:
To use these types in an IDL specification, include the file orb.idl in the IDL
file as follows:
This statement tells the IDL compiler to allow types NamedValue and TypeCode.