1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
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 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
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 |
| |
47 |
| |
48 |
| |
49 |
| |
50 |
| static class ReflectiveEngineConstructor implements EngineConstructor |
51 |
| { |
52 |
| private Class _engineClass; |
53 |
| |
54 |
43
| ReflectiveEngineConstructor(Class engineClass)
|
55 |
| { |
56 |
43
| _engineClass = engineClass;
|
57 |
| } |
58 |
| |
59 |
51
| public IEngine construct()
|
60 |
| { |
61 |
51
| try
|
62 |
| { |
63 |
51
| 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 |
44
| public void initializeService()
|
75 |
| { |
76 |
44
| String engineClassName = _applicationSpecification.getEngineClassName();
|
77 |
| |
78 |
| |
79 |
| |
80 |
44
| if (engineClassName == null)
|
81 |
36
| engineClassName = _defaultEngineClassName;
|
82 |
| |
83 |
44
| Class engineClass = _classResolver.findClass(engineClassName);
|
84 |
| |
85 |
43
| _constructor = new ReflectiveEngineConstructor(engineClass);
|
86 |
| } |
87 |
| |
88 |
51
| public IEngine constructNewEngineInstance(Locale locale)
|
89 |
| { |
90 |
51
| IEngine result = _constructor.construct();
|
91 |
| |
92 |
50
| result.setLocale(locale);
|
93 |
| |
94 |
50
| return result;
|
95 |
| } |
96 |
| |
97 |
44
| public void setApplicationSpecification(IApplicationSpecification specification)
|
98 |
| { |
99 |
44
| _applicationSpecification = specification;
|
100 |
| } |
101 |
| |
102 |
44
| public void setClassResolver(ClassResolver resolver)
|
103 |
| { |
104 |
44
| _classResolver = resolver;
|
105 |
| } |
106 |
| |
107 |
41
| public void setDefaultEngineClassName(String string)
|
108 |
| { |
109 |
41
| _defaultEngineClassName = string;
|
110 |
| } |
111 |
| |
112 |
| } |