📄 copycontainerupes.java
字号:
/*BEGIN CMVC */
//*************************************************************************
//
// Workfile: mqwfupes/src/com/acme/sample/CopyContainerUpes.java, v3-upes, fmv3
// Last update: 04/01/28 11:48:54
// SCCS path, id: /home/flowmark/vc/0/5/5/7/s.99 1.2
//
//************************************************************************/
/*END CMVC */
/*BEGIN COPYRIGHT */
//*************************************************************************
//
// Licensed Materials - Property of IBM
// WA05 Support Pac - @sname@
// (c) Copyright IBM Corp. 2003
// US Government Users Restricted Rights - Use, duplication or
// disclosure restricted by GSA ADP Schedule Contract
// with IBM Corp.
//
//************************************************************************/
/*END COPYRIGHT */
/*BEGIN DISCLAIMER */
//*************************************************************************
// DISCLAIMER
// ----------
// This material contains programming source code for your consideration.
// These examples have not been thoroughly tested under all conditions.
// IBM, therefore, cannot guarantee or imply reliability, serviceability,
// or function of these programs.
// ALL PROGRAMS CONTAINED HEREIN ARE PROVIDED TO YOU "AS IS", WITHOUT ANY
// WARRANTIES (EXPRESS OR IMPLIED) OR SUPPORT WHATSOEVER, INCLUDING BUT
// NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS
// FOR A PARTICULAR PURPOSE.
//************************************************************************/
/*END DISCLAIMER */
package com.acme.sample;
import com.ibm.workflow.upes.BasicContainer;
import com.ibm.workflow.util.msg.BasicResponder;
import com.ibm.workflow.util.msg.Message;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
/**
* BasicUpes is the implementation of a simple standalone UPES. It can
* be launced via the main() method. The BasicTask class used by BasicUpes
* operates directly at the XML message level.
*/
public class CopyContainerUpes extends BasicResponder {
/**
* The BasicTask class used by BasicUpes. It will be instantiated as many
* times as the BasicResponder thread pool has threads.
* It deals with UPES messages directly. The onMessage() method skeleton
* needs to be completed to provide the intended semantics of the UPES.
*/
public class BasicTask extends Task {
/**
* A BasicTask does not convert messages to/from Java Beans but operates
* on the messages itself. The makeBean() method returns the
* <ProgramInputData> element of the message instead of converting the
* <programInputData> it to a Java Bean. Also, since a BasicUpes does not
* provide an FdlGenerator, the 'endpointParameter' map (which otherwise
* would contain the PARAMETER and ENVIRONMENT settings from the generated
* PROGRAM) will always be empty.
*/
protected Object makeBean(Element programInputData, Map endpointParameter) throws InvocationTargetException {
System.out.println("makeBean: " + programInputData.toString());
return programInputData.getParentNode();
}
/**
* The onMessage skeleton.
*/
public Object onMessage(Object inputData, Map endpointParameter, Message.IntHolder rc) throws Exception {
Element invoke = (Element) inputData; // The <ProgramInputData> element
NodeList invokeNodes = invoke.getChildNodes(); //Child nodes of <ProgramInputData>
String output = null; // The data for <ProgramOutputData>, already in WMQWF XML format
StringBuffer tempOutput = new StringBuffer(); //StringBuffer to get and append the elements of <ProgramInputData>
rc.value = 0; // The value for <ProgramRC>. To return a fatal <Exception>, throw an Exception instead
// retrieve the xml message
OutputFormat outputFormat = new OutputFormat();
outputFormat.setOmitXMLDeclaration(true); //Definition of XMLOutputFormat
XMLSerializer serializer = new XMLSerializer(outputFormat);
StringWriter writer = new StringWriter();
serializer.setOutputCharStream(writer);
serializer.asDOMSerializer();
// copy each node child of ProgramInputData into the output
for (int i=0; i<invokeNodes.getLength(); i++) {
if (invokeNodes.item(i).getNodeType()== Node.ELEMENT_NODE) {
serializer.serialize((Element)invokeNodes.item(i));
}
}
tempOutput.append(writer);
output=tempOutput.toString();
System.out.println("Container copied!");
return output;
}
}
/**
* This method returns the TaskFactory singleton which will create the
* BasicTask instances.
*/
public TaskFactory getTaskFactory() {
return taskFactory;
}
/**
* One way to run this UPES.
* Here, a BasicContainer (which reads its
* configuration from the file given in args[0]). Once the UPES has been
* created. The name of the configuration file has to be passed to
* (newly created) the BasicContainer; the container is then passed to the
* init() method of the UPES. This call will never return but launch the
* UPES instead.
*/
public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.out.println("USAGE: startUpes <properties.file>");
System.exit(1);
}
new CopyContainerUpes().init(new BasicContainer(args[0]));
}
// The TaskFactory singleton
private final TaskFactory taskFactory = new TaskFactory() {
public final Task createTask() throws InvocationTargetException {
return new BasicTask();
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -