1 17 package org.apache.servicemix.wsn.spring; 18 19 import javax.jms.ConnectionFactory ; 20 21 import org.apache.servicemix.common.BaseComponent; 22 import org.apache.servicemix.common.BaseLifeCycle; 23 import org.apache.servicemix.common.Endpoint; 24 import org.apache.servicemix.common.ServiceUnit; 25 import org.apache.servicemix.wsn.component.WSNDeployer; 26 import org.apache.servicemix.wsn.component.WSNLifeCycle; 27 import org.springframework.core.io.Resource; 28 29 36 public class WSNSpringComponent extends BaseComponent { 37 38 private Resource[] resources; 39 40 private Object [] requests; 41 42 45 public Resource[] getResources() { 46 return resources; 47 } 48 49 52 public void setResources(Resource[] endpoints) { 53 this.resources = endpoints; 54 } 55 56 59 public Object [] getRequests() { 60 return requests; 61 } 62 63 66 public void setRequests(Object [] requests) { 67 this.requests = requests; 68 } 69 70 73 public ConnectionFactory getConnectionFactory() { 74 return ((WSNLifeCycle) lifeCycle).getConnectionFactory(); 75 } 76 77 80 public void setConnectionFactory(ConnectionFactory connectionFactory) { 81 ((WSNLifeCycle) lifeCycle).setConnectionFactory(connectionFactory); 82 } 83 84 87 protected BaseLifeCycle createLifeCycle() { 88 return new LifeCycle(); 89 } 90 91 public class LifeCycle extends WSNLifeCycle { 92 93 protected ServiceUnit su; 94 95 public LifeCycle() { 96 super(WSNSpringComponent.this); 97 } 98 99 102 protected void doInit() throws Exception { 103 super.doInit(); 104 su = new ServiceUnit(); 105 su.setComponent(WSNSpringComponent.this); 106 WSNDeployer deployer = new WSNDeployer(WSNSpringComponent.this); 107 if (resources != null) { 108 for (int i = 0; i < resources.length; i++) { 109 Endpoint ep = deployer.createEndpoint(resources[i].getURL()); 110 ep.setServiceUnit(su); 111 su.addEndpoint(ep); 112 } 113 } 114 if (requests != null) { 115 for (int i = 0; i < requests.length; i++) { 116 Endpoint ep = deployer.createEndpoint(requests[i]); 117 ep.setServiceUnit(su); 118 su.addEndpoint(ep); 119 } 120 } 121 getRegistry().registerServiceUnit(su); 122 } 123 124 127 protected void doStart() throws Exception { 128 super.doStart(); 129 su.start(); 130 } 131 132 135 protected void doStop() throws Exception { 136 su.stop(); 137 super.doStop(); 138 } 139 140 143 protected void doShutDown() throws Exception { 144 su.shutDown(); 145 super.doShutDown(); 146 } 147 } 148 149 } 150 | Popular Tags |