1 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 ; 23 import javax.management.ObjectName ; 24 25 public class JmsBootstrap implements Bootstrap { 26 27 protected InstallationContext context; 28 protected ObjectName mbeanName; 29 protected JmsConfiguration configuration; 30 31 public JmsBootstrap() { 32 configuration = new JmsConfiguration(); 33 } 34 35 public ObjectName getExtensionMBeanName() { 36 return mbeanName; 37 } 38 39 42 protected Object getExtensionMBean() throws Exception { 43 return configuration; 44 } 45 46 protected ObjectName createExtensionMBeanName() throws Exception { 47 return this.context.getContext().getMBeanNames().createCustomComponentMBeanName("bootstrap"); 48 } 49 50 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 e) { 60 throw new JBIException("Error calling init", e); 61 } 62 } 63 64 protected void doInit() throws Exception { 65 Object mbean = getExtensionMBean(); 66 if (mbean != null) { 67 this.mbeanName = createExtensionMBeanName(); 68 MBeanServer 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 82 public void cleanUp() throws JBIException { 83 try { 84 doCleanUp(); 85 } catch (JBIException e) { 86 throw e; 87 } catch (Exception e) { 88 throw new JBIException("Error calling cleanUp", e); 89 } 90 } 91 92 protected void doCleanUp() throws Exception { 93 if (this.mbeanName != null) { 94 MBeanServer 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 107 public void onInstall() throws JBIException { 108 try { 109 doOnInstall(); 110 } catch (JBIException e) { 111 throw e; 112 } catch (Exception e) { 113 throw new JBIException("Error calling onInstall", e); 114 } 115 } 116 117 protected void doOnInstall() throws Exception { 118 } 119 120 123 public void onUninstall() throws JBIException { 124 try { 125 doOnUninstall(); 126 } catch (JBIException e) { 127 throw e; 128 } catch (Exception e) { 129 throw new JBIException("Error calling onUninstall", e); 130 } 131 } 132 133 protected void doOnUninstall() throws Exception { 134 } 135 136 } 137 | Popular Tags |