|
|||||||||||||||||||
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 | |||||||||||||||
BindingBeanInitializer.java | 100% | 100% | 100% | 100% |
|
1 |
// Copyright 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.bean;
|
|
16 |
|
|
17 |
import org.apache.hivemind.util.Defense;
|
|
18 |
import org.apache.hivemind.util.PropertyUtils;
|
|
19 |
import org.apache.tapestry.IBeanProvider;
|
|
20 |
import org.apache.tapestry.IBinding;
|
|
21 |
import org.apache.tapestry.IComponent;
|
|
22 |
import org.apache.tapestry.binding.BindingSource;
|
|
23 |
|
|
24 |
/**
|
|
25 |
* An {@link org.apache.tapestry.bean.IBeanInitializer} implementation that uses an
|
|
26 |
* {@link org.apache.tapestry.IBinding} to obtain the value which will be assigned to the
|
|
27 |
* bean property.
|
|
28 |
*
|
|
29 |
* @author Howard M. Lewis Ship
|
|
30 |
* @since 3.1
|
|
31 |
*/
|
|
32 |
public class BindingBeanInitializer extends AbstractBeanInitializer |
|
33 |
{ |
|
34 |
private BindingSource _bindingSource;
|
|
35 |
|
|
36 |
private String _bindingReference;
|
|
37 |
|
|
38 |
/** @since 3.1 */
|
|
39 |
private IBinding _binding;
|
|
40 |
|
|
41 |
/** @since 3.1 */
|
|
42 | 18 |
public BindingBeanInitializer(BindingSource source)
|
43 |
{ |
|
44 | 18 |
Defense.notNull(source, "source");
|
45 |
|
|
46 | 18 |
_bindingSource = source; |
47 |
} |
|
48 |
|
|
49 |
/**
|
|
50 |
* @since 3.1
|
|
51 |
*/
|
|
52 | 18 |
public void setBindingReference(String bindingReference) |
53 |
{ |
|
54 | 18 |
_bindingReference = bindingReference; |
55 |
} |
|
56 |
|
|
57 |
/** @since 3.1 */
|
|
58 | 4 |
public String getBindingReference()
|
59 |
{ |
|
60 | 4 |
return _bindingReference;
|
61 |
} |
|
62 |
|
|
63 | 13 |
public void setBeanProperty(IBeanProvider provider, Object bean) |
64 |
{ |
|
65 | 13 |
if (_binding == null) |
66 |
{ |
|
67 | 12 |
IComponent component = provider.getComponent(); |
68 |
|
|
69 | 12 |
String description = BeanMessages.propertyInitializerName(_propertyName); |
70 |
|
|
71 | 12 |
_binding = _bindingSource.createBinding( |
72 |
component, |
|
73 |
description, |
|
74 |
_bindingReference, |
|
75 |
getLocation()); |
|
76 |
} |
|
77 |
|
|
78 | 13 |
Class propertyType = PropertyUtils.getPropertyType(bean, _propertyName); |
79 |
|
|
80 | 13 |
Object bindingValue = _binding.getObject(propertyType); |
81 |
|
|
82 | 13 |
setBeanProperty(bean, bindingValue); |
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
|
|