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.eip;
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 EIPBootstrap implements Bootstrap {
033:
034: protected InstallationContext context;
035: protected ObjectName mbeanName;
036:
037: public EIPBootstrap() {
038: }
039:
040: public ObjectName getExtensionMBeanName() {
041: return mbeanName;
042: }
043:
044: protected Object getExtensionMBean() throws Exception {
045: return null;
046: }
047:
048: protected ObjectName createExtensionMBeanName() throws Exception {
049: return this .context.getContext().getMBeanNames()
050: .createCustomComponentMBeanName("bootstrap");
051: }
052:
053: /* (non-Javadoc)
054: * @see javax.jbi.component.Bootstrap#init(javax.jbi.component.InstallationContext)
055: */
056: public void init(InstallationContext installContext)
057: throws JBIException {
058: try {
059: this .context = installContext;
060: doInit();
061: } catch (JBIException e) {
062: throw e;
063: } catch (Exception e) {
064: throw new JBIException("Error calling init", e);
065: }
066: }
067:
068: protected void doInit() throws Exception {
069: Object mbean = getExtensionMBean();
070: if (mbean != null) {
071: this .mbeanName = createExtensionMBeanName();
072: MBeanServer server = this .context.getContext()
073: .getMBeanServer();
074: if (server == null) {
075: throw new JBIException("null mBeanServer");
076: }
077: if (server.isRegistered(this .mbeanName)) {
078: server.unregisterMBean(this .mbeanName);
079: }
080: server.registerMBean(mbean, this .mbeanName);
081: }
082: }
083:
084: /* (non-Javadoc)
085: * @see javax.jbi.component.Bootstrap#cleanUp()
086: */
087: public void cleanUp() throws JBIException {
088: try {
089: doCleanUp();
090: } catch (JBIException e) {
091: throw e;
092: } catch (Exception e) {
093: throw new JBIException("Error calling cleanUp", e);
094: }
095: }
096:
097: protected void doCleanUp() throws Exception {
098: if (this .mbeanName != null) {
099: MBeanServer server = this .context.getContext()
100: .getMBeanServer();
101: if (server == null) {
102: throw new JBIException("null mBeanServer");
103: }
104: if (server.isRegistered(this .mbeanName)) {
105: server.unregisterMBean(this .mbeanName);
106: }
107: }
108: }
109:
110: /* (non-Javadoc)
111: * @see javax.jbi.component.Bootstrap#onInstall()
112: */
113: public void onInstall() throws JBIException {
114: try {
115: doOnInstall();
116: } catch (JBIException e) {
117: throw e;
118: } catch (Exception e) {
119: throw new JBIException("Error calling onInstall", e);
120: }
121: }
122:
123: protected void doOnInstall() throws Exception {
124: }
125:
126: /* (non-Javadoc)
127: * @see javax.jbi.component.Bootstrap#onUninstall()
128: */
129: public void onUninstall() throws JBIException {
130: try {
131: doOnUninstall();
132: } catch (JBIException e) {
133: throw e;
134: } catch (Exception e) {
135: throw new JBIException("Error calling onUninstall", e);
136: }
137: }
138:
139: protected void doOnUninstall() throws Exception {
140: }
141:
142: }
|