Here is the hands-on developing a message translator Infopipe, which is a kind of the simplest Infopipe in the ISG+IRT/JIM system environment, to show how to use the ISG+IRT/JIM system. Actually, the message translator Infopipe can easily be implemented to change a string text "Hello!" in the messaging stream to a Japanese greeting word, "Kon Nichi Wa!" (in alphabetical representation.)
Figure 7: Hands-on Developing the Message Translator Infopipe
The XML representation of the Infopipe Spec for the Message Translator Infopipe should be as follow:
<?xml version="1.0"?> <!DOCTYPE InfopipeSpec SYSTEM "InfopipeSpec.dtd"> <InfopipeSpec id="TextConverter"> <Method id="convert" match="body"> <InoutArgs id="Inout"> <Arg type="text" id="body">text()</Arg> </InoutArgs> </Method> </InfopipeSpec>
Please note that the Infopipe is named as TextConverter in the above example.
Use ISG to generate three Java files, TextConverter.java, TextConverterException.java and TextConverterStub.java.
/** * This file is generated by InfopipeStubGenerator, * and supposes to be used as a template for your infopipe-middle * * @version $Id: demo2.html,v 1.1 2000/09/20 18:45:01 morimori Exp $ */ import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class TextConverter { /** * inout arguments for convert() */ public class Inout { public String body; } /** * method convert */ public void convert(Inout inout) throws TextConverterException { } }
/** * This file is generated by InfopipeStubGenerator, * and supposes to be used as a template for your infopipe-middle * * @version $Id: demo2.html,v 1.1 2000/09/20 18:45:01 morimori Exp $ */ public class TextConverterException extends Exception { TextConverterException(String msg) { super("TextConverterException: " + msg); } }
/** * Do NOT edit this file that is generated by InfopipeStubGenerator, * and supposes to be used as a wrapper code for your infopipe-middle * * @version $Id: demo2.html,v 1.1 2000/09/20 18:45:01 morimori Exp $ */ ... public class TextConverterStub implements InfopipeStub { ... public void call() throws TextConverterException { ... document = parser.getDocument(); Node root = document.getDocumentElement(); Node node = null; NodeList nl = null; try { nl = XPathAPI.selectNodeList(root, "body"); TextConverter.Inout textConverter_Inout = textConverter.new Inout(); for (int i = 0; i < nl.getLength(); i ++) { node = XPathAPI.selectSingleNode(nl.item(i), "text()"); if (node != null) { if (node.getNodeType() == Node.TEXT_NODE) { textConverter_Inout.body = node.getNodeValue(); } else if (node.getNodeType() == Node.ATTRIBUTE_NODE) { textConverter_Inout.body = ((Attr)node).getValue(); } else { throw new TextConverterException("this node type cannot be treated..."); } } textConverter.convert(textConverter_Inout); ...
Add just a couple of lines as follow:
/** * This file is generated by InfopipeStubGenerator, * and supposes to be used as a template for your infopipe-middle * * @version $Id: demo2.html,v 1.1 2000/09/20 18:45:01 morimori Exp $ */ import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class TextConverter { /** * inout arguments for convert() */ public class Inout { public String body; } /** * method convert */ public void convert(Inout inout) throws TextConverterException { if (inout.body.equals("Hello!")) { inout.body = new String("Kon Nichi Wa!"); } } }
Please note that the only three lines which are illustrated in bold are the added code.
Just use javac to build the three java files. These four steps are the all things the infopipe developers need to do before they execute the infopipe.
Just use the IRT to execute the Infopipe with the name of the Infopipe "TextConverter" as an argument; the IRT instantiates the stub and middle method dynamically at the booting time to make the Message Translator Infopipe to be ready for transferring a message "Hello!" to "Kon Nichi Wa!"
You will see the result as follow:
Figure 8: A message "Hello!" has been sent to another client as "Kon Nichi Wa!" via the Infopipe