com.ibm.as400.access
Class AS400BidiTransform

java.lang.Object
  extended by com.ibm.as400.access.AS400BidiTransform

public class AS400BidiTransform
extends Object

Provides layout transformations that allow the conversion of Bidi text in IBM i format (after its conversion to Unicode), to Bidi text in Java format; or vice-versa.

Bidi text is a combination of a sequence of characters and a set of Bidi flags. That text (Arabic or Hebrew) has characters which are read from right to left. That text might also be mixed with numbers which are read from left to right, and possibly also mixed with Latin characters. Conversion support is needed to display text properly with the correct order and shape.

Bidi text from an IBM i system may be represented by a combination of a String (the characters) and a CCSID (which implies a set of Bidi flags specific to that CCSID).

Multi-threading considerations: Different threads may use the same AS400BidiTransform object if they have the same transformation needs, as follows:

Otherwise, each thread must use its own instances of this class.

The following examples illustrate how to transform bidi text:

 // Java data to IBM i layout:
 AS400BidiTransform abt;
 abt = new AS400BidiTransform(424);
 String dst = abt.toAS400Layout("some bidi string");

 // Specifying a new CCSID for an existing AS400BidiTransform object:
 abt.setAS400Ccsid(62234);                    // 420 RTL //
 String dst = abt.toAS400Layout("some bidi string");

 // Specifying a non-default string type for a given CCSID:
 abt.setAS400StringType(BidiStringType.ST4);  // Vis LTR //
 String dst = abt.toAS400Layout("some bidi string");

 // Specifying a non-default string type for Java data:
 abt.setJavaStringType(BidiStringType.ST11);  // Imp Context LTR //
 String dst = abt.toAS400Layout("some bidi string");

 // How to transform IBM i data to Java layout:
 abt.setJavaStringType(BidiStringType.ST6);   // Imp RTL //
 String dst = abt.toJavaLayout("some bidi string");
 
A more simplified method is to use bidiTransform(). The following example illustrates how to use it:
 String src = "some bidi string";
 String result = AS400BidiTransform.bidiTransform(src, BidiStringType.ST4,  BidiStringType.ST6); // from visual LTR to Implicit RTL //
 


Constructor Summary
AS400BidiTransform(int as400Ccsid)
          Constructs an AS400BidiTransform object assuming that the IBM i Bidi text conforms to a given CCSID.
 
Method Summary
static String bidiTransform(String str, int inFormat, int outFormat)
          Bidi-HCG Perform Bidi layout transformation by given Bidi string types.
 int getAS400Ccsid()
          Returns the current CCSID of IBM i data.
 int getAS400StringType()
          Returns the current string type of the IBM i data.
 BidiConversionProperties getBidiConversionProperties()
          Returns the bidi conversion properties.
 int getJavaStringType()
          Returns the current string type of Java data.
static int getStringType(int ccsid)
          Returns Bidi string type defined for CCSID
static boolean isBidiCcsid(int ccsid)
          Indicates if a given CCSID may apply to Bidi data.
static boolean isVisual(int ccsid)
          Indicates if a given CCSID has a visual string type.
static String meta_data_reordering(String value_, int inFormat, int outFormat)
           
 void setAS400Ccsid(int as400Ccsid)
          Sets the CCSID.
 void setAS400StringType(int as400Type)
          Set the explicit string type for the IBM i data.
 void setBidiConversionProperties(BidiConversionProperties properties)
          Sets the bidi conversion properties.
 void setJavaStringType(int javaType)
          Set the explicit string type for Java data.
static String SQL_statement_reordering(String value_, int inFormat, int outFormat)
          Bidi-HCG Perform Bidi layout transformation of a data into SQL statement.
 String toAS400Layout(String javaText)
          Convert data from the Java layout to the IBM i layout.
 String toJavaLayout(String as400Text)
          Convert data from the IBM i layout to the Java layout.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AS400BidiTransform

public AS400BidiTransform(int as400Ccsid)
Constructs an AS400BidiTransform object assuming that the IBM i Bidi text conforms to a given CCSID. Typically this will be the CCSID of the system.

