1 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.BindingConstants; 23 import org.apache.tapestry.binding.BindingSource; 24 25 33 public class BindingBeanInitializer extends AbstractBeanInitializer 34 { 35 private BindingSource _bindingSource; 36 37 private String _bindingReference; 38 39 40 private IBinding _binding; 41 42 43 public BindingBeanInitializer(BindingSource source) 44 { 45 Defense.notNull(source, "source"); 46 47 _bindingSource = source; 48 } 49 50 53 public void setBindingReference(String bindingReference) 54 { 55 _bindingReference = bindingReference; 56 } 57 58 59 public String getBindingReference() 60 { 61 return _bindingReference; 62 } 63 64 public void setBeanProperty(IBeanProvider provider, Object bean) 65 { 66 if (_binding == null) 67 { 68 IComponent component = provider.getComponent(); 69 70 String description = BeanMessages.propertyInitializerName(_propertyName); 71 72 _binding = _bindingSource.createBinding( 73 component, 74 description, 75 _bindingReference, 76 BindingConstants.OGNL_PREFIX, 77 getLocation()); 78 } 79 80 Class propertyType = PropertyUtils.getPropertyType(bean, _propertyName); 81 82 Object bindingValue = _binding.getObject(propertyType); 83 84 setBeanProperty(bean, bindingValue); 85 } 86 } 87 88 | Popular Tags |