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