コード例 #1
0
 private void setValueSilently(
     Object sourceBean,
     PropertyDescriptor sourcePropertyDescriptor,
     Object targetBean,
     PropertyDescriptor targetPropertyDescriptor,
     Object newValue) {
   if (property1ChangeHandler != null) {
     removePropertyChangeHandler(bean1, bean1Class, property1ChangeHandler);
   }
   if (property2ChangeHandler != null) {
     removePropertyChangeHandler(bean2, bean2Class, property2ChangeHandler);
   }
   try {
     // Set the new value in the target bean.
     BeanUtils.setValue(targetBean, targetPropertyDescriptor, newValue);
   } catch (PropertyVetoException e) {
     // Silently ignore this situation here, will be handled below.
   }
   // The target bean setter may have modified the new value.
   // Read the value set in the target bean.
   Object value = BeanUtils.getValue(targetBean, targetPropertyDescriptor);
   // If the new value and the value read differ,
   // update the source bean's value.
   // This ignores that the source bean setter may modify the value again.
   // But we won't end in a loop.
   if (!BindingUtils.equals(value, newValue)) {
     boolean sourcePropertyWritable = sourcePropertyDescriptor.getWriteMethod() != null;
     if (sourcePropertyWritable) {
       try {
         BeanUtils.setValue(sourceBean, sourcePropertyDescriptor, value);
       } catch (PropertyVetoException e) {
         // Ignore. The value set is a modified variant
         // of a value that had been accepted before.
       }
     }
   }
   if (property1ChangeHandler != null) {
     addPropertyChangeHandler(bean1, bean1Class, property1ChangeHandler);
   }
   if (property2ChangeHandler != null) {
     addPropertyChangeHandler(bean2, bean2Class, property2ChangeHandler);
   }
 }