KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.servicemix.common.ServiceUnit;
20 import org.apache.xbean.kernel.Kernel;
21 import org.apache.xbean.kernel.ServiceFactory;
22 import org.apache.xbean.kernel.ServiceName;
23 import org.apache.xbean.kernel.ServiceNotFoundException;
24
25 import javax.jbi.JBIException;
26
27 public class XBeanServiceUnit extends ServiceUnit {
28
29     private Kernel kernel;
30     private ServiceName configuration;
31
32     /**
33      * @return Returns the kernel.
34      */

35     public Kernel getKernel() {
36         return kernel;
37     }
38
39     /**
40      * @param kernel The kernel to set.
41      */

42     public void setKernel(Kernel kernel) {
43         this.kernel = kernel;
44     }
45
46     public ServiceName getConfiguration() {
47         return configuration;
48     }
49
50     public void setConfiguration(ServiceName configuration) {
51         this.configuration = configuration;
52     }
53     
54     /* (non-Javadoc)
55      * @see org.apache.servicemix.common.ServiceUnit#shutDown()
56      */

57     public void shutDown() throws JBIException {
58         super.shutDown();
59         if (kernel != null) {
60             kernel.destroy();
61         }
62     }
63     
64     public ClassLoader JavaDoc getConfigurationClassLoader() throws ServiceNotFoundException {
65         ClassLoader JavaDoc cl = null;
66         if (kernel != null) {
67             ServiceFactory sf = kernel.getServiceFactory(configuration);
68             cl = sf.getClassLoader();
69         }
70         if (cl == null) {
71             cl = Thread.currentThread().getContextClassLoader();
72         }
73         if (cl == null) {
74             cl = getClass().getClassLoader();
75         }
76         return cl;
77     }
78     
79 }
80
Popular Tags