001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.servicemix.wsn.component;
018:
019: import javax.jbi.JBIException;
020: import javax.jbi.component.Bootstrap;
021: import javax.jbi.component.InstallationContext;
022: import javax.management.MBeanServer;
023: import javax.management.ObjectName;
024:
025: /**
026: * Base class for components bootstrap.
027: *
028: * @author Guillaume Nodet
029: * @version $Revision: 369856 $
030: * @since 3.0
031: */
032: public class WSNBootstrap implements Bootstrap {
033:
034: protected InstallationContext context;
035:
036: protected ObjectName mbeanName;
037:
038: public WSNBootstrap() {
039: }
040:
041: public ObjectName getExtensionMBeanName() {
042: return mbeanName;
043: }
044:
045: protected Object getExtensionMBean() throws Exception {
046: return null;
047: }
048:
049: protected ObjectName createExtensionMBeanName() throws Exception {
050: return this .context.getContext().getMBeanNames()
051: .createCustomComponentMBeanName("bootstrap");
052: }
053:
054: /* (non-Javadoc)
055: * @see javax.jbi.component.Bootstrap#init(javax.jbi.component.InstallationContext)
056: */
057: public void init(InstallationContext installContext)
058: throws JBIException {
059: try {
060: this .context = installContext;
061: doInit();
062: } catch (JBIException e) {
063: throw e;
064: } catch (Exception e) {
065: throw new JBIException("Error calling init", e);
066: }
067: }
068:
069: protected void doInit() throws Exception {
070: Object mbean = getExtensionMBean();
071: if (mbean != null) {
072: this .mbeanName = createExtensionMBeanName();
073: MBeanServer server = this .context.getContext()
074: .getMBeanServer();
075: if (server == null) {
076: throw new JBIException("null mBeanServer");
077: }
078: if (server.isRegistered(this .mbeanName)) {
079: server.unregisterMBean(this .mbeanName);
080: }
081: server.registerMBean(mbean, this .mbeanName);
082: }
083: }
084:
085: /* (non-Javadoc)
086: * @see javax.jbi.component.Bootstrap#cleanUp()
087: */
088: public void cleanUp() throws JBIException {
089: try {
090: doCleanUp();
091: } catch (JBIException e) {
092: throw e;
093: } catch (Exception e) {
094: throw new JBIException("Error calling cleanUp", e);
095: }
096: }
097:
098: protected void doCleanUp() throws Exception {
099: if (this .mbeanName != null) {
100: MBeanServer server = this .context.getContext()
101: .getMBeanServer();
102: if (server == null) {
103: throw new JBIException("null mBeanServer");
104: }
105: if (server.isRegistered(this .mbeanName)) {
106: server.unregisterMBean(this .mbeanName);
107: }
108: }
109: }
110:
111: /* (non-Javadoc)
112: * @see javax.jbi.component.Bootstrap#onInstall()
113: */
114: public void onInstall() throws JBIException {
115: try {
116: doOnInstall();
117: } catch (JBIException e) {
118: throw e;
119: } catch (Exception e) {
120: throw new JBIException("Error calling onInstall", e);
121: }
122: }
123:
124: protected void doOnInstall() throws Exception {
125: }
126:
127: /* (non-Javadoc)
128: * @see javax.jbi.component.Bootstrap#onUninstall()
129: */
130: public void onUninstall() throws JBIException {
131: try {
132: doOnUninstall();
133: } catch (JBIException e) {
134: throw e;
135: } catch (Exception e) {
136: throw new JBIException("Error calling onUninstall", e);
137: }
138: }
139:
140: protected void doOnUninstall() throws Exception {
141: }
142:
143: }
|