KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > wsn > spring > WSNSpringComponent


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.wsn.spring;
18
19 import javax.jms.ConnectionFactory JavaDoc;
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 /**
30  *
31  * @author gnodet
32  * @version $Revision: 376451 $
33  * @org.apache.xbean.XBean element="component"
34  * description="An WS-Notification component"
35  */

36 public class WSNSpringComponent extends BaseComponent {
37
38     private Resource[] resources;
39     
40     private Object JavaDoc[] requests;
41     
42     /**
43      * @return Returns the endpoints.
44      */

45     public Resource[] getResources() {
46         return resources;
47     }
48
49     /**
50      * @param endpoints The endpoints to set.
51      */

52     public void setResources(Resource[] endpoints) {
53         this.resources = endpoints;
54     }
55     
56     /**
57      * @return Returns the requests.
58      */

59     public Object JavaDoc[] getRequests() {
60         return requests;
61     }
62
63     /**
64      * @param requests The requests to set.
65      */

66     public void setRequests(Object JavaDoc[] requests) {
67         this.requests = requests;
68     }
69
70     /**
71      * @return Returns the connectionFactory.
72      */

73     public ConnectionFactory JavaDoc getConnectionFactory() {
74         return ((WSNLifeCycle) lifeCycle).getConnectionFactory();
75     }
76
77     /**
78      * @param connectionFactory The connectionFactory to set.
79      */

80     public void setConnectionFactory(ConnectionFactory JavaDoc connectionFactory) {
81         ((WSNLifeCycle) lifeCycle).setConnectionFactory(connectionFactory);
82     }
83     
84     /* (non-Javadoc)
85      * @see org.servicemix.common.BaseComponent#createLifeCycle()
86      */

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         /* (non-Javadoc)
100          * @see org.servicemix.common.BaseLifeCycle#doInit()
101          */

102         protected void doInit() throws Exception JavaDoc {
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 JavaDoc {
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 JavaDoc {
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 JavaDoc {
144             su.shutDown();
145             super.doShutDown();
146         }
147     }
148
149 }
150
Popular Tags