The given CCSID has a default string type which defines a set of Bidi flags. The orientation implied by this string type is applied to both the IBM i data layout and the Java data layout.

Parameters:
as400Ccsid - The CCSID of the IBM i data.
Method Detail

isBidiCcsid

public static boolean isBidiCcsid(int ccsid)
Indicates if a given CCSID may apply to Bidi data. This is the case for Arabic and Hebrew CCSIDs, and for Unicode (which can encode anything).

If a CCSID is not Bidi, there is no need to perform layout transformations when converting IBM i data to Java data and vice-versa.

Parameters:
ccsid - The CCSID to check.
Returns:
true if the given CCSID may apply to Bidi data, false otherwise.

isVisual

public static boolean isVisual(int ccsid)
Indicates if a given CCSID has a visual string type.

Parameters:
ccsid - The CCSID to check.
Returns:
true if the given CCSID has a visual string type, false otherwse.

setAS400Ccsid

public void setAS400Ccsid(int as400Ccsid)
Sets the CCSID.

The given CCSID has a default string type which defines a set of Bidi flags. The orientation implied by this string type is applied to both the IBM i data layout and the Java data layout.

Parameters:
as400Ccsid - The CCSID of the IBM i data.

getAS400Ccsid

public int getAS400Ccsid()
Returns the current CCSID of IBM i data.

Returns:
The CCSID for the IBM i data.

setAS400StringType

public void setAS400StringType(int as400Type)
Set the explicit string type for the IBM i data. Each CCSID has a default CDRA string type, which defines a set of Bidi flags. This method may be used to specify Bidi flags different from those implied by the CCSID.

Parameters:
as400Type - The string type to apply to the IBM i data. The parameter string type should always be one of the constants defined in BidiStringType.
See Also:
BidiStringType

getAS400StringType

public int getAS400StringType()
Returns the current string type of the IBM i data.

Returns:
The string type of the IBM i data.

setJavaStringType

public void setJavaStringType(int javaType)
Set the explicit string type for Java data.

Parameters:
javaType - The string type to apply to Java data.
See Also:
BidiStringType

getJavaStringType

public int getJavaStringType()
Returns the current string type of Java data.

Returns:
The string type of the Java data.

setBidiConversionProperties

public void setBidiConversionProperties(BidiConversionProperties properties)
Sets the bidi conversion properties.

Parameters:
properties - The bidi conversion properties.

getBidiConversionProperties

public BidiConversionProperties getBidiConversionProperties()
Returns the bidi conversion properties.

Returns:
The bidi conversion properties.

toJavaLayout

public String toJavaLayout(String as400Text)
Convert data from the IBM i layout to the Java layout.

Parameters:
as400Text - The IBM i string to convert.
Returns:
The same text in standard Java Bidi layout.

toAS400Layout

public String toAS400Layout(String javaText)
Convert data from the Java layout to the IBM i layout.

Parameters:
javaText - The Java string to convert.
Returns:
The same text in IBM i Bidi layout.

getStringType

public static int getStringType(int ccsid)
Returns Bidi string type defined for CCSID

Parameters:
ccsid -
Returns:
Bidi string type

bidiTransform

public static String bidiTransform(String str,
                                   int inFormat,
                                   int outFormat)
Bidi-HCG Perform Bidi layout transformation by given Bidi string types.

Parameters:
str - The Java string to convert.
inFormat - Input format.
outFormat - Output format.
Returns:
The same text after Bidi layout transformation.

SQL_statement_reordering

public static String SQL_statement_reordering(String value_,
                                              int inFormat,
                                              int outFormat)
Bidi-HCG Perform Bidi layout transformation of a data into SQL statement. Meta-data (names of columns etc.) is kept untouched.

Parameters:
value_ - Given SQL statement.
inFormat - Input format.
outFormat - Output format.
Returns:
The SQL statement after the Bidi layout transformation.

meta_data_reordering

public static String meta_data_reordering(String value_,
                                          int inFormat,
                                          int outFormat)