KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jsr181 > Jsr181SpringComponent


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.jsr181;
18
19 import org.apache.servicemix.common.BaseComponent;
20 import org.apache.servicemix.common.BaseLifeCycle;
21 import org.apache.servicemix.common.ServiceUnit;
22 import org.apache.servicemix.common.xbean.XBeanServiceUnit;
23
24 /**
25  *
26  * @author gnodet
27  * @version $Revision: 426415 $
28  * @org.apache.xbean.XBean element="component"
29  * description="A jsr181 component"
30  */

31 public class Jsr181SpringComponent extends BaseComponent {
32
33     private Jsr181Endpoint[] endpoints;
34     
35     /* (non-Javadoc)
36      * @see org.servicemix.common.BaseComponent#createLifeCycle()
37      */

38     protected BaseLifeCycle createLifeCycle() {
39         return new LifeCycle();
40     }
41
42     public Jsr181Endpoint[] getEndpoints() {
43         return endpoints;
44     }
45
46     public void setEndpoints(Jsr181Endpoint[] endpoints) {
47         this.endpoints = endpoints;
48     }
49     
50     public class LifeCycle extends Jsr181LifeCycle {
51
52         protected ServiceUnit su;
53         
54         public LifeCycle() {
55             super(Jsr181SpringComponent.this);
56         }
57         
58         /* (non-Javadoc)
59          * @see org.servicemix.common.BaseLifeCycle#doInit()
60          */

61         protected void doInit() throws Exception JavaDoc {
62             super.doInit();
63             su = new XBeanServiceUnit();
64             su.setComponent(Jsr181SpringComponent.this);
65             for (int i = 0; i < endpoints.length; i++) {
66                 endpoints[i].setServiceUnit(su);
67                 endpoints[i].registerService();
68                 su.addEndpoint(endpoints[i]);
69             }
70             getRegistry().registerServiceUnit(su);
71         }
72
73         /* (non-Javadoc)
74          * @see org.servicemix.common.BaseLifeCycle#doStart()
75          */

76         protected void doStart() throws Exception JavaDoc {
77             super.doStart();
78             su.start();
79         }
80         
81         /* (non-Javadoc)
82          * @see org.servicemix.common.BaseLifeCycle#doStop()
83          */

84         protected void doStop() throws Exception JavaDoc {
85             su.stop();
86             super.doStop();
87         }
88         
89         /* (non-Javadoc)
90          * @see org.servicemix.common.BaseLifeCycle#doShutDown()
91          */

92         protected void doShutDown() throws Exception JavaDoc {
93             su.shutDown();
94             super.doShutDown();
95         }
96     }
97
98 }
99
Popular Tags