WebSphere Message Broker -JavaCompute元件的使用
IBM WebSphere Message Broker JavaCompute節點的使用.
import java.util.List;
import com.ibm.broker.javacompute.MbJavaComputeNode;
import com.ibm.broker.plugin.*;
public class Sub_FFN_JavaCompute extends MbJavaComputeNode {
private final ArticleCreator articleCreator;
private final StatementCreator statementCreator;
private final SaleListCreator saleListCreator;
public Sub_FFN_JavaCompute() throws MbException
{
// instantiate the output tree creation objects
saleListCreator = new SaleListCreator();
statementCreator = new StatementCreator();
articleCreator = new ArticleCreator();
}
public void evaluate(MbMessageAssembly inAssembly) throws MbException {
MbOutputTerminal out = getOutputTerminal("out");
MbOutputTerminal alt = getOutputTerminal("alternate");
MbMessage inMessage = inAssembly.getMessage();
// create new message
MbMessage outMessage = new MbMessage(inMessage);
MbMessageAssembly outAssembly = new MbMessageAssembly(inAssembly,
outMessage);
try {
MbElement root = outMessage.getRootElement();
MbElement document = root.getLastChild().getFirstChild();
MbElement chapter2 = document.createElementAsLastChild(MbElement.TYPE_NAME,"Chapter",null);
// add title attribute
MbElement title2 = chapter2.createElementAsFirstChild(MbElement.TYPE_NAME_VALUE,
"title", "Message Flows");
document.createElementAsLastChild(MbElement.TYPE_NAME,"NAME","ZhouHaiTao");
out.propagate(outAssembly);
} finally {
// clear the outMessage
outMessage.clearMessage();
}
}
//複製頭資訊到outMessage中;
public void copyMessageHeaders(MbMessage inMessage, MbMessage outMessage)
throws MbException
{
MbElement outRoot = outMessage.getRootElement();
// iterate though the headers starting with the first child of the root element
MbElement header = inMessage.getRootElement().getFirstChild();
while (header != null && header.getNextSibling() != null) // stop before the last child (body)
{
// copy the header and add it to the out message
outRoot.addAsLastChild(header.copy());
// move along to next header
header = header.getNextSibling();
}
}
/**
* Iterates over the incoming message's SaleList elements and builds the output
* message's SaleList
* 在入報文的遍歷SaleList元素並建立輸出訊息。
*
*/
private final class SaleListCreator extends XPathOperation
{
private SaleListCreator() throws MbException
{
super("/SaleEnvelope/SaleList"); // expression evaluated on the incoming message
}
/**
* Called once for each SaleList element
*/
@SuppressWarnings("unchecked")
protected void forEachElement(MbElement saleList) throws MbException
{
List <MbElement> nodeset = (List <MbElement>)getOutputElement().evaluateXPath("/?SaleEnvelope/?$SaleList");
MbElement outSaleList = nodeset.get(0);
// create the statements for each SaleList
statementCreator.setOutputElement(outSaleList);
statementCreator.evaluate(saleList);
}
}
private final class ArticleCreator extends XPathOperation {
private ArticleCreator() throws MbException
{
super("Item"); // expression evaluated on the incoming Invoice sub-tree
}
public ArticleCreator(String expression) throws MbException {
super(expression);
// TODO 自動生成的建構函式存根
}
//遍歷元素;
@Override
protected void forEachElement(MbElement element) throws MbException {
// TODO 自動生成的方法存根
}
}
/**
* Iterates over the incoming message's Invoice elements and builds the output
* message's Statement sub-tree
* 遍歷的發票在入報文元素並建立輸出;
*/
private final class StatementCreator extends XPathOperation
{
private final MbXPath setCustomer = new MbXPath(
"?$Statement[?@Type[set-value('Monthly')]]" +
" [?@Style[set-value('Full')]]" +
" [?Customer[?Initials[set-value(concat($invoice/Initial[1], $invoice/Initial[2]))]]" +
" [?Name[set-value($invoice/Surname)]]" +
" [?Balance[set-value($invoice/Balance)]]]" +
" /?Purchases");
private StatementCreator() throws MbException
{
super("Invoice"); // expression evaluated on the incoming SaleList sub-tree
}
/**
* Called once for each Invoice element
*/
@SuppressWarnings("unchecked")
protected void forEachElement(MbElement invoice) throws MbException
{
MbElement outSaleList = getOutputElement();
setCustomer.assignVariable("invoice", invoice);
List <MbElement> nodeset = (List <MbElement>)outSaleList.evaluateXPath(setCustomer);
MbElement purchases = nodeset.get(0);
// Now create the articles for each invoice
articleCreator.setOutputElement(purchases);
articleCreator.evaluate(invoice);
}
}
/**
* XPathOperation is an abstract helper class allowing a method to be repeatedly applied to
* results of an XPath expression. The user can optionally access the output message tree
* allowing message transformations to be defined based on XPath evaluations of the input
* tree.
* 是一種抽象的XPathOperation幫助類允許一個方法反覆應用到,
* 的節點。使用者可以選擇性地訪問輸出訊息樹,
* 許資訊轉換的被定義基於0評估輸入的樹
*/
abstract class XPathOperation
{
private MbXPath xpath = null;
private MbElement outputElement = null;
/**
* Constructor taking the XPath expression to evaluate. The expression must evaluate to
* a nodeset.
* 通過構造方法,expression 引數值生成一個xpath路徑;
*
*/
public XPathOperation(String expression) throws MbException
{
xpath = new MbXPath(expression);
}
/**
* Must be called prior to the evaluate method if the user wishes to work with the output
* tree (eg for message transformation).
*
*/
public void setOutputElement(MbElement out)
{
outputElement = out;
}
/**
* Allows the user to access the output tree in the forEachElement() method
*/
public MbElement getOutputElement()
{
return outputElement;
}
/**
* Can be overridden by the user to do initialisation processing before iterating over the
* XPath nodeset results
*/
protected void before() throws MbException { }
/**
* This gets called once for each element in the XPath nodeset results. The current element
* is passed in as the only argument. This method is abstract and must be implemented
* in the derived class.
* 這將被呼叫一次為每個元素在0 nodeset結果。當前元素,
* 通過是作為唯一的論點。該方法是抽象的,必須執行
* 在派生類。
*/
protected abstract void forEachElement(MbElement element) throws MbException;
/**
* Can be overridden by the user to do post-processing after iterating over the
* XPath nodeset results
*/
protected void after() throws MbException { }
/**
* Called by the user to iterate over the XPath nodeset.
*被稱為由使用者自行遍歷的nodeset 0。
* @param element The context element to which the XPath expression will be applied.
*/
@SuppressWarnings("unchecked")
public void evaluate(MbElement element) throws MbException
{
//根據xpath獲得一個結果;
Object result = element.evaluateXPath(xpath);
//如果result不是一個List例項;則return;
if(!(result instanceof List))
{
// error
return;
}
before();
//強制轉換成List<MbElement>List集合;
List<MbElement> nodeset = (List<MbElement>)result;
for(MbElement node : nodeset)
{
//迴圈遍歷node節點元素;
forEachElement(node);
}
after();
}
}
}
下面有一個文件,可以參考一下:
相關文章
- 使用 WebSphere Message Broker 的 WebSphere Transformation Extender 外掛WebORM
- WebSphere Message Broker HttpInput 節點WebHTTP
- 將WBE與WebSphere Message Broker 一起使用Web
- WebSphere Message Broker V6.1 中的新增功能Web
- WebSphere Message Broker 中使用者出口跟蹤訊息Web
- WebSphere Message Broker V7 上的影響分析Web
- ActiveMQ第三彈:在Spring中使用內建的Message BrokerMQSpring
- IBM Message Broker筆記系列(九)IBM筆記
- Oracle Data Guard Broker元件Oracle元件
- Labview 安裝 NI 軟體時出現 ni-systemlink-message-broker 錯誤View
- 使用Broker實現DG切換
- 關於element-ui 中使用Notice元件(Message、MessageBox、Notification)所遇到的坑UI元件
- MQTT 遺囑訊息(Will Message)的使用MQQT
- 使用WebSphere Integration Developer和WebSphere Process Server的二進位制Jar檔案WebDeveloperServerJAR
- RocketMQ系列:使用systemd管理nameserver和brokerMQServer
- DataGuard broker之一:DataGuard broker簡介
- jquery ui Message 簡單使用jQueryUI
- 從零實現Vue的元件庫(七)- Message-Box 實現Vue元件
- 使用DG_broker工具管理DG之switchover
- RocketMQ——Broker篇MQ
- WebSphere Service Registry and Repository 外掛的功能及使用Web
- 使用 WebSphere Portlet Factory 構建SOA 前端Web前端
- 使用c#操作IBM WebSphere MQC#IBMWebMQ
- Message(Message Pool)原始碼分析原始碼
- unity 3種message訊息管理使用Unity
- web技術分享| 基於vue3實現自己的元件庫,第一章:Message元件WebVue元件
- Data Guard Broker系列之二:Data Guard Broker配置實戰
- 使用Broker管理Data Guard——停用、改保護模式等模式
- oracle dataguard broker 配置Oracle
- Broker模組劃分
- 使用 WebSphere Business Modeler 實現業務流程的直接部署Web
- IBM Lotus Quickr services for IBM WebSphere Portal 8.0 中定製元件IBMUIWeb元件
- 怎樣使用程式碼得到bean:message 中的內容?Bean
- 使用 WebSphere Business Modeler 進行業務建模Web行業
- Animation元件的使用元件
- WebSphere CloudBurst 與 Rational Automation Framework for WebSphereWebCloudFramework
- Oracle DG Broker配置的管理週期Oracle
- dg broker配置的問題及分析