ビジネス・オブジェクトを作成する場合、BO の動詞 ASI に CBOH キーワードを指定すると、デフォルトの BO ハンドラーをオーバーライドできます。コネクターの実行時に、doVerbFor() メソッドを使用して、ビジネス・オブジェクト ASI を検索します。CBOH キーワードが検出されると、doVerbFor() によってカスタム BO ハンドラーが起動されます。
カスタム BO ハンドラーを使用すると、プロキシー・クラスに直接アクセスできます。そのため、ローダー、起動側、および接続プールからの接続の検索処理をバイパスできます。これらの処理については、5 および 7 で説明します。
コネクターでは、親レベルのビジネス・オブジェクトのみでカスタム BO ハンドラーをサポートします。
以下に示すカスタム BO ハンドラーの例では、ビジネス・オブジェクトが CBOH=comadaptertest.Lotus123BOHandler という動詞 ASI を使用して定義されているものと想定します。ビジネス・オブジェクトは、CellAddress=A1 という属性 ASI を持ちます。この場合の A1 は、ワークシートに表示される属性のアドレスです。カスタム BO ハンドラーは、属性 ASI によって指定されたセル・アドレスを使用して、ワークシートに属性を書き込みます。
package comadaptertest; import com.crossworlds.cwconnectorapi.*; import com.crossworlds.cwconnectorapi.exceptions.*; import java.util.*; import com.ibm.adapters.utils.comproxy.*; import lotus123.*; public class Lotus123BOHandler implements CWCustomBOHandlerInterface { public int doVerbForCustom(CWConnectorBusObj bo) throws VerbProcessingFailedException { Application currentApplication; Document currentDocument; CWConnectorUtil.traceWrite(CWConnectorUtil.LEVEL4, "Entering AdapterBOHandler.doVerbFor()"); try { currentDocument = new Document(); // Get the application object. currentApplication = new Application(currentDocument. get_Parent()); // Make the application visible. currentApplication.set_Visible(new Boolean("true")); currentDocument = new Document(currentApplication. NewDocument()); } catch (ComException e) { CWConnectorUtil.generateAndLogMsg(91000, CWConnectorUtil.XRD_ERROR, CWConnectorUtil. CONNECTOR_MESSAGE_FILE, e.getMessage()); CWConnectorExceptionObject vSub = new CWConnectorExceptionObject(); vSub.setMsg(e.getMessage()); vSub.setStatus(CWConnectorConstant. APPRESPONSETIMEOUT); throw new VerbProcessingFailedException(vSub); } //do verb processing on this business object dispatch(bo, currentDocument); CWConnectorUtil.traceWrite(CWConnectorUtil. LEVEL4, "Leaving AdapterBOHandler.doVerbFor()"); return CWConnectorConstant.SUCCEED; } //doVerbFor private void dispatch(CWConnectorBusObj bo, Document currentDocument) throws VerbProcessingFailedException { CWConnectorUtil.traceWrite(CWConnectorUtil. LEVEL4, "Entering dispatch"); CWConnectorUtil.traceWrite(CWConnectorUtil. LEVEL3, "Processing business object" + bo.getName()); try { //put this object out onto the spreadsheet. //Follow ASI for Cell addresses businessObjectToWorksheet(bo, currentDocument); } catch (ComException e) { CWConnectorUtil.generateAndLogMsg(90001, CWConnectorUtil.XRD_ERROR, CWConnectorUtil. CONNECTOR_MESSAGE_FILE, e.getMessage()); CWConnectorExceptionObject vSub = new CWConnectorExceptionObject(); vSub.setMsg(e.getMessage()); vSub.setStatus(CWConnectorConstant. APPRESPONSETIMEOUT); throw new VerbProcessingFailedException(vSub); } catch (CWException e) { CWConnectorExceptionObject vSub = new CWConnectorExceptionObject(); vSub.setMsg(e.getMessage()); vSub.setStatus(CWConnectorConstant.FAIL); throw new VerbProcessingFailedException(vSub); } } public static void businessObjectToWorksheet(CWConnectorBusObj bo, Document currentDocument) throws CWException { String incomingAttribute = ""; int attrCount = bo.getAttrCount() - 1; //ignore objeventID Ranges ranges; Range currentRange; ranges = new Ranges(currentDocument.get_Ranges()); for (int i = 0; i < attrCount; i++) { try { if ((!bo.isObjectType(i)) && (!bo.isIgnore(i))) { if (bo.isBlank(i)) incomingAttribute = ""; else incomingAttribute = bo.getStringValue(i); String CellAddress = getCellAddress(bo, i); currentRange = new Range(ranges.Item(new String(CellAddress))); currentRange.set_Contents(incomingAttribute); if (CWConnectorUtil.isTraceEnabled (CWConnectorUtil.LEVEL5)) { CWConnectorUtil.traceWrite (CWConnectorUtil.LEVEL5, "Application datum from BO to application " + CellAddress + "=" + incomingAttribute); } } } catch (AttributeNotFoundException e) { CWConnectorUtil.generateAndLogMsg(91012, CWConnectorUtil.XRD_ERROR, CWConnectorUtil.CONNECTOR_MESSAGE_FILE, bo.getAttrName(i), bo.getName()); throw e; } catch (WrongAttributeException e) { CWConnectorUtil.generateAndLogMsg(91013, CWConnectorUtil.XRD_ERROR, CWConnectorUtil.CONNECTOR_MESSAGE_FILE, bo.getAttrName(i), bo.getName()); throw e; } } } public static String getCellAddress(CWConnectorBusObj bo, int i) throws CWException { String columnName = null; try { columnName = getNameFromASI (bo.getAttrASIHashtable(i, ":"), "CellAddress"); } catch (WrongASIFormatException e) { CWConnectorUtil.generateAndLogMsg(91014, CWConnectorUtil.XRD_ERROR, CWConnectorUtil.CONNECTOR_MESSAGE_FILE, bo.getAttrName(i), "ColumnName"); throw e; } return columnName; } private static String getNameFromASI(Hashtable asi, String fieldName) throws CWException, WrongASIFormatException { String resultName = (String) asi.get(fieldName); if (resultName == null || resultName.equals("")) throw new WrongASIFormatException(); resultName = resultName.toUpperCase(); CWConnectorUtil.traceWrite(CWConnectorUtil.LEVEL4, "Found " + fieldName + " = " + resultName); return resultName; } }