[ dispatch icon ]

Dispatchers

The dispatcher is an element that has one input and many outputs. It can be used for broadcasting the input to several channels or to selectively separate some elements from others.

XML declaration

The dispatch element introduces the use of a dispatcher in a process body. Its structure is the following:

<dispatch type="type" id="id" in="channel" out="channels"> {<with-param>}* </dispatch>

Built-in dispatchers

Transmorpher provides a basic implementation of a dispatcher (broadcast), its behavior is to copy the input to the different outputs. It is used in the bibliography example for dispatching the input:

<dispatch type="broadcast" id="dispatch 2" in="R112" out="D1 D3"/> <dispatch type="broadcast" id="dispatchStripped" in="X1" out="X11 X12"/>

DispatchBasic
Figure: Basic dispatcher

Transmorpher provides an other implementation of a dispatcher (TestingDispatcher), its behavior is to send the input to the first ouput if test==value, to the other if test is test!=value:

<dispatch type="if" id="ifdispatch" in="IN" out="then else"> <with-param name="test">a<with-param> <with-param name="value">b<with-param> </dispatch>

References to contributed extensions can be found here

Manipulation API

Extension API

One can imagine more complex dispatchers. In the bibliography example, a dispatcher could split the reference elements into a regular list of references and the list of authors. This can be useful for generating a list of authors (sorted and uniq'ed) or an index. In the transformation of this paper from XML to HTML, we could have separated the graphic elements from the rest of this paper in order to transform the TIFF pictures into JPEG.

DispatchComplex
Figure: Complex dispatcher

Implementing new dispatchers can be achieved by extending the fr.fluxmedia.transmorpher.TProcessFactory.TDispatcher class. This class extends the org.xml.sax.ContentHandler interface which must be implemented in your class. This means that the SAX events arriving by the input channel must be handled by the new class.

Moreover, the class will have to communicate to the handlers that implements the output channels the SAX events that you want to send to them (at least, startDocument and endDocument). These content handlers are found in the contentHandlers variable (the content handler corresponding to output of rank i by contentHandlers[i]).

 [ merge icon ]

Mergers

The merger is a process that has several inputs and one output.

XML declaration

The merge element introduces the use of a merger in a process body. Its structure is the following:

<merge type="type" id="id" in="channels" out="channel"> {<with-param>}* </merge>

Built-in mergers

Transmorpher provides two simple built-in mergers. concat is a simple merger that copies all the 2..n channels under the root element of the first channel (preserving order). This merger is used in the bibliography example for merging two source XML documents:

<merge type="concat" id="merge" in="R1 R2" out="R3"/>

ConnectorBasic
Figure: Basic merger

A second merger, wrap wraps the tree corresponding of all its input channels under a wrapping tag which will be the root element of the output channel. It thus takes a tag parameter containing the name of this root element.

References to contributed extensions can be found here

Manipulation API

Extension API

One can imagine more complex mergers. For instance, in the bibliography example, one can define a merger which merges a channel of titles with a channel of authors to produce a channel of references.

ConnectorComplex
Figure: complex merger

New mergers must extend the fr.fluxmedia.transmorpher.TProcessFactory.TMerger class. This class must provide handlers for handling input channels and send resulting SAX events to the handler of the output channel. TO BE COMPLETED, THIS IS MORE COMPLICATED.

Next chapter: External processes


Feel free to comment to Jérôme:Euzenat#inrialpes:fr, $Id: dispatch.html,v 1.6 2005-10-25 13:34:00 euzenat Exp $