KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > components > util > SpringBootstrap


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.components.util;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.apache.servicemix.jbi.NotInitialisedYetException;
22 import org.apache.servicemix.jbi.container.ActivationSpec;
23 import org.springframework.beans.BeansException;
24 import org.springframework.context.ApplicationContext;
25 import org.springframework.context.ApplicationContextAware;
26 import org.w3c.dom.DocumentFragment JavaDoc;
27
28 import javax.jbi.JBIException;
29 import javax.jbi.component.Bootstrap;
30 import javax.jbi.component.InstallationContext;
31 import javax.management.ObjectName JavaDoc;
32
33 import java.util.Iterator JavaDoc;
34 import java.util.Map JavaDoc;
35
36 /**
37  * A Spring implementation of the {@link Bootstrap}
38  *
39  * @version $Revision: 426415 $
40  */

41 public class SpringBootstrap implements Bootstrap, ApplicationContextAware {
42     private InstallationContext installContext;
43     private ObjectName JavaDoc extensionMBeanName;
44     private ApplicationContext applicationContext;
45     private static Log log = LogFactory.getLog(SpringBootstrap.class);
46     
47     public void init(InstallationContext installContext) throws JBIException {
48         this.installContext = installContext;
49     }
50
51     public void cleanUp() throws JBIException {
52     }
53
54     public ObjectName JavaDoc getExtensionMBeanName() {
55         return extensionMBeanName;
56     }
57
58     public void onInstall() throws JBIException {
59         if (installContext == null) {
60             throw new NotInitialisedYetException();
61         }
62         DocumentFragment JavaDoc fragment = installContext.getInstallationDescriptorExtension();
63         if (fragment != null) {
64             log.debug("Installation Descriptor Extension Found");
65         } else {
66             log.debug("Installation Descriptor Extension Not Found !");
67         }
68         // lets load this from Spring...
69
Map JavaDoc map = applicationContext.getBeansOfType(ActivationSpec.class, false, false);
70         for (Iterator JavaDoc iter = map.values().iterator(); iter.hasNext(); ) {
71             ActivationSpec spec = (ActivationSpec) iter.next();
72             log.debug("Registering "+spec.getComponentName());
73         }
74     }
75
76     public void onUninstall() throws JBIException {
77     }
78
79     public InstallationContext getInstallContext() {
80         return installContext;
81     }
82
83     public void setApplicationContext(ApplicationContext appCtx) throws BeansException {
84         this.applicationContext = appCtx;
85     }
86 }
87
Popular Tags