WebSphere Message Broker バージョン 8.0.0.5 オペレーティング・システム: AIX、HP-Itanium、Linux、Solaris、Windows、z/OS

製品の最新バージョンについては、IBM Integration Bus バージョン 9.0 をご覧ください。

フィルターを使った反復処理

メッセージ・ツリー内のエレメントをフィルター操作するには、FilterIterator を使用します。

次の例は、FilterIterator を使用してメッセージ・ツリーを反復処理し、Toughened Steel コンポーネントだけを抽出する方法を示しています。
class ToughenedSteelPartsIterator extends FilterIterator
{
  public function __construct(Iterator $it)
  {
    parent::__construct($it);
  }

  function accept()
  {
    /*** only check components ***/
    if (!strcmp($this->key(),"component"))
    {
      /*** Return true for Toughened Steel ***/
      if (!strcmp($this->current()->material,"Toughened Steel"))
      {
        return true;
      }
    }
    return false;
  }
}

class PhpComputeNode_Iterator_Filter
{
  /**
   * @MessageBrokerSimpleTransform
   */
  function evaluate($output_assembly, $input_assembly)
  {
    ob_start();
    echo "¥nIterating over parts which have a material name of Toughened Steel¥n";

    $it  = new MbsElementIterator($input_assembly->XMLNSC->getFirstChild());
    $rii = new ToughenedSteelPartsIterator(new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST));

    foreach($rii as $key=>$value)
    {
      echo $key.' = '.$value->name." ".$value->price." ".$value->material."\n";
    }

    $output_assembly->XMLNSC->results->contents = ob_get_contents();
    ob_end_clean();
  }
}
上記の FilterIterator への入力として、以下のメッセージが使用されます。
<machine>
 <assembly name="Engine Block Top End">
  <assembly name="Cylinder Head">
   <assembly name="Tappet Assembly">
     <component name="Tappet" price="3.50" material="Toughened Steel"/>
     <component name="Coil String" price="1.50" material="Spring Steel"/>
     <component name="Circlip" price="1.50"  material="Spring Steel"/>
     <component name="Circlip" price="1.50"  material="Spring Steel"/>
     <component name="Seat" price="3.50" material="Toughened Steel"/>
   </assembly>
   <assembly name="Cam Shaft">
     <component name="Shaft" price="3.50" material="Mild Steel"/>
     <component name="Cam" price="1.50" material="Toughened Steel" />
     <component name="Cam" price="1.50" material="Toughened Steel" />
     <component name="Cam" price="1.50" material="Toughened Steel" />
     <component name="Cam" price="1.50" material="Toughened Steel" />
     <component name="Bearing" price="1.00" material="Toughened Steel" />
     <component name="Bearing" price="1.00" material="Toughened Steel" />
     <component name="Cam Chain Sprocket" price="4.20" material="Toughened Steel" />
     <component name="Cam Chain" price="4.20" material="Toughened Steel" />
     <component name="Tensioner" price="0.50" material="Plastic" />
   </assembly>
   <component name="Head" price="12.40" material="Alloy" />
   <component name="Plug" price="3.00"  material="Bakelite/Steel" />
  </assembly>
  <assembly name="Cylinder Block">
   <component name="Cylinder" price="20.00"  material="Alloy" />
   <component name="Sleeve" price="10.00"  material="Toughened Steel" />
  </assembly>
  <assembly name="Carburetor">
  <assembly name="Piston Assembly"/>
   <component name="Piston" price="20.00" material="Toughened Steel" />
   <component name="Ring" price="10.00" material="Spring Steel" />
   <component name="Ring" price="10.00"  material="Spring Steel" />
   <component name="Con Rod" price="10.00" material="Toughened Steel" />
  </assembly>
 </assembly>
</machine>
結果の出力には、材料が Toughened Steel の部品だけが示されます。
<results><contents>
Iterating Over parts which have a material name of Toughened Steel
component = Tappet 3.50 Toughened Steel
component = Seat 3.50 Toughened Steel
component = Cam 1.50 Toughened Steel
component = Cam 1.50 Toughened Steel
component = Cam 1.50 Toughened Steel
component = Cam 1.50 Toughened Steel
component = Bearing 1.00 Toughened Steel
component = Bearing 1.00 Toughened Steel
component = Cam Chain Sprocket 4.20 Toughened Steel
component = Cam Chain 4.20 Toughened Steel
component = Sleeve 10.00 Toughened Steel
component = Piston 20.00 Toughened Steel
component = Con Rod 10.00 Toughened Steel
</contents></results>

MbsElementIterator クラスについて詳しくは、MbsElementIteratorを参照してください。

特記事項 | 商標 | ダウンロード | ライブラリー | サポート | フィードバック

Copyright IBM Corporation 1999, 2014Copyright IBM Corporation 1999, 2014.

        
        最終更新:
        
        最終更新: 2015-02-28 17:48:40


概念トピック概念トピック | バージョン 8.0.0.5 | bc28330_