KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > bpe > BPEBootstrap


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.bpe;
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  *
31  * @author Guillaume Nodet
32  * @version $Revision: 369856 $
33  * @since 3.0
34  */

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

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

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

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

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