|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
EngineFactoryImpl.java | 100% | 100% | 100% | 100% |
|
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.hivemind.ApplicationRuntimeException;
|
|
20 |
import org.apache.hivemind.ClassResolver;
|
|
21 |
import org.apache.tapestry.IEngine;
|
|
22 |
import org.apache.tapestry.services.EngineFactory;
|
|
23 |
import org.apache.tapestry.spec.IApplicationSpecification;
|
|
24 |
|
|
25 |
/**
|
|
26 |
* Standard implementation of {@link org.apache.tapestry.services.EngineFactory} service.
|
|
27 |
* This should do for most purposes, since a major focus of Tapestry 4.0 is to no longer
|
|
28 |
* require subclassing of {@link org.apache.tapestry.engine.BaseEngine}.
|
|
29 |
*
|
|
30 |
* @author Howard Lewis Ship
|
|
31 |
* @since 4.0
|
|
32 |
*/
|
|
33 |
public class EngineFactoryImpl implements EngineFactory |
|
34 |
{ |
|
35 |
private IApplicationSpecification _applicationSpecification;
|
|
36 |
private String _defaultEngineClassName;
|
|
37 |
private EngineConstructor _constructor;
|
|
38 |
private ClassResolver _classResolver;
|
|
39 |
|
|
40 |
interface EngineConstructor
|
|
41 |
{ |
|
42 |
IEngine construct(); |
|
43 |
} |
|
44 |
|
|
45 |
|
|
46 |
// TODO: Create a BaseEngineConstructor that is hardcoded to
|
|
47 |
// instantiate a BaseEngine instance, without using reflection
|
|
48 |
// (for efficiency).
|
|
49 |
|
|
50 |
static class ReflectiveEngineConstructor implements EngineConstructor |
|
51 |
{ |
|
52 |
private Class _engineClass;
|
|
53 |
|
|
54 | 48 |
ReflectiveEngineConstructor(Class engineClass) |
55 |
{ |
|
56 | 48 |
_engineClass = engineClass; |
57 |
} |
|
58 |
|
|
59 | 56 |
public IEngine construct()
|
60 |
{ |
|
61 | 56 |
try
|
62 |
{ |
|
63 | 56 |
return (IEngine) _engineClass.newInstance();
|
64 |
} |
|
65 |
catch (Exception ex)
|
|
66 |
{ |
|
67 | 1 |
throw new ApplicationRuntimeException( |
68 |
ImplMessages.errorInstantiatingEngine(_engineClass, ex), |
|
69 |
ex); |
|
70 |
} |
|
71 |
} |
|
72 |
} |
|
73 |
|
|
74 | 49 |
public void initializeService() |
75 |
{ |
|
76 | 49 |
String engineClassName = _applicationSpecification.getEngineClassName(); |
77 |
|
|
78 |
// TODO: Check in web.xml first.
|
|
79 |
|
|
80 | 49 |
if (engineClassName == null) |
81 | 41 |
engineClassName = _defaultEngineClassName; |
82 |
|
|
83 | 49 |
Class engineClass = _classResolver.findClass(engineClassName); |
84 |
|
|
85 | 48 |
_constructor = new ReflectiveEngineConstructor(engineClass);
|
86 |
} |
|
87 |
|
|
88 | 56 |
public IEngine constructNewEngineInstance(Locale locale)
|
89 |
{ |
|
90 | 56 |
IEngine result = _constructor.construct(); |
91 |
|
|
92 | 55 |
result.setLocale(locale); |
93 |
|
|
94 | 55 |
return result;
|
95 |
} |
|
96 |
|
|
97 | 49 |
public void setApplicationSpecification(IApplicationSpecification specification) |
98 |
{ |
|
99 | 49 |
_applicationSpecification = specification; |
100 |
} |
|
101 |
|
|
102 | 49 |
public void setClassResolver(ClassResolver resolver) |
103 |
{ |
|
104 | 49 |
_classResolver = resolver; |
105 |
} |
|
106 |
|
|
107 | 46 |
public void setDefaultEngineClassName(String string) |
108 |
{ |
|
109 | 46 |
_defaultEngineClassName = string; |
110 |
} |
|
111 |
|
|
112 |
} |
|
113 |
|
|