import com.ibm.broker.javacompute.MbJavaComputeNode;
import com.ibm.broker.plugin.*;
public class JavaComputeNodeMsgFlow_JavaCompute extends MbJavaComputeNode {
public void evaluate(MbMessageAssembly inAssembly) throws MbException {
MbOutputTerminal out = getOutputTerminal("out");
MbOutputTerminal alt = getOutputTerminal("alternate");
//Declaration of Variables
String Ename = null,Location = null,Batch = null,Company = null;
MbMessage inMessage = inAssembly.getMessage();
// create new message
MbMessage outMessage = new MbMessage(inMessage);
MbMessageAssembly outAssembly = new MbMessageAssembly(inAssembly,
outMessage);
//-------- INPUT PARSING ------------
MbElement InRoot = inMessage.getRootElement(); // MESSAGE
MbElement InXmlNsc = InRoot.getLastChild(); // XMLNSC
MbElement InDetails = InXmlNsc.getLastChild(); //<DETAILS></DETAILS>
//creating MbElement array to store all employee details
MbElement Emp[] = InDetails.getAllElementsByPath("*"); // <EMP></EMP>
// ------- CREATING STRUCTURE FOR OUTPUT PARSING --------------
MbElement OutRoot = outMessage.getRootElement(); // MESSAGE
MbElement OutXmlNsc = OutRoot.getLastChild(); // XMLNSC
MbElement OutDetails = OutXmlNsc.createElementAsFirstChild(MbElement.TYPE_NAME,"EMP_DETAILS",null); //<EMP_DETAILS></EMP_DETAILS>
//-- This Line used when you have Single <EMP></EMP> Record---
//MbElement OutEmp = OutDetails.createElementAsFirstChild(MbElement.TYPE_NAME,"EMP",null);
//<EMP></EMP>
//Extracting child elements from <EMP>
for(int i=0;i<Emp.length;i++){
//-- This Line used when you have Multiple <EMP></EMP> Record---
MbElement OutEmp = OutDetails.createElementAsFirstChild(MbElement.TYPE_NAME,"EMP",null);
//<EMP></EMP>
Ename = Emp[i].getFirstChild().getValueAsString();
Location = Emp[i].getFirstChild().getNextSibling().getValueAsString();
Batch = Emp[i].getFirstChild().getNextSibling().getNextSibling().getValueAsString();
Company = Emp[i].getLastChild().getValueAsString();
//Create Values inside Multiple <EMP></EMP> Record ,OutEmp
OutEmp.createElementAsFirstChild(MbElement.TYPE_NAME_VALUE,"ENAME",Ename);
OutEmp.createElementAsLastChild(MbElement.TYPE_NAME_VALUE,"LOCATION",Location);
OutEmp.createElementAsLastChild(MbElement.TYPE_NAME_VALUE,"BATCH",Batch);
OutEmp.createElementAsLastChild(MbElement.TYPE_NAME_VALUE,"COMPANY",Company);
} // End Of For Loop
//Create Values inside Single <EMP></EMP> Record ,OutEmp
//OutEmp.createElementAsFirstChild(MbElement.TYPE_NAME_VALUE,"ENAME",Ename);
//OutEmp.createElementAsLastChild(MbElement.TYPE_NAME_VALUE,"LOCATION",Location);
//OutEmp.createElementAsLastChild(MbElement.TYPE_NAME_VALUE,"BATCH",Batch);
//OutEmp.createElementAsLastChild(MbElement.TYPE_NAME_VALUE,"COMPANY",Company);
//detach XMLNSC last child because outMessage is created from inMessage and already contains InMessage Structure.
OutXmlNsc.getLastChild().detach();
//Finally Propogate the Output to OutAssembly
out.propagate(outAssembly);
//clear the output message
outMessage.clearMessage();
}
}
|
No comments:
Post a Comment