ハンドラーおよびステップの実装例の概要

次のコードおよび疑似コードは、固定ワークフロー・ハンドラーおよび可変ワークフロー・ステップの実装例の概要を示します。

プロトコル処理ハンドラー

固定インバウンド・プロトコル処理ハンドラー (ここでは、CSV 処理をサポートするハンドラー) の実装の概要を示します。開発者によってプロトコル固有のコードを追加する必要があります。

public class MyCSVProtocolProcess implements
                                       BusinessProcessHandlerInterface {
    public boolean applies(BusinessDocumentInterface document) {
       //obtain from_protocol from BusinessDocument
        if (from_protocol.equals("CSV_PROTOCOL"))
           return true;
        return false;
       }
   public BusinessDocumentInterface process(
                                    BusinessDocumentInterface document) {
    try {
         //obtain the file contents in a String
         StringTokenizer tokenizer = new StringTokenizer(fileContents, ",");
         String fromBusinessId = tokenizer.nextToken();
         if (fromBusinessId == null) {
                                            EventInfo event = new EventInfo();
            BusinessProcessUtil.logEvent(eventInfo);
         }
         String toBusinessId = tokenizer.nextToken();
         String fromPackaging = tokenizer.nextToken();
         String customerId = tokenizer.nextToken();
         String customerName = tokenizer.nextToken();
         String documentType = tokenizer.nextToken();
         String documentVersion = tokenizer.nextToken();
          ... 
         //log obtained parameters
          ...
          document.setValue(DocumentConstant.FRBUSINESSID, fromBusinessId);
          document.setValue(DocumentConstant.TOBUSINESSID, toBusinessId);
          document.setValue(DocumentConstant.INITBUSINESSID, customerId);
          document.setValue(DocumentConstant.FRPROTOCOLNAME,
                                                 "CSV_PROTOCOL ");
          document.setValue(DocumentConstant.FRPROCESS, documentType);
          document.setValue(DocumentConstant.FRPROCESSVER, documentVersion);
           ...
           document.setDocumentState(BusinessProcessUtil.BCG_DOC_IN_PROCESS);
       } catch (Exception e) {
                                 EventInfo event = new EventInfo();
         document.addEvent(event);
         document.setDocumentState(BusinessProcessUtil.BCG_DOC_FAILED);
          } 
           return document;
       }
   }
 

プロトコル・アンパック・ハンドラー

固定インバウンド・プロトコル・アンパック・ハンドラー (ここでは、Websphere Commerce Business Edition からパッケージ化するカスタム XML をサポートするハンドラー) の実装の概要を示します。開発者によってプロトコル固有のコードを追加する必要があります。

public class WCBEXMLProtocolUnpackagingHandler implements
                                     BusinessProcessHandlerInterface {
  
    private Context m_context = null;
    private rConfig m_config = null;
  
    public void init(Context context,Config config) {
               this.m_context = context;
       this.m_config = config;
       return;
     }
     public boolean applies() {
           //obtain schema for this XML
           if (schemaLocation.startsWith("http://www.ibm.com/WCBE/schemas/"))
                  return true;
            return false;
     }
  
     public BusinessDocumentInterface process(
                                     BusinessDocumentInterface document) {
           try {
                  document.setValue(DocumentConst.FRPACKAGING, "WCBEPackaging");
                  /*
                   * Parse the file and obtain the following information:
                   * 1. Recipient Name
                   * 2. Type of document - PurchaseOrder, RFQ
                   */
  
             //obtain receiver_id
             PartnerService partnerService = BusinessProcessUtil.getPartnerService();
             String receiver_id = partnerService.getBusinessId(recipientName,
                                     PartnerService.COMMUNITY_PARTICIPANT);
                  if (receiver_id == null) {
              EventInfo event = new EventInfo();
                      BusinessProcessUtil.logEvent(msg);
              document.setDocumentState(
                        BusinessProcessUtil.BCG_DOCSTATE_FAILED);
                  }
                 document.setValue(DocumentConstant.TOBUSINESSID, receiver_id);
                 document.setValue(DocumentConst.FRPROCESSCD, documentType);
  
     document.setDocumentState(BusinessProcessUtil.BCG_DOCSTATE_IN_PROCESS);
        }catch (Exception e) {
             EventInfo event = new EventInfo();
             document.addEvents(event);
 document.setDocumentState(BusinessProcessUtil.BCG_DOCSTATE_FAILED);
  }
          return document;
      } 
 }
 

