uCosminexus Service Platform, Basic Development Guide
(1) Interface
CSCOwnCodeConverter interface is as follows:
Create the implementation class of following interface, when developing the character code conversion UOC.
Figure I-1 Figurecharacter code conversion UOC class
- Interface name
- CSCOwnCodeConverter interface
- Description
- This is interface for implementing character code conversion UOC.
- Package name of CSCOwnCodeConverter is jp.co.Hitachi.soft.csc.dt.uoc.CSCOwnCodeConverter.
- Format
public class OwnCodeConverter implements CSCOwnCodeConverter
{
public void setProperties(final Properties properties)
throws CSCOwnCodeConverterException;
public char[] ownCodeToUnicode(final byte[] inBuffer)
throws CSCOwnCodeConverterException;
public byte[] unicodeToOwnCode(final char[] inBuffer)
throws CSCOwnCodeConverterException;
public int available(final byte[] inBuffer)
throws CSCOwnCodeConverterException;
}
- Methods
- Following table describes the methods of CSCOwnCodeConverter interface:
Method name |
Description |
setProperties method |
This is a method for passing definition contents of self-defined file to the character code conversion UOC. |
ownCodeToUnicode method |
This is method for converting the character string of self-defined character code to Unicode. |
unicodeToOwnCode method |
This is the method for converting the character string of Unicode(UTF-16) to self-defined character code. |
Available method |
This is the method of returning bytes count of character string that can be converted at the time of character code conversion. |
- Following figure shows the order of invoking each method from the character code conversion UOC.
Figure I-2 FigureOrder of invoking each method from character code conversion UOC
- Generating an instance
After receiving the message before conversion, generate an instance of character code conversion UOC, depending on data transformation.
- setProperties method
Pass the definition contents of the self-defined file to character code conversion UOC. This method is invoked only once at the time of starting character code conversion UOC.
- ownCodeToUnicode method, unicodeToOwnCode method, available ,method
The respective methods are invoked from character code conversion at the time of executing character code conversion UOC. Method execution order depends on the message format.
- ownCodeToUnicode method
This method is used to convert character string of self-defined character code to Unicode.
- unicodeToOwnCode method
This method is used to convert the character string of Unicode(UTF-16) to the self-defined character code.
- available method
This method is used to return the bytes count of character string that can be converted at the time of character code conversion.
(a) setProperties method
- Description
- Passes the definition contents of the self-defined file to character code conversion UOC.
- Format
public void setProperties(final Properties properties)
throws CSCOwnCodeConverterException;
- Parameter
- properties:
- Definition contents of self-defined file are stored.
- Notes
- In the following cases, arguments of setProperties method always become null. Implement such that error does not occur for character code conversion UOC, even when the argument of setProperties method are null.
- When self-defined file does not exist (not defined)
- When executing character code conversion UOC from reception other than custom reception (reception for which self-defined file cannot be defined)
- When executing character code conversion UOC from adapter for which self-defined file cannot be defined
- Exception
- CSCOwnCodeConverterException:
- Entire data transformation process is aborted as an error occurred during the character code conversion process.
- Return value
- None
(b) ownCodeToUnicode method
- Description
- This method converts the character string of self-defined character code to Unicode.
- Format
public char[] ownCodeToUnicode(final byte[] inBuffer)
throws CSCOwnCodeConverterException;
- Parameter
- inBuffer:
- Buffer of the byte array that stores the character string of self-defined character code is stored. As this buffer is read-only, you cannot edit the same.
- Exception
- CSCOwnCodeConverterException:
- Entire data transformation process was aborted as error occurred during the character code conversion process.
- Return value
- Returns the buffer of character array that stores the character string converted to Unicode.
(c) unicodeToOwnCode method
- Description
- Coverts the character string in Unicode(UTF-16) to self-defined character code.
- Format
public byte[] unicodeToOwnCode(final char[] inBuffer)
throws CSCOwnCodeConverterException;
- Parameter
- inBuffer:
- Buffer of character array that stores the character string of Unicode is stored.
- Since this buffer is read-only you cannot edit the same.
- Exception
- CSCOwnCodeConverterException:
- Entire data transformation process was aborted, as error occurred during the character code conversion process.
- Return value
- Returns the byte array buffer that stores the character string converted to the self-defined character code.
(d) available method
- Description
- Returns the byte count of character string that can be converted at the time of character code conversion.
- Format
public int available(final byte[] inBuffer)
throws CSCOwnCodeConverterException;
- Parameter
- inBuffer:
- Buffer of the byte array that stores the character string of self-defined character code is stored. Since this buffer is read-only, you cannot edit the same.
- Exception
- CSCOwnCodeConverterException:
- Entire data transformation process was aborted, as error occurred during the character code conversion process.
- Return value
- Stores the byte count of character string that can be successfully converted. If any character cannot be converted, stores the byte count till character just before the concerned character.
(2) Exception class
Exception class that occurs at the time of developing character code conversion UOC is as follows:
- Class name
- CSCOwnCodeConverterException class
- Description
- This exception is sent when error occurs during the character code conversion process.
- When this exception occurs, entire data transformation process is aborted.
(3) Implementation example
Implementation example of CSCOwnCodeConverter interface is as follows:
public class OwnConvertUoc implements CSCOwnCodeConverter {
// Code conversion option
HJCOption option = null;
// Code conversion result
HJCResult result = null;
// Encode
String encode = null;
// Constructor
public void OwnConvertUoc() {
result = new HJCResult();
option = new HJCOption();
}
// Receive self-defined file in property format of Java
public void setProperties(final Properties properties)
throws CSCOwnCodeConverterException {
if ( properties == null ) {
// self-defined file has not been registered
// self-defined file is executed from the non-defined reception/service adapter
// Since there is a possibility of occurrence, it is not considered as error
encode = "";
return;
}
encode = properties.getProperty("encode");
if ( encode == null ) {
// When key does not exist
String message = "Character code is not specified.";
throw new CSCOwnCodeConverterException(message);
}
}
// Convert the self-defined code to Unicode
public char[] ownCodeToUnicode(final byte[] inBuffer)
throws CSCOwnCodeConverterException {
if ( encode.equals("SJIS") ) {
// Convert from SJIS(MS932) to Unicode
// Use code conversion
HJCString inStr = new HJCString( inBuffer );
try {
HJCConverters.cs_ms932tounicode(inStr, result, option);
} catch ( Exception e ){
throw new CSCOwnCodeConverterException(e);
}
return result.getStrResult().toString().toCharArray();
}
else if ( encode.equals("KEIS") ) {
// Convert from KEIS to Unicode
// Use code conversion
HJCString inStr = new HJCString( inBuffer );
try {
HJCConverters.cs_keistounicode(inStr, result, option);
} catch ( Exception e ){
throw new CSCOwnCodeConverterException(e);
}
return result.getStrResult().toString().toCharArray();
}
else {
// Character code not considered as target
String message = "This is a character code not considered as target.";
throw new CSCOwnCodeConverterException(message);
}
}
// Convert Unicode to self-defined code
public byte[] unicodeToOwnCode(final char[] inBuffer)
throws CSCOwnCodeConverterException {
// (omitted)
}
// Returns the byte count, that can be successfully converted
public int available(final byte[] inBuffer)
throws CSCOwnCodeConverterException {
// (omitted)
}
}
- Note
- For implementation same as example, you must purchase code conversion separately.
All Rights Reserved. Copyright (C) 2015, Hitachi, Ltd.