Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
InvokeEngineTerminator |
|
| 1.0;1 |
1 | // Copyright 2004, 2005 The Apache Software Foundation | |
2 | // | |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | // you may not use this file except in compliance with the License. | |
5 | // You may obtain a copy of the License at | |
6 | // | |
7 | // http://www.apache.org/licenses/LICENSE-2.0 | |
8 | // | |
9 | // Unless required by applicable law or agreed to in writing, software | |
10 | // distributed under the License is distributed on an "AS IS" BASIS, | |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | // See the License for the specific language governing permissions and | |
13 | // limitations under the License. | |
14 | ||
15 | package org.apache.tapestry.services.impl; | |
16 | ||
17 | import java.io.IOException; | |
18 | ||
19 | import org.apache.tapestry.Constants; | |
20 | import org.apache.tapestry.IEngine; | |
21 | import org.apache.tapestry.services.EngineManager; | |
22 | import org.apache.tapestry.services.Infrastructure; | |
23 | import org.apache.tapestry.services.WebRequestServicer; | |
24 | import org.apache.tapestry.web.WebRequest; | |
25 | import org.apache.tapestry.web.WebResponse; | |
26 | ||
27 | /** | |
28 | * The terminatior for the <code>tapestry.RequestProcessor</code> pipeline, this service is | |
29 | * responsible for: | |
30 | * <ul> | |
31 | * <li>Locating the correct engine instance and letting it to the rest of the request. | |
32 | * <li>Returning the engine instance to the pool at the end of the request. </ul> | |
33 | * | |
34 | * @author Howard Lewis Ship | |
35 | * @since 4.0 | |
36 | */ | |
37 | 0 | public class InvokeEngineTerminator implements WebRequestServicer |
38 | { | |
39 | private EngineManager _engineManager; | |
40 | ||
41 | private Infrastructure _infrastructure; | |
42 | ||
43 | public void service(WebRequest request, WebResponse response) throws IOException | |
44 | { | |
45 | 0 | IEngine engine = _engineManager.getEngineInstance(); |
46 | ||
47 | // Until we can inject the infrastructure into the engine | |
48 | // we do this to let the engine know about it. | |
49 | ||
50 | 0 | request.setAttribute(Constants.INFRASTRUCTURE_KEY, _infrastructure); |
51 | ||
52 | try | |
53 | { | |
54 | 0 | engine.service(request, response); |
55 | } | |
56 | finally | |
57 | { | |
58 | 0 | _engineManager.storeEngineInstance(engine); |
59 | 0 | } |
60 | ||
61 | 0 | } |
62 | ||
63 | public void setEngineManager(EngineManager manager) | |
64 | { | |
65 | 0 | _engineManager = manager; |
66 | 0 | } |
67 | ||
68 | public void setInfrastructure(Infrastructure infrastructure) | |
69 | { | |
70 | 0 | _infrastructure = infrastructure; |
71 | 0 | } |
72 | } |