1 17 package org.apache.servicemix.jbi.nmr.flow; 18 19 import javax.jbi.messaging.MessageExchange; 20 import javax.jbi.messaging.MessagingException; 21 22 import org.apache.servicemix.JbiConstants; 23 import org.apache.servicemix.jbi.messaging.MessageExchangeImpl; 24 25 public class DefaultFlowChooser implements FlowChooser { 26 27 public DefaultFlowChooser() { 28 } 29 30 public Flow chooseFlow(Flow[] flows, MessageExchange exchange) throws MessagingException { 31 String flow = (String ) exchange.getProperty(JbiConstants.FLOW_PROPERTY_NAME); 33 if (flow != null) { 34 Flow foundFlow = null; 35 for (int i = 0; i < flows.length; i++) { 36 if (flows[i].getName().equalsIgnoreCase(flow)) { 37 foundFlow = flows[i]; 38 break; 39 } 40 } 41 if (foundFlow == null) { 42 throw new MessagingException("Flow '" + flow + "' was specified but not found"); 43 } if (foundFlow.canHandle(exchange)) { 44 return foundFlow; 45 } else { 46 throw new MessagingException("Flow '" + flow + "' was specified but not able to handle exchange"); 47 } 48 } 49 for (int i = 0; i < flows.length; i++) { 51 if (flows[i].canHandle(exchange)) { 52 ((MessageExchangeImpl) exchange).getPacket().setProperty(JbiConstants.FLOW_PROPERTY_NAME, flows[i].getName()); 53 return flows[i]; 54 } 55 } 56 return null; 57 } 58 59 } 60 | Popular Tags |