KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > common > xbean > AbstractXBeanServiceUnitAnalyzer


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.common.xbean;
18
19 import java.io.File JavaDoc;
20 import java.util.ArrayList JavaDoc;
21 import java.util.List JavaDoc;
22
23 import javax.jbi.messaging.MessageExchange;
24
25 import org.apache.servicemix.common.Endpoint;
26 import org.apache.servicemix.common.packaging.Provides;
27 import org.apache.servicemix.common.packaging.ServiceUnitAnalyzer;
28 import org.apache.xbean.spring.context.FileSystemXmlApplicationContext;
29
30 public abstract class AbstractXBeanServiceUnitAnalyzer implements
31         ServiceUnitAnalyzer {
32
33     List JavaDoc consumes = new ArrayList JavaDoc();
34
35     List JavaDoc provides = new ArrayList JavaDoc();
36
37     /*
38      * (non-Javadoc)
39      *
40      * @see org.apache.servicemix.common.packaging.ServiceUnitAnalyzer#getConsumes()
41      */

42     public List JavaDoc getConsumes() {
43         return consumes;
44     }
45
46     protected abstract List JavaDoc getConsumes(Endpoint endpoint);
47
48     /*
49      * (non-Javadoc)
50      *
51      * @see org.apache.servicemix.common.packaging.ServiceUnitAnalyzer#getProvides()
52      */

53     public List JavaDoc getProvides() {
54         return provides;
55     }
56
57     protected List JavaDoc getProvides(Endpoint endpoint) {
58         List JavaDoc providesList = new ArrayList JavaDoc();
59         if (endpoint.getRole().equals(MessageExchange.Role.PROVIDER)) {
60             Provides newProvide = new Provides();
61             newProvide.setEndpointName(endpoint.getEndpoint());
62             newProvide.setInterfaceName(endpoint.getInterfaceName());
63             newProvide.setServiceName(endpoint.getService());
64             providesList.add(newProvide);
65         }
66
67         return providesList;
68     }
69
70     protected abstract String JavaDoc getXBeanFile();
71
72     /*
73      * (non-Javadoc)
74      *
75      * @see org.apache.servicemix.common.packaging.ServiceUnitAnalyzer#init(java.io.File)
76      */

77     public void init(File JavaDoc explodedServiceUnitRoot) {
78         
79         FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(
80            "file:///" + explodedServiceUnitRoot.getAbsolutePath() + "/"
81                         + getXBeanFile());
82                 
83         for (int i = 0; i < context.getBeanDefinitionNames().length; i++) {
84             Object JavaDoc bean = context.getBean(context.getBeanDefinitionNames()[i]);
85             if (isValidEndpoint(bean)) {
86                 // The provides are generic while the consumes need to
87
// be handled by the implementation
88
Endpoint endpoint = (Endpoint) bean;
89                 provides.addAll(getProvides(endpoint));
90                 consumes.addAll(getConsumes(endpoint));
91             }
92         }
93     }
94
95     protected abstract boolean isValidEndpoint(Object JavaDoc bean);
96
97 }
98
Popular Tags