1 17 package org.apache.servicemix.lwcontainer; 18 19 import javax.jbi.component.ComponentContext; 20 import javax.jbi.messaging.MessageExchange.Role; 21 import javax.xml.namespace.QName ; 22 23 import org.apache.activemq.util.IdGenerator; 24 import org.apache.servicemix.common.Endpoint; 25 import org.apache.servicemix.common.ExchangeProcessor; 26 import org.apache.servicemix.jbi.container.ActivationSpec; 27 import org.apache.servicemix.jbi.container.JBIContainer; 28 import org.apache.servicemix.jbi.framework.ComponentContextImpl; 29 30 public class LwContainerEndpoint extends Endpoint { 31 32 private static final QName SERVICE_NAME = new QName ("http://lwcontainer.servicemix.org", "LwContainerComponent"); 33 34 private ActivationSpec activationSpec; 35 36 public LwContainerEndpoint(ActivationSpec activationSpec) { 37 this.activationSpec = activationSpec; 38 this.service = SERVICE_NAME; 39 if (activationSpec.getId() != null) { 40 this.endpoint = activationSpec.getId(); 41 } else if (activationSpec.getComponentName() != null) { 42 this.endpoint = activationSpec.getComponentName(); 43 } else { 44 this.endpoint = new IdGenerator().generateId(); 45 } 46 } 47 48 public Role getRole() { 49 throw new UnsupportedOperationException (); 50 } 51 52 public void activate() throws Exception { 53 getContainer().activateComponent(activationSpec); 54 55 } 56 57 public void deactivate() throws Exception { 58 getContainer().deactivateComponent(activationSpec.getId()); 59 } 60 61 public ExchangeProcessor getProcessor() { 62 throw new UnsupportedOperationException (); 63 } 64 65 public JBIContainer getContainer() { 66 ComponentContext context = getServiceUnit().getComponent().getComponentContext(); 67 if( context instanceof ComponentContextImpl ) { 68 return ((ComponentContextImpl) context).getContainer(); 69 } 70 throw new IllegalStateException ("LwContainer component can only be deployed in ServiceMix"); 71 } 72 73 } 74 | Popular Tags |