001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.servicemix.eip.packaging;
018:
019: import java.util.ArrayList;
020: import java.util.List;
021:
022: import org.apache.servicemix.common.Endpoint;
023: import org.apache.servicemix.common.packaging.Consumes;
024: import org.apache.servicemix.common.xbean.AbstractXBeanServiceUnitAnalyzer;
025: import org.apache.servicemix.eip.EIPEndpoint;
026: import org.apache.servicemix.eip.patterns.ContentBasedRouter;
027: import org.apache.servicemix.eip.patterns.MessageFilter;
028: import org.apache.servicemix.eip.patterns.Pipeline;
029: import org.apache.servicemix.eip.patterns.SplitAggregator;
030: import org.apache.servicemix.eip.patterns.StaticRecipientList;
031: import org.apache.servicemix.eip.patterns.StaticRoutingSlip;
032: import org.apache.servicemix.eip.patterns.WireTap;
033: import org.apache.servicemix.eip.patterns.XPathSplitter;
034: import org.apache.servicemix.eip.support.ExchangeTarget;
035: import org.apache.servicemix.eip.support.RoutingRule;
036:
037: public class EipServiceUnitAnalyzer extends
038: AbstractXBeanServiceUnitAnalyzer {
039:
040: protected List<Consumes> getConsumes(Endpoint endpoint) {
041: List<Consumes> consumes;
042: if (endpoint instanceof ContentBasedRouter) {
043: consumes = resolveContentBasedRouter((ContentBasedRouter) endpoint);
044: } else if (endpoint instanceof MessageFilter) {
045: consumes = resolveMessageFilter((MessageFilter) endpoint);
046: } else if (endpoint instanceof Pipeline) {
047: consumes = resolvePipeline((Pipeline) endpoint);
048: } else if (endpoint instanceof SplitAggregator) {
049: consumes = resolveSplitAggregator((SplitAggregator) endpoint);
050: } else if (endpoint instanceof StaticRecipientList) {
051: consumes = resolveStaticRecipientList((StaticRecipientList) endpoint);
052: } else if (endpoint instanceof StaticRoutingSlip) {
053: consumes = resolveStaticRoutingSlip((StaticRoutingSlip) endpoint);
054: } else if (endpoint instanceof WireTap) {
055: consumes = resolveWireTap((WireTap) endpoint);
056: } else if (endpoint instanceof XPathSplitter) {
057: consumes = resolveXPathSplitter((XPathSplitter) endpoint);
058: } else {
059: consumes = new ArrayList<Consumes>();
060: }
061: return consumes;
062: }
063:
064: private List<Consumes> resolveXPathSplitter(XPathSplitter splitter) {
065: return generateConsumesFromTarget(splitter.getTarget(),
066: new ArrayList<Consumes>());
067: }
068:
069: private List<Consumes> resolveWireTap(WireTap tap) {
070: List<Consumes> consumes = new ArrayList<Consumes>();
071: consumes = generateConsumesFromTarget(tap.getTarget(), consumes);
072: consumes = generateConsumesFromTarget(tap.getInListener(),
073: consumes);
074: consumes = generateConsumesFromTarget(tap.getOutListener(),
075: consumes);
076: consumes = generateConsumesFromTarget(tap.getFaultListener(),
077: consumes);
078: return consumes;
079: }
080:
081: private List<Consumes> resolveStaticRoutingSlip(
082: StaticRoutingSlip slip) {
083: List<Consumes> consumes = new ArrayList<Consumes>();
084: for (int i = 0; i < slip.getTargets().length; i++) {
085: consumes = generateConsumesFromTarget(slip.getTargets()[i],
086: consumes);
087: }
088: return consumes;
089: }
090:
091: private List<Consumes> resolveStaticRecipientList(
092: StaticRecipientList list) {
093: List<Consumes> consumes = new ArrayList<Consumes>();
094: for (int i = 0; i < list.getRecipients().length; i++) {
095: consumes = generateConsumesFromTarget(
096: list.getRecipients()[i], consumes);
097: }
098: return consumes;
099: }
100:
101: private List<Consumes> resolveSplitAggregator(
102: SplitAggregator aggregator) {
103: return generateConsumesFromTarget(aggregator.getTarget(),
104: new ArrayList<Consumes>());
105: }
106:
107: private List<Consumes> resolvePipeline(Pipeline pipeline) {
108: List<Consumes> consumes = generateConsumesFromTarget(pipeline
109: .getTarget(), new ArrayList<Consumes>());
110: consumes = generateConsumesFromTarget(
111: pipeline.getTransformer(), consumes);
112: return consumes;
113: }
114:
115: private List<Consumes> resolveMessageFilter(MessageFilter filter) {
116: return generateConsumesFromTarget(filter.getTarget(),
117: new ArrayList<Consumes>());
118: }
119:
120: private List<Consumes> resolveContentBasedRouter(
121: ContentBasedRouter router) {
122: List<Consumes> consumes = new ArrayList<Consumes>();
123: for (int i = 0; i < router.getRules().length; i++) {
124: RoutingRule rule = router.getRules()[i];
125: consumes = generateConsumesFromTarget(rule.getTarget(),
126: consumes);
127: }
128: return consumes;
129: }
130:
131: private List<Consumes> generateConsumesFromTarget(
132: ExchangeTarget target, List<Consumes> consumes) {
133: if (target != null) {
134: Consumes consume = new Consumes();
135: consume.setEndpointName(target.getEndpoint());
136: consume.setServiceName(target.getService());
137: consume.setInterfaceName(target.getInterface());
138: consumes.add(consume);
139: }
140: return consumes;
141: }
142:
143: protected String getXBeanFile() {
144: return "xbean.xml";
145: }
146:
147: protected boolean isValidEndpoint(Object bean) {
148: return bean instanceof EIPEndpoint;
149: }
150:
151: }
|