KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > eip > EIPBootstrap


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.eip;
18
19 import javax.jbi.JBIException;
20 import javax.jbi.component.Bootstrap;
21 import javax.jbi.component.InstallationContext;
22 import javax.management.MBeanServer JavaDoc;
23 import javax.management.ObjectName JavaDoc;
24
25 /**
26  * Base class for components bootstrap.
27  *
28  * @author Guillaume Nodet
29  * @version $Revision: 369856 $
30  * @since 3.0
31  */

32 public class EIPBootstrap implements Bootstrap {
33
34     protected InstallationContext context;
35     protected ObjectName JavaDoc mbeanName;
36     
37     public EIPBootstrap() {
38     }
39     
40     public ObjectName JavaDoc getExtensionMBeanName() {
41         return mbeanName;
42     }
43
44     protected Object JavaDoc getExtensionMBean() throws Exception JavaDoc {
45         return null;
46     }
47     
48     protected ObjectName JavaDoc createExtensionMBeanName() throws Exception JavaDoc {
49         return this.context.getContext().getMBeanNames().createCustomComponentMBeanName("bootstrap");
50     }
51
52     /* (non-Javadoc)
53      * @see javax.jbi.component.Bootstrap#init(javax.jbi.component.InstallationContext)
54      */

55     public void init(InstallationContext installContext) throws JBIException {
56         try {
57             this.context = installContext;
58             doInit();
59         } catch (JBIException e) {
60             throw e;
61         } catch (Exception JavaDoc e) {
62             throw new JBIException("Error calling init", e);
63         }
64     }
65
66     protected void doInit() throws Exception JavaDoc {
67         Object JavaDoc mbean = getExtensionMBean();
68         if (mbean != null) {
69             this.mbeanName = createExtensionMBeanName();
70             MBeanServer JavaDoc server = this.context.getContext().getMBeanServer();
71             if (server == null) {
72                 throw new JBIException("null mBeanServer");
73             }
74             if (server.isRegistered(this.mbeanName)) {
75                 server.unregisterMBean(this.mbeanName);
76             }
77             server.registerMBean(mbean, this.mbeanName);
78         }
79     }
80     
81     /* (non-Javadoc)
82      * @see javax.jbi.component.Bootstrap#cleanUp()
83      */

84     public void cleanUp() throws JBIException {
85         try {
86             doCleanUp();
87         } catch (JBIException e) {
88             throw e;
89         } catch (Exception JavaDoc e) {
90             throw new JBIException("Error calling cleanUp", e);
91         }
92     }
93
94     protected void doCleanUp() throws Exception JavaDoc {
95         if (this.mbeanName != null) {
96             MBeanServer JavaDoc server = this.context.getContext().getMBeanServer();
97             if (server == null) {
98                 throw new JBIException("null mBeanServer");
99             }
100             if (server.isRegistered(this.mbeanName)) {
101                 server.unregisterMBean(this.mbeanName);
102             }
103         }
104     }
105
106     /* (non-Javadoc)
107      * @see javax.jbi.component.Bootstrap#onInstall()
108      */

109     public void onInstall() throws JBIException {
110         try {
111             doOnInstall();
112         } catch (JBIException e) {
113             throw e;
114         } catch (Exception JavaDoc e) {
115             throw new JBIException("Error calling onInstall", e);
116         }
117     }
118
119     protected void doOnInstall() throws Exception JavaDoc {
120     }
121     
122     /* (non-Javadoc)
123      * @see javax.jbi.component.Bootstrap#onUninstall()
124      */

125     public void onUninstall() throws JBIException {
126         try {
127             doOnUninstall();
128         } catch (JBIException e) {
129             throw e;
130         } catch (Exception JavaDoc e) {
131             throw new JBIException("Error calling onUninstall", e);
132         }
133     }
134
135     protected void doOnUninstall() throws Exception JavaDoc {
136     }
137     
138 }
139
Popular Tags