Package org.springframework.beans

Examples of org.springframework.beans.BeanWrapper


  @Test
  public void usesFieldAccessForWriteIfNoAccessorCanBeFound() {

    Sample sample = new Sample();

    BeanWrapper wrapper = new DirectFieldAccessFallbackBeanWrapper(sample);
    wrapper.setPropertyValue("firstname", "Dave");

    assertThat(sample.firstname, is("Dave"));
  }
View Full Code Here


   * @see DATACMNS-452
   */
  @Test(expected = NotReadablePropertyException.class)
  public void throwsAppropriateExceptionIfNoFieldFoundForRead() {

    BeanWrapper wrapper = new DirectFieldAccessFallbackBeanWrapper(new Sample());
    wrapper.getPropertyValue("lastname");
  }
View Full Code Here

   * @see DATACMNS-452
   */
  @Test(expected = NotWritablePropertyException.class)
  public void throwsAppropriateExceptionIfNoFieldFoundForWrite() {

    BeanWrapper wrapper = new DirectFieldAccessFallbackBeanWrapper(new Sample());
    wrapper.setPropertyValue("lastname", "Matthews");
  }
View Full Code Here

        validatedObjects.add(obj);

        // after all the validation rules where applied, checking what properties of the object require their own
        // validation and recursively calling this method on them.
        CascadeValidation[] cascadeValidations = configuration.getCascadeValidations();
        BeanWrapper wrapper = wrapBean(obj);
        for (int i=0; i<cascadeValidations.length; i++) {
            CascadeValidation cascadeValidation = cascadeValidations[i];
            Condition applicabilityCondition = cascadeValidation.getApplicabilityCondition();

            if (!applicabilityCondition.check(obj)) {
                continue;
            }

            String propertyName = cascadeValidation.getPropertyName();
            Class propertyType = wrapper.getPropertyType(propertyName);
            Object propertyValue = wrapper.getPropertyValue(propertyName);

            // if the property value is not there nothing to validate.
            if (propertyValue == null) {
                continue;
            }
View Full Code Here

     * If you want to provide custom behaviour, set an appropriate property editor (see {@link #setPropertyEditor(PropertyEditor propertyEditor)}).
     * @return The binding value, or null if no target object has been set.
     */
    public String getStatusValue() {
        if (this.target != null) {
            BeanWrapper wrapper = new BeanWrapperImpl(this.target);
            Object value = wrapper.getPropertyValue(this.expression);
            if (this.propertyEditor == null) {
                return value.toString();
            }
            else {
                this.propertyEditor.setValue(value);
View Full Code Here

     * @param contentProperty The JavaBean property which will be retrieved from the object for setting the content of the option: there must be
     * a standard JavaBean getter for this property.
     */
    public Option(Object optionObject, String valueProperty, String contentProperty) {
        if (optionObject != null) {
            BeanWrapper wrapper = new BeanWrapperImpl(optionObject);
           
            Object tmp = wrapper.getPropertyValue(valueProperty);
            if (tmp != null) {
                this.addAttribute("value", tmp.toString());
            }
            else {
                this.addAttribute("value", "");
            }
           
            tmp = wrapper.getPropertyValue(contentProperty);
            if (tmp != null) {
                this.internalAddContent(new SimpleText(tmp.toString()));
            }
            else {
                this.internalAddContent(new SimpleText(""));
View Full Code Here

     * @param textRenderingCallback A callback to implement for rendering the object property value as a specific component: if <code>null</code>,
     * the object property value will be rendered as simple text.
     */
    public AbstractTableData(Object dataObject, String property, TextRenderingCallback textRenderingCallback) {
        if (dataObject != null) {
            BeanWrapper wrapper = new BeanWrapperImpl(dataObject);
            Object tmp = wrapper.getPropertyValue(property);
            if (tmp != null) {
                String value = tmp.toString();
                if (textRenderingCallback != null) {
                  this.internalAddContent(textRenderingCallback.getRenderingComponent(value));
                }
View Full Code Here

      touch(target, properties);
    }
  }
 
  private static void touch(Object target, Object[] properties) {
    BeanWrapper beanWrapper = new BeanWrapperImpl(target);
    for (int x = 0; properties != null && x < properties.length; x++) {
      Object property = properties[x];
      if (property instanceof String) {
        Object result = beanWrapper.getPropertyValue((String)property);
        if (result instanceof Collection) {
          ((Collection)result).size();
        }
      } else if (property instanceof Map) {
        for (Iterator iter = ((Map)property).keySet().iterator(); iter.hasNext();) {
          Object key = iter.next();
          Object tmpProperties = ((Map)property).get(key);
          if (!(key instanceof String)) {
            throw new IllegalArgumentException("Maps configured in the [properties] property should have a string key!");
          }
          if (!(tmpProperties instanceof Collection)) {
            throw new IllegalArgumentException("Maps configured in the [properties] property should have a list value!");
          }
          Object result = beanWrapper.getPropertyValue((String)key);
          if (result instanceof Collection) {
            touch(((Collection)result).toArray(), ((Collection)tmpProperties).toArray());
          } else if (result instanceof Object[]) {
            touch((Object[])result, ((Collection)tmpProperties).toArray());
          } else {
View Full Code Here

    }

    Properties properties = SemicolonSeparatedPropertiesParser
        .parseProperties(text);

    BeanWrapper beanWrapper = new BeanWrapperImpl(cacheModelClass);

    if (properties != null) {
      for (Iterator i = properties.keySet().iterator(); i.hasNext();) {
        String propertyName = (String) i.next();
        String textProperty = properties.getProperty(propertyName);

        Object propertyValue = null;

        PropertyEditor propertyEditor = getPropertyEditor(propertyName);
        if (propertyEditor != null) {
          propertyEditor.setAsText(textProperty);
          propertyValue = propertyEditor.getValue();
        } else {
          propertyValue = textProperty;
        }
        beanWrapper.setPropertyValue(propertyName, propertyValue);
      }
    }

    setValue(beanWrapper.getWrappedInstance());
  }
View Full Code Here

   * @param targetType
   *          the target type (representing a JavaBean).
   * @return an instance of the specified target type.
   */
  private Object getBeanMatchingValue(Class targetType) {
    BeanWrapper beanWrapper = new BeanWrapperImpl(targetType);
    boolean matching = true;

    int memberCount = members.size();
    for (int i = 0; i < memberCount; i++) {
      XmlRpcMember member = (XmlRpcMember) members.get(i);

      String propertyName = member.name;
      if (beanWrapper.isWritableProperty(propertyName)) {
        Class propertyType = beanWrapper.getPropertyType(propertyName);
        Object propertyValue = member.value.getMatchingValue(propertyType);

        if (propertyValue == NOT_MATCHING) {
          matching = false;
          break;
        }

        beanWrapper.setPropertyValue(propertyName, propertyValue);

      } else {
        matching = false;
        break;
      }
    }

    Object matchingValue = null;
    if (matching) {
      matchingValue = beanWrapper.getWrappedInstance();
    } else {
      matchingValue = NOT_MATCHING;
    }

    return matchingValue;
View Full Code Here

TOP

Related Classes of org.springframework.beans.BeanWrapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.