WebSphere Message Broker Version 8.0.0.5 Betriebssysteme: AIX, HP-Itanium, Linux, Solaris, Windows, z/OS

Sehen Sie sich die Informationen zur aktuellen Produktversion im IBM Integration Bus Version 9.0 an.

Mit einem Filter iterieren

Mit einem FilterIterator können Sie die Elemente einer Nachrichtenbaumstruktur filtern.

Das folgende Beispiel zeigt, wie Sie mit einem FilterIterator über eine Nachrichtenbaumstruktur iterieren, um nur die Toughened Steel-Komponenten zu extrahieren:
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();
  }
}
Folgende Nachricht wird als Eingabe für den oben gezeigten FilterIterator verwendet:
<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>
In der Ausgabe werden nur Komponenten mit dem Material Toughened Steel (gehärteter Stahl) zurückgegeben:
<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>

Weitere Informationen zur MbsElementIterator-Klasse finden Sie im Abschnitt MbsElementIterator.

Bemerkungen | Marken | Downloads | Bibliothek | Support | Feedback

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

        
        Letzte Aktualisierung:
        
        Letzte Aktualisierung: 2015-02-28 16:22:34


KonzeptthemaKonzeptthema | Version 8.0.0.5 | bc28330_