コード例 #1
0
  private PropertyValues createPropertyValues(Element beanElement) {
    PropertyValues propertyValues = new PropertyValues();
    NodeList nl = beanElement.getElementsByTagName(PROPERTY_ELEMENT);
    for (int i = 0; i < nl.getLength(); i++) {
      Element propElement = (Element) nl.item(i);
      PropertyValue propertyValue = createPropertyValue(propElement);
      propertyValues.addPropertyValue(propertyValue);
    }

    return propertyValues;
  }
コード例 #2
0
  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);
    }
  }
コード例 #3
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();
   }
 }
コード例 #4
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);
     }
   }
 }
コード例 #5
0
  public PropertyValues changesSince(PropertyValues old) {
    MutablePropertyValues changes = new MutablePropertyValues();
    if (old == this) return changes;

    // for each property value in the new set
    for (int i = 0; i < this.propertyValueArray.length; i++) {
      PropertyValue newPv = propertyValueArray[i];
      // if there wasn't an old one, add it
      PropertyValue pvOld = old.getPropertyValue(newPv.getName());
      if (pvOld == null) {
        changes.addPropertyValue(newPv);
      } else if (!pvOld.equals(newPv)) {
        // it's changed
        changes.addPropertyValue(newPv);
      }
    }
    return changes;
  }