KickJava   Java API By Example, From Geeks To Geeks.

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


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 JavaDoc;
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.RequestLocaleManager;
23 import org.apache.tapestry.services.ObjectPool;
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 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         Locale JavaDoc locale = _localeManager.extractLocaleForCurrentRequest();
43
44         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         if (result == null)
51             result = _engineFactory.constructNewEngineInstance(locale);
52
53         return result;
54     }
55
56     public void storeEngineInstance(IEngine engine)
57     {
58         _enginePool.store(engine.getLocale(), engine);
59     }
60
61     public void setEngineFactory(EngineFactory factory)
62     {
63         _engineFactory = factory;
64     }
65
66     public void setEnginePool(ObjectPool pool)
67     {
68         _enginePool = pool;
69     }
70
71     public void setLocaleManager(RequestLocaleManager manager)
72     {
73         _localeManager = manager;
74     }
75 }
Popular Tags