1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
package org.apache.tapestry.pageload; |
16 | |
|
17 | |
import org.apache.hivemind.ApplicationRuntimeException; |
18 | |
import org.apache.tapestry.IBinding; |
19 | |
import org.apache.tapestry.IComponent; |
20 | |
import org.apache.tapestry.binding.BindingConstants; |
21 | |
import org.apache.tapestry.binding.BindingSource; |
22 | |
import org.apache.tapestry.spec.IComponentSpecification; |
23 | |
import org.apache.tapestry.spec.IParameterSpecification; |
24 | |
|
25 | |
import java.util.Iterator; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | 0 | public class EstablishDefaultParameterValuesVisitor implements IComponentVisitor |
35 | |
{ |
36 | |
|
37 | |
|
38 | |
private BindingSource _bindingSource; |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
public void visitComponent(IComponent component) |
44 | |
{ |
45 | 0 | IComponentSpecification spec = component.getSpecification(); |
46 | |
|
47 | 0 | Iterator i = spec.getParameterNames().iterator(); |
48 | |
|
49 | 0 | while(i.hasNext()) |
50 | |
{ |
51 | 0 | String name = (String) i.next(); |
52 | 0 | IParameterSpecification parameterSpec = spec.getParameter(name); |
53 | |
|
54 | |
|
55 | |
|
56 | 0 | if (!name.equals(parameterSpec.getParameterName())) continue; |
57 | |
|
58 | 0 | String defaultValue = parameterSpec.getDefaultValue(); |
59 | 0 | if (defaultValue == null) continue; |
60 | |
|
61 | |
|
62 | 0 | if (parameterSpec.isRequired()) |
63 | 0 | throw new ApplicationRuntimeException(PageloadMessages |
64 | |
.parameterMustHaveNoDefaultValue(component, name), |
65 | |
component, parameterSpec.getLocation(), null); |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | 0 | if (component.getBinding(name) == null) |
73 | |
{ |
74 | 0 | String description = PageloadMessages |
75 | |
.defaultParameterName(name); |
76 | |
|
77 | 0 | IBinding binding = _bindingSource.createBinding(component, |
78 | |
description, defaultValue, |
79 | |
BindingConstants.OGNL_PREFIX, parameterSpec |
80 | |
.getLocation()); |
81 | |
|
82 | 0 | component.setBinding(name, binding); |
83 | |
} |
84 | 0 | } |
85 | 0 | } |
86 | |
|
87 | |
|
88 | |
|
89 | |
public void setBindingSource(BindingSource bindingSource) |
90 | |
{ |
91 | 0 | _bindingSource = bindingSource; |
92 | 0 | } |
93 | |
} |