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.bpmscript.jbi.tasklist;
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: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027:
028: /**
029: * Bootstrap class. This class is usefull to perform tasks at installation /
030: * uninstallation time
031: */
032: public class TaskListBootstrap implements Bootstrap {
033:
034: protected final transient Log logger = LogFactory
035: .getLog(getClass());
036:
037: protected InstallationContext context;
038:
039: protected ObjectName mbeanName;
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: /*
055: * (non-Javadoc)
056: *
057: * @see javax.jbi.component.Bootstrap#init(javax.jbi.component.InstallationContext)
058: */
059: public void init(InstallationContext installContext)
060: throws JBIException {
061: try {
062: if (logger.isDebugEnabled()) {
063: logger.debug("Initializing bootstrap");
064: }
065: this .context = installContext;
066: doInit();
067: if (logger.isDebugEnabled()) {
068: logger.debug("Bootstrap initialized");
069: }
070: } catch (JBIException e) {
071: throw e;
072: } catch (Exception e) {
073: throw new JBIException("Error calling init", e);
074: }
075: }
076:
077: protected void doInit() throws Exception {
078: Object mbean = getExtensionMBean();
079: if (mbean != null) {
080: this .mbeanName = createExtensionMBeanName();
081: MBeanServer server = this .context.getContext()
082: .getMBeanServer();
083: if (server == null) {
084: throw new JBIException("null mBeanServer");
085: }
086: if (server.isRegistered(this .mbeanName)) {
087: server.unregisterMBean(this .mbeanName);
088: }
089: server.registerMBean(mbean, this .mbeanName);
090: }
091: }
092:
093: /*
094: * (non-Javadoc)
095: *
096: * @see javax.jbi.component.Bootstrap#cleanUp()
097: */
098: public void cleanUp() throws JBIException {
099: try {
100: if (logger.isDebugEnabled()) {
101: logger.debug("Cleaning up bootstrap");
102: }
103: doCleanUp();
104: if (logger.isDebugEnabled()) {
105: logger.debug("Bootstrap cleaned up");
106: }
107: } catch (JBIException e) {
108: throw e;
109: } catch (Exception e) {
110: throw new JBIException("Error calling cleanUp", e);
111: }
112: }
113:
114: protected void doCleanUp() throws Exception {
115: if (this .mbeanName != null) {
116: MBeanServer server = this .context.getContext()
117: .getMBeanServer();
118: if (server == null) {
119: throw new JBIException("null mBeanServer");
120: }
121: if (server.isRegistered(this .mbeanName)) {
122: server.unregisterMBean(this .mbeanName);
123: }
124: }
125: }
126:
127: /*
128: * (non-Javadoc)
129: *
130: * @see javax.jbi.component.Bootstrap#onInstall()
131: */
132: public void onInstall() throws JBIException {
133: try {
134: if (logger.isDebugEnabled()) {
135: logger.debug("Bootstrap onInstall");
136: }
137: doOnInstall();
138: if (logger.isDebugEnabled()) {
139: logger.debug("Bootstrap onInstall done");
140: }
141: } catch (JBIException e) {
142: throw e;
143: } catch (Exception e) {
144: throw new JBIException("Error calling onInstall", e);
145: }
146: }
147:
148: protected void doOnInstall() throws Exception {
149: }
150:
151: /*
152: * (non-Javadoc)
153: *
154: * @see javax.jbi.component.Bootstrap#onUninstall()
155: */
156: public void onUninstall() throws JBIException {
157: try {
158: if (logger.isDebugEnabled()) {
159: logger.debug("Bootstrap onUninstall");
160: }
161: doOnUninstall();
162: if (logger.isDebugEnabled()) {
163: logger.debug("Bootstrap onUninstall done");
164: }
165: } catch (JBIException e) {
166: throw e;
167: } catch (Exception e) {
168: throw new JBIException("Error calling onUninstall", e);
169: }
170: }
171:
172: protected void doOnUninstall() throws Exception {
173: }
174:
175: }
|