検証ステップ

可変ワークフロー・ステップ (ここでは、WCBE 仕入れ注文文書を検証するステップ) の実装の概要を示します。 2 つの部分があります。最初の部分は、ファクトリー・インターフェース BusinessProcessFactoryInterface を実装し、2 番目の部分はプロセス・インターフェースBusinessProcessInterface を実装します。開発者によってプロトコル固有のコードを追加する必要があります。

ファクトリー・クラス:

public class WCBEXMLValidationFactory implements
                                    BusinessProcessFactoryInterface {
  
     public BusinessDocumentInterface getBusinessProcess(Context context,
                                                     Config config,
                                            BusinessDocumentInterface bDoc)
 {
  
 // Can use any configuration values from config as necessary.  These
 //are set via the Console.
  
          WCBEValidationBusinessProcess bp = new WCBEValidationBusinessProcess();
             // Set any items in this class as specific to the implementation
 // between the factory and the business process class.
  
  
             return bp;
      }
  
 public static void returnBusinessProcess(BusinessProcessInterface bp)
                                        throws BCGWorkflowException {
       // if not reusing Business Processes then do nothing.
  }
 }
 

プロセス・クラス:

public class WCBEValidationBusinessProcess implements
                                         BusinessProcessInterface {
  
     public BusinessDocumentInterface process(BusinessDocumentInterface bDoc,
                                          Context context) {
            /*
             * Obtain document's contents.
             */
          File document = bDoc.getDocument();
    // Read in file.
  
  
            //obtain validation map
          MapService mapService = BusinessProcessUtil.getMapService();
          byte[] fromValidationMap = mapService.getFromValidationMap(bDoc, context);
  
    /* Obtain a validating XML parser instance.
     * Set the validation map location in the parser.
             * Validate the XML by parsing it.
             */ 
  
  
 /*
          * Validate the PurchaseOrder:
  *
          * if document type is PurchaseOrder
          *     check if there is at least one orderitem
          *             if there is atleast one orderitem
          *                    check if the quantity ordered is atleast one
          *                    if the quantity ordered is less than 1
          *                           set document status to DOC_FAILED
          *                           throw BCGInvalidDocumentException
          *             else
          *                     set document status to DOC_FAILED
          *                     throw BCGInvalidDocumentException
          * 
          */
  
  return bDoc
     }
  
     public boolean reset() {
         /* 
          * reset internal variables.
          */
      }
 }
 

変形ステップ

可変ワークフロー・ステップ (ここでは、文書をあるフォーマットから別のフォーマットに変形するステップ) の実装の概要を示します。このサンプルには、プロセス実装のコードおよび疑似コードのみが含まれていますが、関連するファクトリーも必要です。開発者によってプロトコル固有のコードを追加する必要があります。

プロセス・クラス:

public class WCBETransformationBusinessProcess implements
                                                 BusinessProcessInterface {
  
     public BusinessDocumentInterface process(BusinessDocumentInterface bDoc,
                                            Context context) {
             //obtain transformation map
              MapService mapService = BusinessProcessUtil.getMapService();
               byte[] transformationMap = mapService.getTransformationMap(
                                                        bDoc, context);
     // Transformer is for example only and is part of customer
     // implementation.
      Transformer transformer = new Transformer(transformationMap);
  
   // Get the Business document file.
     File message = bDoc.getDocument();
   //get contents of File
     byte[] transformOutput = transformer.transform(fileContents);
     File transformedFile = bDoc.createFile();
   //write transformedOutput to transformedFile
    bDoc.setDocument(transformedFile);
          return bDoc;
     } 
  
     public boolean reset() {
          /* 
           * reset internal variables.
           */
       }
 }
 

Copyright IBM Corp. 1997, 2004