001: package com.bostech.corporation.component.x12splitter.processors;
002:
003: import java.util.LinkedList;
004: import java.util.List;
005:
006: import javax.jbi.component.ComponentContext;
007: import javax.jbi.messaging.DeliveryChannel;
008: import javax.jbi.messaging.InOnly;
009: import javax.jbi.messaging.MessageExchange;
010: import javax.jbi.messaging.MessageExchangeFactory;
011: import javax.jbi.messaging.NormalizedMessage;
012: import javax.jbi.servicedesc.ServiceEndpoint;
013: import javax.xml.namespace.QName;
014: import javax.xml.transform.Source;
015:
016: import org.apache.commons.logging.Log;
017: import org.apache.commons.logging.LogFactory;
018:
019: import com.bostech.corporation.component.x12splitter.X12SplitterEndpoint;
020: import com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.CbProviderProcessor;
021: import com.bostechcorp.cbesb.runtime.ccsl.nmhandler.NormalizedMessageHandler;
022: import com.bostechcorp.cbesb.runtime.ccsl.nmhandler.StringSource;
023:
024: public class X12SplitterProviderProcessor extends CbProviderProcessor {
025:
026: protected final transient Log logger = LogFactory
027: .getLog(getClass());
028:
029: protected ComponentContext context;
030: private X12SplitterEndpoint endpoint;
031: private MessageExchangeFactory messageExchangeFactory;
032: private DeliveryChannel channel;
033:
034: public X12SplitterProviderProcessor(X12SplitterEndpoint endpoint) {
035: super (endpoint);
036: this .endpoint = endpoint;
037: }
038:
039: public ComponentContext getContext() {
040: return context;
041: }
042:
043: public void setContext(ComponentContext context) {
044: this .context = context;
045: }
046:
047: public MessageExchangeFactory getMessageExchangeFactory() {
048: return messageExchangeFactory;
049: }
050:
051: public void setMessageExchangeFactory(
052: MessageExchangeFactory messageExchangeFactory) {
053: this .messageExchangeFactory = messageExchangeFactory;
054: }
055:
056: public DeliveryChannel getChannel() {
057: return channel;
058: }
059:
060: public void setChannel(DeliveryChannel channel) {
061: this .channel = channel;
062: }
063:
064: @Override
065: public void processInMessage(QName service, QName operation,
066: NormalizedMessage in, MessageExchange exchange)
067: throws Exception {
068:
069: NormalizedMessageHandler handlerIn = new NormalizedMessageHandler(
070: in);
071: List<String> contentList = new LinkedList<String>();
072: for (int i = 0; i < handlerIn.getRecordCount(); i++) {
073: Source src = handlerIn.getRecordAtIndex(i);
074: if (src instanceof StringSource) {
075: String x12Interchange = ((StringSource) src).getText();
076: contentList = X12SplitterUtil.splitX12(x12Interchange);
077: } else {
078: throw new Exception();
079: }
080: }
081:
082: if (contentList.size() > 0) {
083: for (int i = 0; i < contentList.size(); i++) {
084: InOnly newExchange = messageExchangeFactory
085: .createInOnlyExchange();
086: QName serviceNameQN = endpoint
087: .getDestinationServiceName();
088: String endpointName = endpoint
089: .getDestinationEndpointName();
090: ServiceEndpoint se = context.getEndpoint(serviceNameQN,
091: endpointName);
092: newExchange.setEndpoint(se);
093: String senderEndpointKey = newExchange.getEndpoint()
094: .getServiceName()
095: + ":"
096: + newExchange.getEndpoint().getEndpointName();
097: newExchange.setProperty(
098: "org.apache.servicemix.senderEndpoint",
099: senderEndpointKey);
100: logger.debug("senderEndpointKey is: "
101: + newExchange.getEndpoint().getServiceName()
102: + ":"
103: + newExchange.getEndpoint().getEndpointName());
104:
105: NormalizedMessage newInMsg = newExchange
106: .createMessage();
107:
108: NormalizedMessageHandler dataMessageHandler = new NormalizedMessageHandler(
109: newInMsg);
110: dataMessageHandler.addRecord(new StringSource(
111: contentList.get(i)));
112: newInMsg = dataMessageHandler.generateMessageContent();
113:
114: logger.debug("content is: " + contentList.get(i));
115: newExchange.setInMessage(newInMsg);
116:
117: channel.sendSync(newExchange);
118: }
119: }
120: }
121:
122: /*
123: * (non-Javadoc)
124: *
125: * @see com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.BaseProviderProcessor#processInOutMessage(javax.xml.namespace.QName,
126: * javax.xml.namespace.QName, javax.jbi.messaging.NormalizedMessage,
127: * javax.jbi.messaging.NormalizedMessage, boolean)
128: */
129: public boolean processInOutMessage(QName service, QName operation,
130: NormalizedMessage in, NormalizedMessage out,
131: boolean optionalOut, MessageExchange exchange)
132: throws Exception {
133:
134: return false;
135: }
136: }
|