This discussion is based on the existing DayOfWeek example. DayOfWeek is a service that creates a simple server to return the day of the week for any date entered. It is located in your <installdir>\tutorials\webservices\DayOfWeek directory.
While the regular example returns the day in English, perhaps you wish to modify the server to return the day in Japanese. You could modify the server method to output the string in Shift-JIS, convert it to UTF-8, and send it as a SOAP response over the wire. The client could then convert it back to Shift-JIS. The resulting output would then be the Shift-JIS representation of the day of the week.
Creating a custom converter requires the following steps:
Generate code.
Create the converter.
The following sections discuss these steps. In addition, note that the discussion is Windows-based.
Generate code, as always. For example,
<prompt> rwsfgen -projectname CharConvert DayOfWeek.wsdl
You do not need to explicitly link in the ICU libraries, as that is performed automatically at runtime.
HydraExpress offers several options for creating custom converters. The option discussed in this section creates a converter that uses the class RWUFromUnicodeConverter from the Internationalization Module of SourcePro Core.
Assuming you are building a DayOfWeek service that returns the day in Japanese, you would need a converter to and from UTF-8 and Shift-JIS.
For example, the following code
RWUFromUnicodeConverter from("SHIFT_JIS");
creates a server-side converter from that will convert from Unicode (UTF-8) to Shift-JIS.
The application could then define a set of arrays to hold each weekday in Japanese.
RWUChar16 sunday[] = { 0x65E5, 0x66DC, 0x65E5, 0x0 }; <! -- 1 --> RWUChar16 monday[] = { 0x6708, 0x66DC, 0x65E5, 0x0 }; RWUChar16 tuesday[] = { 0x706B, 0x66DC, 0x65E5, 0x0 }; RWUChar16 wednesday[] = { 0x6C34, 0x66DC, 0x65E5, 0x0 }; RWUChar16 thursday[] = { 0x6728, 0x66DC, 0x65E5, 0x0 }; RWUChar16 friday[] = { 0x91D1, 0x66DC, 0x65E5, 0x0 }; RWUChar16 saturday[] = { 0x571F, 0x66DC, 0x65E5, 0x0 };
//1 | Uses a set of hexadecimal values for each UTF-16 code point. For more information on Unicode, see the Internationalization Module's User's Guide at the location noted below. |
The client can now convert the strings to Shift-JIS. Here's an example of how that could be done:
RWCString day = date_in.weekDayName(); if (day == "Saturday") return RWUString(saturday).toBytes(from); if (day == "Sunday") return RWUString(sunday).toBytes(from); if (day == "Monday") return RWUString(monday).toBytes(from); if (day == "Tuesday") return RWUString(tuesday).toBytes(from); if (day == "Wednesday") return RWUString(wednesday).toBytes(from); if (day == "Thursday") return RWUString(thursday).toBytes(from); if (day == "Friday") return RWUString(friday).toBytes(from);
For each day that matches the day string, this code generates an RWUString from the UTF-16 character string and then uses RWUString.toBytes to return an RWCString containing Shift_JIS using the converter from.
For more information on performing conversions and manipulating string data in various character encodings, see the Internationalization Module User's Guide on the Rogue Wave website (From http://www.roguewave.com, select Support | Product Documentation | SourcePro® C ++ Edition 9 | Internationalization Module User's Guide.)
When you create custom code for inclusion in a HydraExpress project, you must copy the header file to your code generation directory at \include\project name.
© Copyright Rogue Wave Software, Inc. All Rights Reserved. All Rights Reserved. Rogue Wave is a registered trademark of Rogue Wave Software, Inc. in the United States and other countries. HydraExpress is a trademark of Rogue Wave Software, Inc. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.