01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: private ClassLoader classLoader;
32:
33: /**
34: * @return Returns the kernel.
35: */
36: public Kernel getKernel() {
37: return kernel;
38: }
39:
40: /**
41: * @param kernel The kernel to set.
42: */
43: public void setKernel(Kernel kernel) {
44: this .kernel = kernel;
45: }
46:
47: public ServiceName getConfiguration() {
48: return configuration;
49: }
50:
51: public void setConfiguration(ServiceName configuration) {
52: this .configuration = configuration;
53: }
54:
55: /* (non-Javadoc)
56: * @see org.apache.servicemix.common.ServiceUnit#shutDown()
57: */
58: public void shutDown() throws JBIException {
59: super .shutDown();
60: classLoader = null;
61: if (kernel != null) {
62: kernel.destroy();
63: }
64: }
65:
66: public ClassLoader getConfigurationClassLoader() {
67: if (classLoader == null && kernel != null
68: && configuration != null) {
69: try {
70: ServiceFactory sf = kernel
71: .getServiceFactory(configuration);
72: classLoader = sf.getClassLoader();
73: } catch (ServiceNotFoundException e) {
74: // This should never happen
75: }
76: }
77: ClassLoader cl = classLoader;
78: if (cl == null) {
79: cl = Thread.currentThread().getContextClassLoader();
80: }
81: if (cl == null) {
82: cl = getClass().getClassLoader();
83: }
84: return cl;
85: }
86:
87: }
|