KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > http > HttpBootstrap


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.http;
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: 436741 $
30  * @since 3.0
31  */

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

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

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

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

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