KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jms > JmsBootstrap


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.jms;
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 public class JmsBootstrap implements Bootstrap {
26
27     protected InstallationContext context;
28     protected ObjectName JavaDoc mbeanName;
29     protected JmsConfiguration configuration;
30     
31     public JmsBootstrap() {
32         configuration = new JmsConfiguration();
33     }
34     
35     public ObjectName JavaDoc getExtensionMBeanName() {
36         return mbeanName;
37     }
38
39     /* (non-Javadoc)
40      * @see org.apache.servicemix.common.BaseBootstrap#getExtensionMBean()
41      */

42     protected Object JavaDoc getExtensionMBean() throws Exception JavaDoc {
43         return configuration;
44     }
45
46     protected ObjectName JavaDoc createExtensionMBeanName() throws Exception JavaDoc {
47         return this.context.getContext().getMBeanNames().createCustomComponentMBeanName("bootstrap");
48     }
49
50     /* (non-Javadoc)
51      * @see javax.jbi.component.Bootstrap#init(javax.jbi.component.InstallationContext)
52      */

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

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

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

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