KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > services > impl > InvokeEngineTerminator


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 JavaDoc;
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.RequestGlobals;
24 import org.apache.tapestry.services.WebRequestServicer;
25 import org.apache.tapestry.web.WebRequest;
26 import org.apache.tapestry.web.WebResponse;
27
28 /**
29  * The terminatior for the <code>tapestry.RequestProcessor</code> pipeline, this service is
30  * responsible for:
31  * <ul>
32  * <li>Storing the request and response into {@link org.apache.tapestry.services.RequestGlobals}.
33  * <li>Locating the correct engine instance and letting it to the rest of the request.
34  * <li>Returning the engine instance to the pool at the end of the request. </ul
35  *
36  * @author Howard Lewis Ship
37  * @since 4.0
38  */

39 public class InvokeEngineTerminator implements WebRequestServicer
40 {
41     private EngineManager _engineManager;
42
43     private Infrastructure _infrastructure;
44
45     private RequestGlobals _requestGlobals;
46
47     public void service(WebRequest request, WebResponse response) throws IOException JavaDoc
48     {
49         _requestGlobals.store(request, response);
50
51         IEngine engine = _engineManager.getEngineInstance();
52
53         // Until we can inject the infrastructure into the engine
54
// we do this to let the engine know about it.
55

56         request.setAttribute(Constants.INFRASTRUCTURE_KEY, _infrastructure);
57
58         try
59         {
60             engine.service(request, response);
61         }
62         finally
63         {
64             _engineManager.storeEngineInstance(engine);
65         }
66
67     }
68
69     public void setEngineManager(EngineManager manager)
70     {
71         _engineManager = manager;
72     }
73
74     public void setInfrastructure(Infrastructure infrastructure)
75     {
76         _infrastructure = infrastructure;
77     }
78
79     public void setRequestGlobals(RequestGlobals requestGlobals)
80     {
81         _requestGlobals = requestGlobals;
82     }
83 }
Popular Tags