10.4. Basic Data TypesIDL supports the basic data types shown in Table 10-2. In the same table, I've shown the Java type that each is mapped to according to the standard IDL-to-Java mapping. Note that there isn't a standard mapping defined for the fixed and long double IDL types. These data types were added to the IDL syntax relatively recently, and the IDL Java mapping hasn't been updated to include these as of this writing. Another important thing to note is that Java doesn't support unsigned types, such as unsigned short. So the IDL short and unsigned short types are both mapped to the Java short data type. You should be aware of this when writing implementations of IDL-generated Java interfaces, since it is up to you to either ensure that their values remain positive or deal with the fact that their values may be set to negative values. Table 10-2. IDL Basic Data Types, Sizes, and Java Mappings
10.4.1. Strings and CharactersThere are two character types included in IDL: char and wchar. A char represents an 8-bit character from a single-byte character set, such as ASCII. A wchar represents a wide character from any character set, including multibyte character sets like Kanji. The size of a wchar is implementation-specific. I've included the IDL string and wstring data types in this table as well, although technically they should be considered constructed data types (arrays of a basic data type, characters). Since they're so frequently used, it's useful to have them together with all of the IDL basic data types. A string is the equivalent of an array of char values, and a wstring is an array of wchar values. In each case, there are two ways to specify a string type: with or without a size specification, in angle brackets following the type name. If you provide a size specification in your IDL declaration (e.g., string<10> name), the language mapping is responsible for enforcing the size limits of the string. If you don't provide a size specification, the string is allowed to grow to any size, limited only by the implementation language. If support for a multibyte character set is important for your application, it's best to declare all your character and string data as wchar and wstring values. This way you'll be sure to get multibyte support in languages that support it. 10.4.1.1. Mapping strings and characters to JavaIn the IDL-to-Java mapping, both char and wchar are mapped to the Java char type, and both string and wstring are mapped to the java.lang.String class. In Java, the char type represents a two-byte Unicode character and can therefore support multibyte character sets by default. When marshalling and unmarshalling data items during remote method calls, the ORB is responsible for performing bounds checks on the data members being set. If a value exceeds the limits declared for the string member in the IDL specification of the interface, an org.omg.CORBA.MARSHAL exception is thrown. Copyright © 2001 O'Reilly & Associates. All rights reserved. |
|