Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
EngineManagerImpl |
|
| 1.2;1.2 |
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.util.Locale; | |
18 | ||
19 | import org.apache.tapestry.IEngine; | |
20 | import org.apache.tapestry.services.EngineFactory; | |
21 | import org.apache.tapestry.services.EngineManager; | |
22 | import org.apache.tapestry.services.ObjectPool; | |
23 | import org.apache.tapestry.services.RequestLocaleManager; | |
24 | ||
25 | /** | |
26 | * Implementation of service {@link org.apache.tapestry.services.EngineManager}. | |
27 | * Service point tapestry.request.EngineManager. | |
28 | * | |
29 | * @author Howard Lewis Ship | |
30 | * @since 4.0 | |
31 | */ | |
32 | 0 | public class EngineManagerImpl implements EngineManager |
33 | { | |
34 | private ObjectPool _enginePool; | |
35 | ||
36 | private EngineFactory _engineFactory; | |
37 | ||
38 | private RequestLocaleManager _localeManager; | |
39 | ||
40 | public IEngine getEngineInstance() | |
41 | { | |
42 | 0 | Locale locale = _localeManager.extractLocaleForCurrentRequest(); |
43 | ||
44 | 0 | IEngine result = (IEngine) _enginePool.get(locale); |
45 | ||
46 | // This happens when either the pool is empty, or when a session exists | |
47 | // but the engine has not been stored into it (which should never happen, and | |
48 | // probably indicates an error in the framework or the application). | |
49 | ||
50 | 0 | if (result == null) |
51 | 0 | result = _engineFactory.constructNewEngineInstance(locale); |
52 | ||
53 | 0 | return result; |
54 | } | |
55 | ||
56 | public void storeEngineInstance(IEngine engine) | |
57 | { | |
58 | 0 | _enginePool.store(engine.getLocale(), engine); |
59 | 0 | } |
60 | ||
61 | public void setEngineFactory(EngineFactory factory) | |
62 | { | |
63 | 0 | _engineFactory = factory; |
64 | 0 | } |
65 | ||
66 | public void setEnginePool(ObjectPool pool) | |
67 | { | |
68 | 0 | _enginePool = pool; |
69 | 0 | } |
70 | ||
71 | public void setLocaleManager(RequestLocaleManager manager) | |
72 | { | |
73 | 0 | _localeManager = manager; |
74 | 0 | } |
75 | } |