XML データ・ハンドラーのカスタマイズは以下により実行できます。
XML データ・ハンドラーはネーム・ハンドラーを呼び出して、XML メッセージからビジネス・オブジェクトの名前を抽出します。 XML データ・ハンドラーに組み込まれているデフォルトのネーム・ハンドラーは、次のタグを探します。
<!DOCTYPE Name>
このタグと BOPrefix メタオブジェクト属性から、データ・ハンドラーはビジネス・オブジェクトの名前を生成します。 XML データ・ハンドラーは、データ・ハンドラー・メタオブジェクトに格納されている NameHandlerClass 属性の値を使用して、起動するネーム・ハンドラーを判別します。
ネーム・ハンドラーを別の方法で機能させる必要がある場合には、次を実行する必要があります。
次のサンプル・コードは、DataHandler クラスを拡張して、XML データ・ハンドラーのカスタム・データ・ハンドラー CustomDataHandler を作成します。
package com.crossworlds.DataHandlers.xml; // DataHandler Dependencies import com.crossworlds.DataHandlers. Exceptions.MalformedDataException; import com.crossworlds.DataHandlers.NameHandler; import com.crossworlds.DataHandlers.DataHandler; // Java classes import java.io.*; import java.lang.Exception; /*********************************************************** * CustomNameHandler class. This class extends the Namehandler * class and implements method: * getBOName( Reader serializedData, String subType ) * The method getBOName contains the logic to extract the BOName *************************************************************/ public class CustomNameHandler extends NameHandler { /** * This method generates the business object name from * the data extracted from the 'serializedData' arg. * In this case, it is up to the caller to create * the BOName. */ public String getBOName( Reader serializedData, String subType ) throws MalformedDataException { // The NameHandler uses DataHandler tracing. If the // DataHandler is not set, the NameHandler won't run. if (dh == null) return null; // Log a message dh.traceWrite( "Entering CustomNameHandler.getBOName for subtype '" + subType + "'.", 4); // This method parses the XML document and extracts the // business object name from the following tag in // the XML doc: // <cml title= // For example, in: // <cml title="cholestrol" id="cml_cholesterol"> // the business object name is 'cholestrol'. // Log a message dh.traceWrite( "Name resolution will be done using <cml title= ",4); String name = null; try { // Read line of data from the Reader object LineNumberReader lineReader = new LineNumberReader( serializedData ); serializedData.mark( 1000 ); String line = lineReader.readLine(); while ( line != null ) { // search for <cml title= in the line int start = line.indexOf("<cml title="); if ( start != -1 ) { start += 12; // search for the ending quotes for the tile tag int end = line.indexOf('\"', start); // extract name from line name = line.substring(start, end); break; } line = lineReader.readLine(); } if ( name == null || name.length() == 0 ) throw new MalformedDataException( "Error: can't determine the BusinessObject Name."); } catch(Exception e) { throw new MalformedDataException( e.getMessage() ); } serializedData.reset(); return name; } }
XML データ・ハンドラーで使用される SAX パーサーはエンティティー・リゾルバーを呼び出して、XML 文書内の外部エンティティー (参照される DTD) を検索します。XML データ・ハンドラーに組み込まれるエンティティー・リゾルバーは、外部参照を無視するか、またはローカル・ファイル・システム上で検索できます。別の方法を指定して外部エンティティーを検出する必要がある場合は、カスタム・エンティティー・リゾルバー・クラスを作成する必要があります。
XML データ・ハンドラーは、XML データ・ハンドラー・メタオブジェクトに格納されている EntityResolver 属性の値を使用して、起動するエンティティー・リゾルバーを判別します。