KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > http > HttpSpringComponent


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.http;
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.apache.servicemix.http.jetty.JCLLogger;
25 import org.w3c.dom.DocumentFragment JavaDoc;
26
27 /**
28  *
29  * @author gnodet
30  * @version $Revision: 426415 $
31  * @org.apache.xbean.XBean element="component"
32  * description="An http component"
33  */

34 public class HttpSpringComponent extends BaseComponent {
35
36     private HttpEndpoint[] endpoints;
37     
38     static {
39         JCLLogger.init();
40     }
41     
42     /* (non-Javadoc)
43      * @see org.servicemix.common.BaseComponent#createLifeCycle()
44      */

45     protected BaseLifeCycle createLifeCycle() {
46         return new LifeCycle();
47     }
48
49     /* (non-Javadoc)
50      * @see javax.jbi.component.Component#resolveEndpointReference(org.w3c.dom.DocumentFragment)
51      */

52     public ServiceEndpoint resolveEndpointReference(DocumentFragment JavaDoc epr) {
53         return HttpResolvedEndpoint.resolveEndpoint(epr);
54     }
55     
56     public HttpEndpoint[] getEndpoints() {
57         return endpoints;
58     }
59
60     public void setEndpoints(HttpEndpoint[] endpoints) {
61         this.endpoints = endpoints;
62     }
63     
64     public class LifeCycle extends HttpLifeCycle {
65
66         protected ServiceUnit su;
67         
68         public LifeCycle() {
69             super(HttpSpringComponent.this);
70         }
71         
72         /* (non-Javadoc)
73          * @see org.servicemix.common.BaseLifeCycle#doInit()
74          */

75         protected void doInit() throws Exception JavaDoc {
76             super.doInit();
77             su = new ServiceUnit();
78             su.setComponent(HttpSpringComponent.this);
79             if (endpoints != null) {
80                 for (int i = 0; i < endpoints.length; i++) {
81                     endpoints[i].setServiceUnit(su);
82                     su.addEndpoint(endpoints[i]);
83                 }
84             }
85             getRegistry().registerServiceUnit(su);
86         }
87
88         /* (non-Javadoc)
89          * @see org.servicemix.common.BaseLifeCycle#doStart()
90          */

91         protected void doStart() throws Exception JavaDoc {
92             super.doStart();
93             su.start();
94         }
95         
96         /* (non-Javadoc)
97          * @see org.servicemix.common.BaseLifeCycle#doStop()
98          */

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

107         protected void doShutDown() throws Exception JavaDoc {
108             su.shutDown();
109             super.doShutDown();
110         }
111     }
112
113     /**
114      * @return the configuration
115      * @org.apache.xbean.Flat
116      */

117     public HttpConfiguration getConfiguration() {
118         return ((HttpLifeCycle) getLifeCycle()).getConfiguration();
119     }
120
121     /**
122      * @param configuration the configuration to set
123      */

124     public void setConfiguration(HttpConfiguration configuration) {
125         ((HttpLifeCycle) getLifeCycle()).setConfiguration(configuration);
126     }
127
128     public HttpProcessor getMainProcessor() {
129         return ((HttpLifeCycle) getLifeCycle()).getMainProcessor();
130     }
131
132 }
133
Popular Tags