|
|||||||||||||||||||
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 | |||||||||||||||
EstablishDefaultParameterValuesVisitor.java | 90% | 94.4% | 100% | 93.3% |
|
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.pageload;
|
|
16 |
|
|
17 |
import java.util.Iterator;
|
|
18 |
|
|
19 |
import org.apache.hivemind.ApplicationRuntimeException;
|
|
20 |
import org.apache.tapestry.IBinding;
|
|
21 |
import org.apache.tapestry.IComponent;
|
|
22 |
import org.apache.tapestry.binding.BindingConstants;
|
|
23 |
import org.apache.tapestry.binding.BindingSource;
|
|
24 |
import org.apache.tapestry.spec.IComponentSpecification;
|
|
25 |
import org.apache.tapestry.spec.IParameterSpecification;
|
|
26 |
|
|
27 |
/**
|
|
28 |
* For all parameters in the examined component that have default values, but are not bound,
|
|
29 |
* automatically add an ExpressionBinding with the default value.
|
|
30 |
*
|
|
31 |
* @author mindbridge
|
|
32 |
* @since 3.0
|
|
33 |
*/
|
|
34 |
public class EstablishDefaultParameterValuesVisitor implements IComponentVisitor |
|
35 |
{ |
|
36 |
/** @since 4.0 */
|
|
37 |
private BindingSource _bindingSource;
|
|
38 |
|
|
39 |
/**
|
|
40 |
* @see org.apache.tapestry.pageload.IComponentVisitor#visitComponent(org.apache.tapestry.IComponent)
|
|
41 |
*/
|
|
42 | 1133 |
public void visitComponent(IComponent component) |
43 |
{ |
|
44 | 1133 |
IComponentSpecification spec = component.getSpecification(); |
45 |
|
|
46 | 1133 |
Iterator i = spec.getParameterNames().iterator(); |
47 |
|
|
48 | 1133 |
while (i.hasNext())
|
49 |
{ |
|
50 | 3284 |
String name = (String) i.next(); |
51 | 3284 |
IParameterSpecification parameterSpec = spec.getParameter(name); |
52 |
|
|
53 | 3284 |
String defaultValue = parameterSpec.getDefaultValue(); |
54 | 3284 |
if (defaultValue == null) |
55 | 2882 |
continue;
|
56 |
|
|
57 |
// the parameter has a default value, so it must not be required
|
|
58 | 402 |
if (parameterSpec.isRequired())
|
59 | 0 |
throw new ApplicationRuntimeException(PageloadMessages |
60 |
.parameterMustHaveNoDefaultValue(component, name), component, parameterSpec |
|
61 |
.getLocation(), null);
|
|
62 |
|
|
63 |
// if there is no binding for this parameter, bind it to the default value.
|
|
64 |
// In 3.0, default-value as always an OGNL expression, but now its a locator.
|
|
65 |
|
|
66 | 402 |
if (component.getBinding(name) == null) |
67 |
{ |
|
68 | 379 |
String description = PageloadMessages.defaultParameterName(name); |
69 |
|
|
70 | 379 |
String defaultBindingType = parameterSpec.getDefaultBindingType(); |
71 | 379 |
if (defaultBindingType == null) |
72 | 16 |
defaultBindingType = BindingConstants.OGNL_PREFIX; |
73 |
|
|
74 | 379 |
IBinding binding = _bindingSource.createBinding( |
75 |
component, |
|
76 |
description, |
|
77 |
defaultValue, |
|
78 |
defaultBindingType, |
|
79 |
parameterSpec.getLocation()); |
|
80 |
|
|
81 | 379 |
component.setBinding(name, binding); |
82 |
} |
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
/** @since 4.0 */
|
|
87 |
|
|
88 | 45 |
public void setBindingSource(BindingSource bindingSource) |
89 |
{ |
|
90 | 45 |
_bindingSource = bindingSource; |
91 |
} |
|
92 |
} |
|