KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > common > BaseBootstrap


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;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21
22 import javax.jbi.JBIException;
23 import javax.jbi.component.Bootstrap;
24 import javax.jbi.component.InstallationContext;
25 import javax.management.MBeanServer JavaDoc;
26 import javax.management.ObjectName JavaDoc;
27
28 /**
29  * Base class for components bootstrap.
30  * Due to classloading mechanism in JBI, Shared Libraries are
31  * not available at bootstrap time, so this class should be
32  * copied in your own component and modified directly, instead
33  * of inheriting it.
34  *
35  * @author Guillaume Nodet
36  * @version $Revision: 434069 $
37  * @deprecated
38  * @since 3.0
39  */

40 public class BaseBootstrap implements Bootstrap {
41
42     protected final transient Log logger = LogFactory.getLog(getClass());
43     
44     protected InstallationContext context;
45     protected ObjectName JavaDoc mbeanName;
46     
47     public BaseBootstrap() {
48     }
49     
50     public ObjectName JavaDoc getExtensionMBeanName() {
51         return mbeanName;
52     }
53
54     protected Object JavaDoc getExtensionMBean() throws Exception JavaDoc {
55         return null;
56     }
57     
58     protected ObjectName JavaDoc createExtensionMBeanName() throws Exception JavaDoc {
59         return this.context.getContext().getMBeanNames().createCustomComponentMBeanName("bootstrap");
60     }
61
62     /* (non-Javadoc)
63      * @see javax.jbi.component.Bootstrap#init(javax.jbi.component.InstallationContext)
64      */

65     public void init(InstallationContext installContext) throws JBIException {
66         try {
67             if (logger.isDebugEnabled()) {
68                 logger.debug("Initializing bootstrap");
69             }
70             this.context = installContext;
71             doInit();
72             if (logger.isDebugEnabled()) {
73                 logger.debug("Bootstrap initialized");
74             }
75         } catch (JBIException e) {
76             throw e;
77         } catch (Exception JavaDoc e) {
78             throw new JBIException("Error calling init", e);
79         }
80     }
81
82     protected void doInit() throws Exception JavaDoc {
83         Object JavaDoc mbean = getExtensionMBean();
84         if (mbean != null) {
85             this.mbeanName = createExtensionMBeanName();
86             MBeanServer JavaDoc server = this.context.getContext().getMBeanServer();
87             if (server == null) {
88                 throw new JBIException("null mBeanServer");
89             }
90             if (server.isRegistered(this.mbeanName)) {
91                 server.unregisterMBean(this.mbeanName);
92             }
93             server.registerMBean(mbean, this.mbeanName);
94         }
95     }
96     
97     /* (non-Javadoc)
98      * @see javax.jbi.component.Bootstrap#cleanUp()
99      */

100     public void cleanUp() throws JBIException {
101         try {
102             if (logger.isDebugEnabled()) {
103                 logger.debug("Cleaning up bootstrap");
104             }
105             doCleanUp();
106             if (logger.isDebugEnabled()) {
107                 logger.debug("Bootstrap cleaned up");
108             }
109         } catch (JBIException e) {
110             throw e;
111         } catch (Exception JavaDoc e) {
112             throw new JBIException("Error calling cleanUp", e);
113         }
114     }
115
116     protected void doCleanUp() throws Exception JavaDoc {
117         if (this.mbeanName != null) {
118             MBeanServer JavaDoc server = this.context.getContext().getMBeanServer();
119             if (server == null) {
120                 throw new JBIException("null mBeanServer");
121             }
122             if (server.isRegistered(this.mbeanName)) {
123                 server.unregisterMBean(this.mbeanName);
124             }
125         }
126     }
127
128     /* (non-Javadoc)
129      * @see javax.jbi.component.Bootstrap#onInstall()
130      */

131     public void onInstall() throws JBIException {
132         try {
133             if (logger.isDebugEnabled()) {
134                 logger.debug("Bootstrap onInstall");
135             }
136             doOnInstall();
137             if (logger.isDebugEnabled()) {
138                 logger.debug("Bootstrap onInstall done");
139             }
140         } catch (JBIException e) {
141             throw e;
142         } catch (Exception JavaDoc e) {
143             throw new JBIException("Error calling onInstall", e);
144         }
145     }
146
147     protected void doOnInstall() throws Exception JavaDoc {
148     }
149     
150     /* (non-Javadoc)
151      * @see javax.jbi.component.Bootstrap#onUninstall()
152      */

153     public void onUninstall() throws JBIException {
154         try {
155             if (logger.isDebugEnabled()) {
156                 logger.debug("Bootstrap onUninstall");
157             }
158             doOnUninstall();
159             if (logger.isDebugEnabled()) {
160                 logger.debug("Bootstrap onUninstall done");
161             }
162         } catch (JBIException e) {
163             throw e;
164         } catch (Exception JavaDoc e) {
165             throw new JBIException("Error calling onUninstall", e);
166         }
167     }
168
169     protected void doOnUninstall() throws Exception JavaDoc {
170     }
171     
172 }
173
Popular Tags