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 |
977
| public void visitComponent(IComponent component)
|
43 |
| { |
44 |
977
| IComponentSpecification spec = component.getSpecification();
|
45 |
| |
46 |
977
| Iterator i = spec.getParameterNames().iterator();
|
47 |
| |
48 |
977
| while (i.hasNext())
|
49 |
| { |
50 |
3316
| String name = (String) i.next();
|
51 |
3316
| IParameterSpecification parameterSpec = spec.getParameter(name);
|
52 |
| |
53 |
| |
54 |
| |
55 |
3316
| if (!name.equals(parameterSpec.getParameterName()))
|
56 |
0
| continue;
|
57 |
| |
58 |
3316
| String defaultValue = parameterSpec.getDefaultValue();
|
59 |
3316
| if (defaultValue == null)
|
60 |
2744
| continue;
|
61 |
| |
62 |
| |
63 |
572
| if (parameterSpec.isRequired())
|
64 |
0
| throw new ApplicationRuntimeException(PageloadMessages
|
65 |
| .parameterMustHaveNoDefaultValue(component, name), component, parameterSpec |
66 |
| .getLocation(), null); |
67 |
| |
68 |
| |
69 |
| |
70 |
| |
71 |
572
| if (component.getBinding(name) == null)
|
72 |
| { |
73 |
551
| String description = PageloadMessages.defaultParameterName(name);
|
74 |
| |
75 |
551
| IBinding binding = _bindingSource.createBinding(
|
76 |
| component, |
77 |
| description, |
78 |
| defaultValue, |
79 |
| BindingConstants.OGNL_PREFIX, |
80 |
| parameterSpec.getLocation()); |
81 |
| |
82 |
551
| component.setBinding(name, binding);
|
83 |
| } |
84 |
| } |
85 |
| } |
86 |
| |
87 |
| |
88 |
| |
89 |
39
| public void setBindingSource(BindingSource bindingSource)
|
90 |
| { |
91 |
39
| _bindingSource = bindingSource;
|
92 |
| } |
93 |
| } |