KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jms > JmsSpringComponent


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.jms;
18
19 import javax.jbi.servicedesc.ServiceEndpoint;
20
21 import org.apache.servicemix.common.BaseComponent;
22 import org.apache.servicemix.common.BaseLifeCycle;
23 import org.apache.servicemix.common.ServiceUnit;
24 import org.w3c.dom.DocumentFragment JavaDoc;
25
26 /**
27  *
28  * @author gnodet
29  * @version $Revision: 376451 $
30  * @org.apache.xbean.XBean element="component"
31  * description="A jms component"
32  */

33 public class JmsSpringComponent extends BaseComponent {
34
35     private JmsEndpoint[] endpoints;
36
37     /* (non-Javadoc)
38      * @see org.servicemix.common.BaseComponent#createLifeCycle()
39      */

40     protected BaseLifeCycle createLifeCycle() {
41         return new LifeCycle();
42     }
43
44     /* (non-Javadoc)
45      * @see javax.jbi.component.Component#resolveEndpointReference(org.w3c.dom.DocumentFragment)
46      */

47     public ServiceEndpoint resolveEndpointReference(DocumentFragment JavaDoc epr) {
48         return JmsResolvedEndpoint.resolveEndpoint(epr);
49     }
50     
51     public JmsEndpoint[] getEndpoints() {
52         return endpoints;
53     }
54
55     public void setEndpoints(JmsEndpoint[] endpoints) {
56         this.endpoints = endpoints;
57     }
58     
59     /**
60      * @return the configuration
61      * @org.apache.xbean.Flat
62      */

63     public JmsConfiguration getConfiguration() {
64         return ((JmsLifeCycle) getLifeCycle()).getConfiguration();
65     }
66
67     /**
68      * @param configuration the configuration to set
69      */

70     public void setConfiguration(JmsConfiguration configuration) {
71         ((JmsLifeCycle) getLifeCycle()).setConfiguration(configuration);
72     }
73
74     public class LifeCycle extends JmsLifeCycle {
75
76         protected ServiceUnit su;
77         
78         public LifeCycle() {
79             super(JmsSpringComponent.this);
80         }
81         
82         /* (non-Javadoc)
83          * @see org.servicemix.common.BaseLifeCycle#doInit()
84          */

85         protected void doInit() throws Exception JavaDoc {
86             super.doInit();
87             su = new ServiceUnit();
88             su.setComponent(JmsSpringComponent.this);
89             if (endpoints != null) {
90                 for (int i = 0; i < endpoints.length; i++) {
91                     endpoints[i].setServiceUnit(su);
92                     su.addEndpoint(endpoints[i]);
93                 }
94             }
95             getRegistry().registerServiceUnit(su);
96         }
97
98         /* (non-Javadoc)
99          * @see org.servicemix.common.BaseLifeCycle#doStart()
100          */

101         protected void doStart() throws Exception JavaDoc {
102             super.doStart();
103             su.start();
104         }
105         
106         /* (non-Javadoc)
107          * @see org.servicemix.common.BaseLifeCycle#doStop()
108          */

109         protected void doStop() throws Exception JavaDoc {
110             su.stop();
111             super.doStop();
112         }
113         
114         /* (non-Javadoc)
115          * @see org.servicemix.common.BaseLifeCycle#doShutDown()
116          */

117         protected void doShutDown() throws Exception JavaDoc {
118             su.shutDown();
119             super.doShutDown();
120         }
121     }
122
123 }
124
Popular Tags