Cosminexus V9 BPM/ESB基盤 サービスプラットフォーム 開発ガイド 基本開発編
CSCOwnCodeConverterインターフェースを次に示します。
文字コード変換UOCを開発する場合,次のインターフェースの実装クラスを作成します。
図H-1 文字コード変換UOCクラス
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; }
メソッド名 | 説明 |
---|---|
setPropertiesメソッド | 独自定義ファイルの定義内容を文字コード変換UOCに渡すためのメソッドです。 |
ownCodeToUnicodeメソッド | 独自文字コードの文字列をUnicodeに変換するメソッドです。 |
unicodeToOwnCodeメソッド | Unicode(UTF-16)の文字列を独自文字コードに変換するメソッドです。 |
availableメソッド | 文字コード変換時に変換できる文字列のバイト数を返すメソッドです。 |
図H-2 文字コード変換UOCからの各メソッドの呼び出し順序
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;
文字コード変換UOCの開発時に発生する例外クラスを次に示します。
CSCOwnCodeConverterインターフェースの実装例を次に示します。
public class OwnConvertUoc implements CSCOwnCodeConverter { // コード変換オプション HJCOption option = null; // コード変換結果 HJCResult result = null; // エンコード String encode = null; // コンストラクタ public void OwnConvertUoc() { result = new HJCResult(); option = new HJCOption(); } // 独自定義ファイルをJavaのプロパティ形式で受け取る public void setProperties(final Properties properties) throws CSCOwnCodeConverterException { if ( properties == null ) { // 独自定義ファイルが登録されていない // 独自定義ファイルを定義できない受付・サービスアダプタから実行されている // 可能性があるのでエラーにしない encode = ""; return; } encode = properties.getProperty("encode"); if ( encode == null ) { // キーがない場合 String message = "文字コードが指定されていません。"; throw new CSCOwnCodeConverterException(message); } } // 独自コードをUnicodeに変換する public char[] ownCodeToUnicode(final byte[] inBuffer) throws CSCOwnCodeConverterException { if ( encode.equals("SJIS") ) { // SJIS(MS932)からUnicodeに変換 // コード変換を使用 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") ) { // KEISからUnicodeに変換 // コード変換を使用 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 { // 対象外の文字コード String message = "対象外の文字コードです。"; throw new CSCOwnCodeConverterException(message); } } // Unicodeを独自コードに変換する public byte[] unicodeToOwnCode(final char[] inBuffer) throws CSCOwnCodeConverterException { // (中略) } // 正常に変換できるバイト数を返す public int available(final byte[] inBuffer) throws CSCOwnCodeConverterException { // (中略) } }
All Rights Reserved. Copyright (C) 2012, 2019, Hitachi, Ltd.