1 17 package org.apache.servicemix.components.util; 18 19 import org.springframework.beans.factory.DisposableBean; 20 21 import javax.jbi.JBIException; 22 import javax.jbi.component.ComponentContext; 23 import javax.jbi.component.ComponentLifeCycle; 24 import javax.management.ObjectName ; 25 import javax.xml.namespace.QName ; 26 27 32 public class PojoLifecycleAdaptor implements ComponentLifeCycle { 33 34 private Object pojo; 35 private QName service; 36 private String endpoint; 37 private ComponentContext context; 38 private ObjectName extensionMBeanName; 39 40 public PojoLifecycleAdaptor(Object pojo, QName service, String endpoint) { 41 this.pojo = pojo; 42 this.service = service; 43 this.endpoint = endpoint; 44 } 45 46 public ObjectName getExtensionMBeanName() { 47 return extensionMBeanName; 48 } 49 50 public void init(ComponentContext context) throws JBIException { 51 this.context = context; 52 if (service != null && endpoint != null) { 53 context.activateEndpoint(service, endpoint); 54 } 55 } 56 57 58 public void shutDown() throws JBIException { 59 if (pojo instanceof DisposableBean) { 60 DisposableBean disposableBean = (DisposableBean) pojo; 61 try { 62 disposableBean.destroy(); 63 } 64 catch (Exception e) { 65 throw new JBIException(e); 66 } 67 } 68 } 69 70 public void start() throws JBIException { 71 } 72 73 public void stop() throws JBIException { 74 } 75 76 public Object getPojo() { 79 return pojo; 80 } 81 82 public void setExtensionMBeanName(ObjectName extensionMBeanName) { 83 this.extensionMBeanName = extensionMBeanName; 84 } 85 86 public ComponentContext getContext() { 87 return context; 88 } 89 } 90 | Popular Tags |