001: package com.bostechcorp.cbesb.custom;
002:
003: import java.util.LinkedList;
004: import java.util.Map;
005: import java.util.Set;
006:
007: import javax.jbi.JBIException;
008: import javax.jbi.component.ComponentContext;
009: import javax.jbi.messaging.DeliveryChannel;
010: import javax.jbi.messaging.MessageExchange;
011: import javax.jbi.messaging.NormalizedMessage;
012:
013: import org.apache.commons.logging.Log;
014:
015: import com.bostechcorp.cbesb.runtime.ccsl.lib.DumpNormalizedMessage;
016: import com.bostechcorp.cbesb.runtime.ccsl.lib.IScriptObject;
017: import com.bostechcorp.cbesb.runtime.ccsl.nmhandler.NormalizedMessageHandler;
018:
019: public class BounceBack implements IScriptObject {
020:
021: /**
022: * The run method is called when an exchange is sent to the endpoint.
023: *
024: * @param logger - the loggger object
025: * @param rootDir - the root direcory of the SU
026: * @param componentContext - the componentContext object
027: * @param channel - the delivery channel object
028: * @param exchange - the MessageExchange object passed in
029: * @param params - the user paramaters in name/value pair
030: * @throws Exception
031: */
032:
033: public void run(Log logger, String rootDir,
034: ComponentContext componentContext, DeliveryChannel channel,
035: MessageExchange exchange, Map<String, String> params)
036: throws Exception {
037:
038: NormalizedMessage m;
039: if ((m = exchange.getMessage("in")) != null) {
040: boolean isNewOutMessage = false;
041: NormalizedMessage mOut = exchange.getMessage("out");
042: if (mOut == null) {
043: mOut = exchange.createMessage();
044: isNewOutMessage = true;
045: }
046: NormalizedMessageHandler dest = new NormalizedMessageHandler(
047: mOut);
048: NormalizedMessageHandler source = new NormalizedMessageHandler(
049: m);
050: for (int i = 0; i < source.getRecordCount(); i++)
051: dest.addRecord(source.getRecordAtIndex(i));
052: Set<String> propertyNames = m.getPropertyNames();
053: for (String propertyName : propertyNames) {
054: mOut.setProperty(propertyName, m
055: .getProperty(propertyName));
056: }
057: dest.generateMessageContent();
058: if (isNewOutMessage)
059: exchange.setMessage(mOut, "out");
060: }
061: }
062:
063: /**
064: * Start mode can be used for initialization. Consumer endpoints
065: * that do not use timed mode should set up a thread to generate
066: * exchanges in start mode.
067: *
068: * @param logger - the loggger object
069: * @param rootDir - the root direcory of the SU
070: * @param componentContext - the componentContext object
071: * @param channel - the delivery channel object
072: * @param exchange - the MessageExchange object passed in
073: * @param params - the user paramaters in name/value pair
074: * @throws Exception
075: */
076:
077: public void start(Log logger, String rootDir,
078: ComponentContext componentContext, DeliveryChannel channel,
079: Map<String, String> params) throws Exception {
080:
081: // nothing to do for startup
082:
083: }
084:
085: /**
086: * The stop method should clean up resources
087: *
088: * @param logger - the loggger object
089: * @param rootDir - the root direcory of the SU
090: * @param componentContext - the componentContext object
091: * @param channel - the delivery channel object
092: * @param params - the user paramaters in name/value pair
093: * @throws Exception
094: */
095: public void stop(Log logger, String rootDir,
096: ComponentContext componentContext, DeliveryChannel channel,
097: Map<String, String> params) throws Exception {
098:
099: // nothing to do for stop
100: }
101:
102: /**
103: * The time method is called for a timed mode consumer endpoint.
104: * It returns a linked list of exchanges to be sent from the
105: * endpoint.
106: *
107: * @param logger - the loggger object
108: * @param rootDir - the root direcory of the SU
109: * @param componentContext - the componentContext object
110: * @param channel - the delivery channel object
111: * @param exchange - the MessageExchange object passed in
112: * @param params - the user paramaters in name/value pair
113: * @return - the LinkList containning one of many MessageExchange objects
114: * @throws Exception
115: */
116: public LinkedList time(Log logger, String rootDir,
117: ComponentContext componentContext, DeliveryChannel channel,
118: MessageExchange exchange, Map<String, String> params)
119: throws Exception {
120:
121: // This component cannot run as a consumer so throw an exception
122: JBIException e = new JBIException(
123: "cannot run Echo component in time mode");
124: throw e;
125: }
126: }
|