コード例 #1
0
 /**
  * Checks for structured properties. Structured properties are properties with a name containg a
  * "_"
  *
  * @param propertyValues
  */
 @SuppressWarnings("unchecked")
 private void checkStructuredProperties(MutablePropertyValues propertyValues) {
   PropertyValue[] pvs = propertyValues.getPropertyValues();
   for (PropertyValue propertyValue : pvs) {
     if (!isStructured(propertyValue)) {
       continue;
     }
     String propertyName = getNameOf(propertyValue);
     Class<?> type = bean.getPropertyType(propertyName);
     if (type != null) {
       PropertyEditor editor = findCustomEditor(type, propertyName);
       if (null != editor && StructuredPropertyEditor.class.isAssignableFrom(editor.getClass())) {
         StructuredPropertyEditor structuredEditor = (StructuredPropertyEditor) editor;
         List fields = new ArrayList();
         fields.addAll(structuredEditor.getRequiredFields());
         fields.addAll(structuredEditor.getOptionalFields());
         Map<String, String> fieldValues = new HashMap<String, String>();
         try {
           for (Object fld : fields) {
             String field = (String) fld;
             PropertyValue partialStructValue =
                 propertyValues.getPropertyValue(
                     propertyName + STRUCTURED_PROPERTY_SEPERATOR + field);
             if (partialStructValue == null
                 && structuredEditor.getRequiredFields().contains(field)) {
               throw new MissingPropertyException(
                   "Required structured property is missing [" + field + "]");
             } else if (partialStructValue == null) {
               continue;
             }
             fieldValues.put(field, getStringValue(partialStructValue));
           }
           try {
             Object value = structuredEditor.assemble(type, fieldValues);
             for (Object fld : fields) {
               String field = (String) fld;
               PropertyValue partialStructValue =
                   propertyValues.getPropertyValue(
                       propertyName + STRUCTURED_PROPERTY_SEPERATOR + field);
               if (null != partialStructValue) {
                 partialStructValue.setConvertedValue(getStringValue(partialStructValue));
               }
             }
             propertyValues.addPropertyValue(new PropertyValue(propertyName, value));
           } catch (IllegalArgumentException iae) {
             LOG.warn(
                 "Unable to parse structured date from request for date [" + propertyName + "]",
                 iae);
           }
         } catch (InvalidPropertyException ipe) {
           // ignore
         }
       }
     }
   }
 }
コード例 #2
0
  @SuppressWarnings("unchecked")
  private void filterBlankValuesWhenTargetIsNullable(MutablePropertyValues mpvs) {
    Object target = getTarget();
    Map constrainedProperties = resolveConstrainedProperties(target, domainClass);
    if (constrainedProperties == null) {
      return;
    }

    PropertyValue[] valueArray = mpvs.getPropertyValues();
    for (PropertyValue propertyValue : valueArray) {
      if (BLANK.equals(propertyValue.getValue())) {
        ConstrainedProperty cp =
            getConstrainedPropertyForPropertyValue(constrainedProperties, propertyValue);
        if (shouldNullifyBlankString(propertyValue, cp)) {
          propertyValue.setConvertedValue(null);
        }
      }
    }
  }