001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.servicemix.wsn.spring;
018
019 import javax.jms.ConnectionFactory;
020
021 import org.apache.servicemix.common.BaseComponent;
022 import org.apache.servicemix.common.BaseLifeCycle;
023 import org.apache.servicemix.common.Endpoint;
024 import org.apache.servicemix.common.ServiceUnit;
025 import org.apache.servicemix.wsn.component.WSNDeployer;
026 import org.apache.servicemix.wsn.component.WSNLifeCycle;
027 import org.springframework.core.io.Resource;
028
029 /**
030 *
031 * @author gnodet
032 * @version $Revision: 376451 $
033 * @org.apache.xbean.XBean element="component"
034 * description="An WS-Notification component"
035 */
036 public class WSNSpringComponent extends BaseComponent {
037
038 private Resource[] resources;
039
040 private Object[] requests;
041
042 /**
043 * @return Returns the endpoints.
044 */
045 public Resource[] getResources() {
046 return resources;
047 }
048
049 /**
050 * @param endpoints The endpoints to set.
051 */
052 public void setResources(Resource[] endpoints) {
053 this.resources = endpoints;
054 }
055
056 /**
057 * @return Returns the requests.
058 */
059 public Object[] getRequests() {
060 return requests;
061 }
062
063 /**
064 * @param requests The requests to set.
065 */
066 public void setRequests(Object[] requests) {
067 this.requests = requests;
068 }
069
070 /**
071 * @return Returns the connectionFactory.
072 */
073 public ConnectionFactory getConnectionFactory() {
074 return ((WSNLifeCycle) lifeCycle).getConnectionFactory();
075 }
076
077 /**
078 * @param connectionFactory The connectionFactory to set.
079 */
080 public void setConnectionFactory(ConnectionFactory connectionFactory) {
081 ((WSNLifeCycle) lifeCycle).setConnectionFactory(connectionFactory);
082 }
083
084 /* (non-Javadoc)
085 * @see org.servicemix.common.BaseComponent#createLifeCycle()
086 */
087 protected BaseLifeCycle createLifeCycle() {
088 return new LifeCycle();
089 }
090
091 public class LifeCycle extends WSNLifeCycle {
092
093 protected ServiceUnit su;
094
095 public LifeCycle() {
096 super(WSNSpringComponent.this);
097 }
098
099 /* (non-Javadoc)
100 * @see org.servicemix.common.BaseLifeCycle#doInit()
101 */
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 /* (non-Javadoc)
125 * @see org.servicemix.common.BaseLifeCycle#doStart()
126 */
127 protected void doStart() throws Exception {
128 super.doStart();
129 su.start();
130 }
131
132 /* (non-Javadoc)
133 * @see org.servicemix.common.BaseLifeCycle#doStop()
134 */
135 protected void doStop() throws Exception {
136 su.stop();
137 super.doStop();
138 }
139
140 /* (non-Javadoc)
141 * @see org.servicemix.common.BaseLifeCycle#doShutDown()
142 */
143 protected void doShutDown() throws Exception {
144 su.shutDown();
145 super.doShutDown();
146 }
147 }
148
149 }