|
|||||||||||||||||||
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 | |||||||||||||||
RequestCycleFactoryImpl.java | 70% | 89.3% | 100% | 87.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 org.apache.hivemind.ErrorHandler;
|
|
18 |
import org.apache.tapestry.IEngine;
|
|
19 |
import org.apache.tapestry.IRequestCycle;
|
|
20 |
import org.apache.tapestry.Tapestry;
|
|
21 |
import org.apache.tapestry.engine.IEngineService;
|
|
22 |
import org.apache.tapestry.engine.IMonitor;
|
|
23 |
import org.apache.tapestry.engine.IMonitorFactory;
|
|
24 |
import org.apache.tapestry.engine.IPageSource;
|
|
25 |
import org.apache.tapestry.engine.RequestCycle;
|
|
26 |
import org.apache.tapestry.engine.ServiceEncoder;
|
|
27 |
import org.apache.tapestry.engine.ServiceEncodingImpl;
|
|
28 |
import org.apache.tapestry.record.PropertyPersistenceStrategySource;
|
|
29 |
import org.apache.tapestry.request.RequestContext;
|
|
30 |
import org.apache.tapestry.services.Infrastructure;
|
|
31 |
import org.apache.tapestry.services.RequestCycleFactory;
|
|
32 |
import org.apache.tapestry.services.ServiceConstants;
|
|
33 |
import org.apache.tapestry.services.ServiceMap;
|
|
34 |
import org.apache.tapestry.util.QueryParameterMap;
|
|
35 |
|
|
36 |
/**
|
|
37 |
* @author Howard M. Lewis Ship
|
|
38 |
* @since 3.1
|
|
39 |
*/
|
|
40 |
public class RequestCycleFactoryImpl implements RequestCycleFactory |
|
41 |
{ |
|
42 |
private ServiceEncoder[] _encoders;
|
|
43 |
|
|
44 |
private IMonitorFactory _monitorFactory;
|
|
45 |
|
|
46 |
private PropertyPersistenceStrategySource _strategySource;
|
|
47 |
|
|
48 |
private ErrorHandler _errorHandler;
|
|
49 |
|
|
50 |
private Infrastructure _infrastructure;
|
|
51 |
|
|
52 | 185 |
public IRequestCycle newRequestCycle(IEngine engine, RequestContext context)
|
53 |
{ |
|
54 | 185 |
IMonitor monitor = _monitorFactory.createMonitor(context); |
55 |
|
|
56 | 185 |
QueryParameterMap parameters = extractParameters(context); |
57 |
|
|
58 | 185 |
decodeParameters(context.getRequest().getServletPath(), parameters); |
59 |
|
|
60 | 185 |
IEngineService service = findService(parameters); |
61 |
|
|
62 | 185 |
return new RequestCycle(engine, context, parameters, service, _infrastructure, |
63 |
_strategySource, _errorHandler, monitor); |
|
64 |
} |
|
65 |
|
|
66 | 185 |
private IEngineService findService(QueryParameterMap parameters)
|
67 |
{ |
|
68 | 185 |
String serviceName = parameters.getParameterValue(ServiceConstants.SERVICE); |
69 |
|
|
70 | 185 |
if (serviceName == null) |
71 | 24 |
serviceName = Tapestry.HOME_SERVICE; |
72 |
|
|
73 | 185 |
return _infrastructure.getServiceMap().getService(serviceName);
|
74 |
} |
|
75 |
|
|
76 |
/**
|
|
77 |
* Constructs a {@link org.apache.tapestry.util.QueryParameterMap}using the parameters
|
|
78 |
* available from the {@link org.apache.tapestry.request.RequestContext} (but ignoring any
|
|
79 |
* file upload parameters!).
|
|
80 |
*/
|
|
81 |
|
|
82 | 185 |
private QueryParameterMap extractParameters(RequestContext context)
|
83 |
{ |
|
84 | 185 |
QueryParameterMap result = new QueryParameterMap();
|
85 |
|
|
86 | 185 |
String[] names = context.getParameterNames(); |
87 |
|
|
88 | 185 |
for (int i = 0; i < names.length; i++) |
89 |
{ |
|
90 | 582 |
String name = names[i]; |
91 |
|
|
92 | 582 |
String[] values = context.getParameters(name); |
93 |
|
|
94 | 582 |
if (values.length == 1)
|
95 | 562 |
result.setParameterValue(name, values[0]); |
96 |
else
|
|
97 | 20 |
result.setParameterValues(name, values); |
98 |
} |
|
99 |
|
|
100 | 185 |
return result;
|
101 |
} |
|
102 |
|
|
103 | 185 |
private void decodeParameters(String servletPath, QueryParameterMap map) |
104 |
{ |
|
105 | 185 |
ServiceEncodingImpl se = new ServiceEncodingImpl(servletPath, map);
|
106 |
|
|
107 | 185 |
for (int i = 0; i < _encoders.length; i++) |
108 |
{ |
|
109 | 0 |
_encoders[i].decode(se); |
110 |
|
|
111 | 0 |
if (se.isModified())
|
112 | 0 |
return;
|
113 |
} |
|
114 |
} |
|
115 |
|
|
116 | 52 |
public void setEncoders(ServiceEncoder[] encoders) |
117 |
{ |
|
118 | 52 |
_encoders = encoders; |
119 |
} |
|
120 |
|
|
121 | 52 |
public void setMonitorFactory(IMonitorFactory monitorFactory) |
122 |
{ |
|
123 | 52 |
_monitorFactory = monitorFactory; |
124 |
} |
|
125 |
|
|
126 | 52 |
public void setStrategySource(PropertyPersistenceStrategySource strategySource) |
127 |
{ |
|
128 | 52 |
_strategySource = strategySource; |
129 |
} |
|
130 |
|
|
131 | 52 |
public void setErrorHandler(ErrorHandler errorHandler) |
132 |
{ |
|
133 | 52 |
_errorHandler = errorHandler; |
134 |
} |
|
135 |
|
|
136 | 52 |
public void setInfrastructure(Infrastructure infrastructure) |
137 |
{ |
|
138 | 52 |
_infrastructure = infrastructure; |
139 |
} |
|
140 |
} |
|