/**
*
*/
package net.fp.rp.workflow.flow.action;
import net.fp.rp.workflow.flow.state.FlowStateBean;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import net.fp.rp.common.exception.RpException;
import net.fp.rp.jms.ITestMessageSender;
import org.apache.log4j.Logger;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;
import org.springframework.beans.factory.BeanFactory;
/**
* Reads the required information from the Database
*
* This project uses Apache, Spring, JBoss and other GPL Licenced Code
*
* @author paul browne
*/
public class SendJMSActionHander extends AbstractActionHandler implements
ActionHandler {
// Serial ID
static final long serialVersionUID = 1;
/** Logger for this class and subclasses */
protected final Logger log = Logger.getLogger(getClass());
// These values will be set by JBPM
public String successTransitionName = null;
/**
* The Name of the Spring Bean under used to send JMS messages
*
*/
public static final String JMS_BEAN = "jmsSender";
/**
* Pass in the Execution Context, decide on which transition to leave the
* node by. jBPM expects the transition provided (
*
* @return String - name of the Transition to follow
*/
public void execute(ExecutionContext executionContext) {
log.debug("Enter SendJMSActionHander");
try {
// Carry out the processing
FlowStateBean flowBean = super
.getFlowBeanFromContext(executionContext);
// Convert to Text
//String xmlMessage = convertDocumentToString();
// Use the Spring Message bean to send the message
BeanFactory context = super.getSpringContext();
ITestMessageSender jmsSender = (ITestMessageSender) context .getBean(JMS_BEAN);
// Send messages
jmsSender.sendMessage("replace this");
// Update the context
super.setFlowBeanInContext(executionContext, flowBean);
// transition to the next node based on the decision
executionContext.leaveNode(successTransitionName);
} catch (Throwable t) {
// Log the exception , end the workflow
log.warn("Exception occured , ending workflow", t);
executionContext
.leaveNode(AbstractActionHandler.ERROR_TRANSITION_NAME);
}
log.debug("Exit SendJMSActionHander");
}
/**
* Convert to a string Doing it this way preserves the
* <?xml version="1.0" encoding="UTF-8"?>
*
* @param inDoc
* @return
*/
private String convertDocumentToString(String inDoc) throws IOException {
// Convert this to a string
ByteArrayOutputStream tmpStream = new ByteArrayOutputStream();
//inDoc.save(tmpStream);
return tmpStream.toString();
}
}