|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
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 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| public class EstablishDefaultParameterValuesVisitor implements IComponentVisitor |
|
35 |
| { |
|
36 |
| |
|
37 |
| private BindingSource _bindingSource; |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
2931
| public void visitComponent(IComponent component)
|
|
43 |
| { |
|
44 |
2931
| IComponentSpecification spec = component.getSpecification();
|
|
45 |
| |
|
46 |
2931
| Iterator i = spec.getParameterNames().iterator();
|
|
47 |
| |
|
48 |
2931
| while (i.hasNext())
|
|
49 |
| { |
|
50 |
9948
| String name = (String) i.next();
|
|
51 |
9948
| IParameterSpecification parameterSpec = spec.getParameter(name);
|
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
9948
| if (!name.equals(parameterSpec.getParameterName()))
|
|
56 |
0
| continue;
|
|
57 |
| |
|
58 |
9948
| String defaultValue = parameterSpec.getDefaultValue();
|
|
59 |
9948
| if (defaultValue == null)
|
|
60 |
8232
| continue;
|
|
61 |
| |
|
62 |
| |
|
63 |
1716
| if (parameterSpec.isRequired())
|
|
64 |
0
| throw new ApplicationRuntimeException(PageloadMessages
|
|
65 |
| .parameterMustHaveNoDefaultValue(component, name), component, parameterSpec |
|
66 |
| .getLocation(), null); |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
1716
| if (component.getBinding(name) == null)
|
|
72 |
| { |
|
73 |
1653
| String description = PageloadMessages.defaultParameterName(name);
|
|
74 |
| |
|
75 |
1653
| IBinding binding = _bindingSource.createBinding(
|
|
76 |
| component, |
|
77 |
| description, |
|
78 |
| defaultValue, |
|
79 |
| BindingConstants.OGNL_PREFIX, |
|
80 |
| parameterSpec.getLocation()); |
|
81 |
| |
|
82 |
1653
| component.setBinding(name, binding);
|
|
83 |
| } |
|
84 |
| } |
|
85 |
| } |
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
117
| public void setBindingSource(BindingSource bindingSource)
|
|
90 |
| { |
|
91 |
117
| _bindingSource = bindingSource;
|
|
92 |
| } |
|
93 |
| } |