Java™ および MbMessageCollection クラスを使用してメッセージ・コレクションを作成できます。 メッセージ・コレクションを使用すると便利なのは、構文解析のためにメッセージをグループ化する必要がある場合や、特定のデータ構造 (CICS® Transaction Server for z/OS® チャネル・データ構造など) を表すためにメッセージ・コレクションを作成しなければならない場合です。
メッセージ・コレクションは、Properties ヘッダーと、Collection という 1 つのドメイン・エレメントで構成されるメッセージです。
Collection フォルダーには多数の子メッセージが含まれていて、それぞれには Properties フォルダーを 1 つと、多数のヘッダー (MQMD など)、および本体を入れることができます。 また、メッセージ・コレクションには、0 個以上の属性 (名前と値のペア) を指定できます。 属性名は、メッセージ・コレクションで固有でなければなりません。 メッセージ・コレクションの標準属性は、CollectionName と呼ばれる属性です。
以下の図は、メッセージ・コレクション構造の例を示しています。
構文解析用にメッセージをグループ化するためのメッセージ・コレクションを Java および MbMessageCollection クラスで作成すること、または特定のデータ構造 (CICS チャネル・データ構造など) を表すために構成する必要のあるメッセージ・コレクションを作成することができます。
Java を使用してメッセージ・コレクションを構成するには、以下の手順を実行します。
- 以下の例を使用して、新規メッセージを作成します。
// create new message
MbMessageCollection outMessage = new MbMessageCollection();
MbMessageAssembly outAssembly = new MbMessageAssembly(inAssembly,
outMessage);
- 次の例を使用して、コレクションの Properties フォルダーを作成します。
// create top level Properties folder and data
MbElement omroot = outMessage.getRootElement();
MbElement properties = omroot.createElementAsFirstChild("Properties");
MbElement property1 = properties.createElementAsLastChild(
MbElement.TYPE_NAME_VALUE, "myProperty1", "propertyData1");
MbElement property2 = properties.createElementAsLastChild(
MbElement.TYPE_NAME_VALUE, "myProperty2", "propertyData2");
- 以下の例を使用して、名前/値のペアを作成します。
// create collection attributes (name/value pairs)
MbElement cn = outMessage.createNameValue("CollectionName", "myCollectionName");
MbElement nv1 = outMessage.createNameValue("NAME1", "Value1");
MbElement nv2 = outMessage.createNameValue("NAME2", 12345);
メッセージ・フォルダーと同様、ドメイン・エレメントは必ずメッセージ・プロパティーの最後の子になります。
- 次の例は、コレクション内にメッセージを作成する手順を示しています。 ステップ 1 から 3 は繰り返します。
public void evaluate(MbMessageAssembly inAssembly) throws MbException {
MbOutputTerminal out = getOutputTerminal("out");
// create new message
MbMessageCollection outMessage = new MbMessageCollection();
MbMessageAssembly outAssembly = new MbMessageAssembly(inAssembly,
outMessage);
// create top level Properties folder and data
MbElement omroot = outMessage.getRootElement();
MbElement properties = omroot.createElementAsFirstChild("Properties");
MbElement property1 = properties.createElementAsLastChild(
MbElement.TYPE_NAME_VALUE, "myProperty1", "propertyData1");
MbElement property2 = properties.createElementAsLastChild(
MbElement.TYPE_NAME_VALUE, "myProperty2", "propertyData2");
// create collection attributes (name/value pairs)
MbElement cn = outMessage.createNameValue("CollectionName", "myCollectionName");
MbElement nv1 = outMessage.createNameValue("NAME1", "Value1");
MbElement nv2 = outMessage.createNameValue("NAME2", 12345);
// create folder 1
MbElement folder1 = outMessage.createFolder("folder1");
// create properties for folder 1
MbElement folder1properties = folder1.createElementAsFirstChild("Properties");
MbElement folder1property1 = folder1properties.createElementAsLastChild(
MbElement.TYPE_NAME_VALUE, "myFolder1Property1", "folder1propertyData1");
MbElement folder1property2 = folder1properties.createElementAsLastChild(
MbElement.TYPE_NAME_VALUE, "myFolder1Property2", "folder1propertyData2");
// create body of folder 1
MbElement mrm = folder1.createElementAsLastChild("MRM");
// create message domain element of folder 1
MbElement msg = mrm.createElementAsLastChild(MbElement.TYPE_NAME,
"msg", null);
// create data within the message body for folder 1
MbElement data = msg.createElementAsLastChild(
MbElement.TYPE_NAME_VALUE, "data", "myData");
// create folder 2
MbElement folder2 = outMessage.createFolder("Folder2");
// create properties for folder 2
MbElement folder2properties = folder2.createElementAsFirstChild("Properties");
MbElement folder2property1 = folder2properties.createElementAsLastChild(
MbElement.TYPE_NAME_VALUE, "myFolder2Property1", "folder2propertyData1");
MbElement folder2property2 = folder2properties.createElementAsLastChild(
MbElement.TYPE_NAME_VALUE, "myFolder2Property2", "folder2propertyData2");
// create body of folder 2
MbElement xmlnsc = folder2.createElementAsLastChild("XMLNSC");
// create message domain element of folder 2
MbElement msg2 = xmlnsc.createElementAsLastChild(
MbElement.TYPE_NAME, "msg2", null);
// create data within the message body for folder 2
MbElement data2 = msg2.createElementAsLastChild(
MbElement.TYPE_NAME_VALUE, "myData2", "myXMLData");
try {
out.propagate(outAssembly);
} finally {
// clear the outMessage even if there's an exception
outMessage.clearMessage();
}
}