Section G.4. Basic Data Types


G.4. Basic Data Types

IDL supports the basic data types shown in Table G-2. The table also shows the Java type that each is mapped to according to the standard IDL Java mapping. Note that there isn't a standard mapping defined for the long double IDL type, because Java doesn't have a basic data type that supports the precision required. Another important thing to note is that Java doesn't support unsigned types, such as unsigned short. So you'll see in the table that IDL short and unsigned short 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 in fact be set to negative values.

Table G-2. IDL basic data types, sizes, and Java mappings

IDL type specifier

Required size

Java data type

short

16 bits

short

long

32 bits

int

long long

64 bits

long

unsigned short

16 bits

short

unsigned long

32 bits

int

unsigned long long

64 bits

long

char

8 bits

char

wchar

Implementation-dependent

char

string

Unlimited

java.lang.String

string<size>

size chars

java.lang.String

wstring

Unlimited

java.lang.String

wstring<size>

size wchars

java.lang.String

boolean

Implementation-dependent

boolean

octet

8 bits

byte

Any

Implementation-dependent

org.omg.CORBA.Any

float

IEEE single precision

float

double

IEEE double precision

double

long double

IEEE double extended

Not supported

fixed

31 decimal digits

java.math.BigDecimal


G.4.1. Strings and Characters

There 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.

We'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 chars, and a wstring is an array of wchars. In both cases, there are two ways to specify a string type: with or without a size specification or 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 bounds 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, then it's best to declare all of your character and string data as wchars and wstrings. This way you'll be sure to get multibyte support in languages that support it.

G.4.1.1. Mapping strings and characters to Java

In the IDL Java mapping, both char and wchar are mapped to the Java char type, and both string and wstring types are mapped to the java.lang.String class. In Java, the char type represents a 2-byte Unicode character and can therefore support multibyte character sets by default.

When marshaling and unmarshaling 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 bounds limits declared for the string member in the IDL specification of the interface, then an org.omg.CORBA.BAD_PARAM exception is thrown. If a character in a string falls outside the range supported by IDL, then an org.omg.CORBA.DATA_CONVERSION exception is thrown.



Java Enterprise in a Nutshell
Java Enterprise in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596101422
EAN: 2147483647
Year: 2004
Pages: 269

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net