1 17 package org.apache.servicemix.eip.packaging; 18 19 import java.util.ArrayList ; 20 import java.util.List ; 21 22 import org.apache.servicemix.common.Endpoint; 23 import org.apache.servicemix.common.packaging.Consumes; 24 import org.apache.servicemix.common.xbean.AbstractXBeanServiceUnitAnalyzer; 25 import org.apache.servicemix.eip.EIPEndpoint; 26 import org.apache.servicemix.eip.patterns.ContentBasedRouter; 27 import org.apache.servicemix.eip.patterns.MessageFilter; 28 import org.apache.servicemix.eip.patterns.Pipeline; 29 import org.apache.servicemix.eip.patterns.SplitAggregator; 30 import org.apache.servicemix.eip.patterns.StaticRecipientList; 31 import org.apache.servicemix.eip.patterns.StaticRoutingSlip; 32 import org.apache.servicemix.eip.patterns.WireTap; 33 import org.apache.servicemix.eip.patterns.XPathSplitter; 34 import org.apache.servicemix.eip.support.ExchangeTarget; 35 import org.apache.servicemix.eip.support.RoutingRule; 36 37 public class EipServiceUnitAnalyzer extends AbstractXBeanServiceUnitAnalyzer { 38 39 protected List getConsumes(Endpoint endpoint) { 40 if (endpoint instanceof ContentBasedRouter) 41 return resolveContentBasedRouter((ContentBasedRouter) endpoint); 42 if (endpoint instanceof MessageFilter) 43 return resolveMessageFilter((MessageFilter) endpoint); 44 if (endpoint instanceof Pipeline) 45 return resolvePipeline((Pipeline) endpoint); 46 if (endpoint instanceof SplitAggregator) 47 return resolveSplitAggregator((SplitAggregator) endpoint); 48 if (endpoint instanceof StaticRecipientList) 49 return resolveStaticRecipientList((StaticRecipientList) endpoint); 50 if (endpoint instanceof StaticRoutingSlip) 51 return resolveStaticRoutingSlip((StaticRoutingSlip) endpoint); 52 if (endpoint instanceof WireTap) 53 return resolveWireTap((WireTap) endpoint); 54 if (endpoint instanceof XPathSplitter) 55 return resolveXPathSplitter((XPathSplitter) endpoint); 56 return new ArrayList (); 57 } 58 59 private List resolveXPathSplitter(XPathSplitter splitter) { 60 return generateConsumesFromTarget(splitter.getTarget(), new ArrayList ()); 61 } 62 63 private List resolveWireTap(WireTap tap) { 64 List consumes = new ArrayList (); 65 consumes = generateConsumesFromTarget(tap.getTarget(), consumes); 66 consumes = generateConsumesFromTarget(tap.getInListener(), consumes); 67 consumes = generateConsumesFromTarget(tap.getOutListener(), consumes); 68 consumes = generateConsumesFromTarget(tap.getFaultListener(), consumes); 69 return consumes; 70 } 71 72 private List resolveStaticRoutingSlip(StaticRoutingSlip slip) { 73 List consumes = new ArrayList (); 74 for (int i = 0; i < slip.getTargets().length; i++) { 75 consumes = generateConsumesFromTarget(slip.getTargets()[i], 76 consumes); 77 } 78 return consumes; 79 } 80 81 private List resolveStaticRecipientList(StaticRecipientList list) { 82 List consumes = new ArrayList (); 83 for (int i = 0; i < list.getRecipients().length; i++) { 84 consumes = generateConsumesFromTarget(list.getRecipients()[i], 85 consumes); 86 } 87 return consumes; 88 } 89 90 private List resolveSplitAggregator(SplitAggregator aggregator) { 91 return generateConsumesFromTarget(aggregator.getTarget(), 92 new ArrayList ()); 93 } 94 95 private List resolvePipeline(Pipeline pipeline) { 96 List consumes = generateConsumesFromTarget(pipeline.getTarget(), new ArrayList ()); 97 consumes = generateConsumesFromTarget(pipeline.getTransformer(), consumes); 98 return consumes; 99 } 100 101 private List resolveMessageFilter(MessageFilter filter) { 102 return generateConsumesFromTarget(filter.getTarget(), new ArrayList ()); 103 } 104 105 private List resolveContentBasedRouter(ContentBasedRouter router) { 106 List consumes = new ArrayList (); 107 for (int i = 0; i < router.getRules().length; i++) { 108 RoutingRule rule = router.getRules()[i]; 109 consumes = generateConsumesFromTarget(rule.getTarget(), consumes); 110 } 111 return consumes; 112 } 113 114 private List generateConsumesFromTarget(ExchangeTarget target, List consumes) { 115 if (target != null) { 116 Consumes consume = new Consumes(); 117 consume.setEndpointName(target.getEndpoint()); 118 consume.setServiceName(target.getService()); 119 consume.setInterfaceName(target.getInterface()); 120 consumes.add(consume); 121 } 122 return consumes; 123 } 124 125 protected String getXBeanFile() { 126 return "xbean.xml"; 127 } 128 129 protected boolean isValidEndpoint(Object bean) { 130 return (bean instanceof EIPEndpoint); 131 } 132 133 } 134 | Popular Tags |