KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > eip > packaging > EipServiceUnitAnalyzer


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.eip.packaging;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.List JavaDoc;
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 JavaDoc 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 JavaDoc();
57     }
58
59     private List JavaDoc resolveXPathSplitter(XPathSplitter splitter) {
60         return generateConsumesFromTarget(splitter.getTarget(), new ArrayList JavaDoc());
61     }
62
63     private List JavaDoc resolveWireTap(WireTap tap) {
64         List JavaDoc consumes = new ArrayList JavaDoc();
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 JavaDoc resolveStaticRoutingSlip(StaticRoutingSlip slip) {
73         List JavaDoc consumes = new ArrayList JavaDoc();
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 JavaDoc resolveStaticRecipientList(StaticRecipientList list) {
82         List JavaDoc consumes = new ArrayList JavaDoc();
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 JavaDoc resolveSplitAggregator(SplitAggregator aggregator) {
91         return generateConsumesFromTarget(aggregator.getTarget(),
92                 new ArrayList JavaDoc());
93     }
94
95     private List JavaDoc resolvePipeline(Pipeline pipeline) {
96         List JavaDoc consumes = generateConsumesFromTarget(pipeline.getTarget(), new ArrayList JavaDoc());
97         consumes = generateConsumesFromTarget(pipeline.getTransformer(), consumes);
98         return consumes;
99     }
100
101     private List JavaDoc resolveMessageFilter(MessageFilter filter) {
102         return generateConsumesFromTarget(filter.getTarget(), new ArrayList JavaDoc());
103     }
104
105     private List JavaDoc resolveContentBasedRouter(ContentBasedRouter router) {
106         List JavaDoc consumes = new ArrayList JavaDoc();
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 JavaDoc generateConsumesFromTarget(ExchangeTarget target, List JavaDoc 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 JavaDoc getXBeanFile() {
126         return "xbean.xml";
127     }
128
129     protected boolean isValidEndpoint(Object JavaDoc bean) {
130         return (bean instanceof EIPEndpoint);
131     }
132
133 }
134
Popular Tags