1 17 package org.apache.servicemix.sca; 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 32 public class ScaBootstrap implements Bootstrap { 33 34 protected InstallationContext context; 35 protected ObjectName mbeanName; 36 37 public ScaBootstrap() { 38 } 39 40 public ObjectName getExtensionMBeanName() { 41 return mbeanName; 42 } 43 44 protected Object getExtensionMBean() throws Exception { 45 return null; 46 } 47 48 protected ObjectName createExtensionMBeanName() throws Exception { 49 return this.context.getContext().getMBeanNames().createCustomComponentMBeanName("bootstrap"); 50 } 51 52 55 public void init(InstallationContext installContext) throws JBIException { 56 try { 57 this.context = installContext; 58 doInit(); 59 } catch (JBIException e) { 60 throw e; 61 } catch (Exception e) { 62 throw new JBIException("Error calling init", e); 63 } 64 } 65 66 protected void doInit() throws Exception { 67 Object mbean = getExtensionMBean(); 68 if (mbean != null) { 69 this.mbeanName = createExtensionMBeanName(); 70 MBeanServer server = this.context.getContext().getMBeanServer(); 71 if (server == null) { 72 throw new JBIException("null mBeanServer"); 73 } 74 if (server.isRegistered(this.mbeanName)) { 75 server.unregisterMBean(this.mbeanName); 76 } 77 server.registerMBean(mbean, this.mbeanName); 78 } 79 } 80 81 84 public void cleanUp() throws JBIException { 85 try { 86 doCleanUp(); 87 } catch (JBIException e) { 88 throw e; 89 } catch (Exception e) { 90 throw new JBIException("Error calling cleanUp", e); 91 } 92 } 93 94 protected void doCleanUp() throws Exception { 95 if (this.mbeanName != null) { 96 MBeanServer server = this.context.getContext().getMBeanServer(); 97 if (server == null) { 98 throw new JBIException("null mBeanServer"); 99 } 100 if (server.isRegistered(this.mbeanName)) { 101 server.unregisterMBean(this.mbeanName); 102 } 103 } 104 } 105 106 109 public void onInstall() throws JBIException { 110 try { 111 doOnInstall(); 112 } catch (JBIException e) { 113 throw e; 114 } catch (Exception e) { 115 throw new JBIException("Error calling onInstall", e); 116 } 117 } 118 119 protected void doOnInstall() throws Exception { 120 } 121 122 125 public void onUninstall() throws JBIException { 126 try { 127 doOnUninstall(); 128 } catch (JBIException e) { 129 throw e; 130 } catch (Exception e) { 131 throw new JBIException("Error calling onUninstall", e); 132 } 133 } 134 135 protected void doOnUninstall() throws Exception { 136 } 137 138 } 139 | Popular Tags |