public void setPropertyValues(PropertyValues propertyValues, boolean ignoreUnknown)
      throws BeansException {
    List propertyAccessExceptions = new ArrayList();
    PropertyValue[] pvs = propertyValues.getPropertyValues();
    for (int i = 0; i < pvs.length; i++) {
      try {
        // This method may throw any BeansException, which won't be caught
        // here, if there is a critical failure such as no matching field.
        // We can attempt to deal only with less serious exceptions.
        setPropertyValue(pvs[i]);
      } catch (NotWritablePropertyException ex) {
        if (!ignoreUnknown) {
          throw ex;
        }
        // Otherwise, just ignore it and continue...
      } catch (PropertyAccessException ex) {
        propertyAccessExceptions.add(ex);
      }
    }

    // If we encountered individual exceptions, throw the composite exception.
    if (!propertyAccessExceptions.isEmpty()) {
      Object[] paeArray =
          propertyAccessExceptions.toArray(
              new PropertyAccessException[propertyAccessExceptions.size()]);
      throw new PropertyAccessExceptionsException(this, (PropertyAccessException[]) paeArray);
    }
  }
示例#2
0
 /**
  * Copy all given PropertyValues into this object. Guarantees PropertyValue references are
  * independent, although it can't deep copy objects currently referenced by individual
  * PropertyValue objects.
  *
  * @param source the PropertyValues to copy
  */
 public void addPropertyValues(PropertyValues source) {
   if (source != null) {
     PropertyValue[] pvs = source.getPropertyValues();
     for (int i = 0; i < pvs.length; i++) {
       addPropertyValue(new PropertyValue(pvs[i].getName(), pvs[i].getValue()));
     }
     recache();
   }
 }
示例#3
0
 /**
  * Deep copy constructor. Guarantees PropertyValue references are independent, although it can't
  * deep copy objects currently referenced by individual PropertyValue objects.
  *
  * @param source the PropertyValues to copy
  * @see #addPropertyValues(PropertyValues)
  */
 public MutablePropertyValues(PropertyValues source) {
   // We can optimize this because it's all new:
   // there is no replacement of existing property values
   if (source != null) {
     PropertyValue[] pvs = source.getPropertyValues();
     this.propertyValueArray = new PropertyValue[pvs.length];
     for (int i = 0; i < pvs.length; i++) {
       PropertyValue newPv = new PropertyValue(pvs[i].getName(), pvs[i].getValue());
       propertyValueArray[i] = newPv;
       propertyValueList.add(newPv);
     }
   }
 }