1 10 11 package org.mule.routing.outbound; 12 13 import java.util.Iterator ; 14 15 import org.mule.config.i18n.Message; 16 import org.mule.umo.UMOException; 17 import org.mule.umo.UMOMessage; 18 import org.mule.umo.UMOSession; 19 import org.mule.umo.endpoint.UMOEndpoint; 20 import org.mule.umo.routing.CouldNotRouteOutboundMessageException; 21 import org.mule.umo.routing.RoutingException; 22 23 39 public class EndpointSelector extends FilteringOutboundRouter 40 { 41 private String selectorProperty = "endpoint"; 42 43 public UMOMessage route(UMOMessage message, UMOSession session, boolean synchronous) 44 throws RoutingException 45 { 46 String endpointName = message.getStringProperty(getSelectorProperty(), null); 47 if (endpointName == null) 48 { 49 throw new IllegalArgumentException ("selectorProperty '" + getSelectorProperty() 50 + "' must be set on message in order to route it."); 51 } 52 53 UMOEndpoint ep = lookupEndpoint(endpointName); 54 if (ep == null) 55 { 56 throw new CouldNotRouteOutboundMessageException( 57 Message.createStaticMessage("No endpoint found with the name " + endpointName), message, ep); 58 } 59 60 try 61 { 62 if (synchronous) 63 { 64 return send(session, message, ep); 65 } 66 else 67 { 68 dispatch(session, message, ep); 69 return null; 70 } 71 } 72 catch (UMOException e) 73 { 74 throw new CouldNotRouteOutboundMessageException(message, ep, e); 75 } 76 } 77 78 protected UMOEndpoint lookupEndpoint(String endpointName) 79 { 80 UMOEndpoint ep; 81 Iterator iterator = endpoints.iterator(); 82 while (iterator.hasNext()) 83 { 84 ep = (UMOEndpoint)iterator.next(); 85 if (endpointName.equals(ep.getName())) 86 { 87 return ep; 88 } 89 else if (endpointName.equals(ep.getEndpointURI().getAddress())) 90 { 91 return ep; 92 } 93 } 94 return null; 95 } 96 97 public String getSelectorProperty() 98 { 99 return selectorProperty; 100 } 101 102 public void setSelectorProperty(String selectorProperty) 103 { 104 this.selectorProperty = selectorProperty; 105 } 106 } 107 | Popular Tags |