Examples of BeanWrapper


Examples of org.springframework.beans.BeanWrapper

    /** Get the object id. */
    @SuppressWarnings("unchecked")
  private String getObjectParameterIdFromList(Object object, List list) {


        BeanWrapper wrapper = new BeanWrapperImpl(object);
        Object idValue =  wrapper.getPropertyValue(this.idPropertyName);


        if (!(idValue instanceof Number || idValue == null) ) {
            throw new IllegalStateException("The value of index property is not a number");
        }
View Full Code Here

Examples of org.springframework.beans.BeanWrapper

  private String getObjectParameterIdFromMap(Object object, Map map) {

        Object idValue = null;

        if (!this.idPropertyName.equals("id")) {
            BeanWrapper wrapper = new BeanWrapperImpl(object);
            idValue =  wrapper.getPropertyValue(this.idPropertyName);

            if (keyType==String.class) {
                return idValue.toString();
            } else {
                return idValue.toString();
View Full Code Here

Examples of org.springframework.beans.BeanWrapper

              " specified, you must use 'parquet' with " + this.getClass().getSimpleName() + ".");
        }
      }
    }
    GenericRecordBuilder builder = new GenericRecordBuilder(schema);
    BeanWrapper beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(entity);
    for (Schema.Field f : schema.getFields()) {
      if (beanWrapper.isReadableProperty(f.name())) {
        Schema fieldSchema = f.schema();
        if (f.schema().getType().equals(Schema.Type.UNION)) {
          for (Schema s : f.schema().getTypes()) {
            if (!s.getName().equals("null")) {
              fieldSchema = s;
            }
          }
        }
        if (fieldSchema.getType().equals(Schema.Type.RECORD)) {
          throw new StoreException("Nested record currently not supported for field: " + f.name() +
              " of type: " + beanWrapper.getPropertyDescriptor(f.name()).getPropertyType().getName());
        } else {
          if (fieldSchema.getType().equals(Schema.Type.BYTES)) {
            ByteBuffer buffer = null;
            Object value = beanWrapper.getPropertyValue(f.name());
            if (value == null || value instanceof byte[]) {
              if(value != null) {
                byte[] bytes = (byte[]) value;
                buffer = ByteBuffer.wrap(bytes);
              }
              builder.set(f.name(), buffer);
            } else {
              throw new StoreException("Don't know how to handle " + value.getClass() + " for " + fieldSchema);
            }
          } else {
            builder.set(f.name(), beanWrapper.getPropertyValue(f.name()));
            }
        }
      }
    }
    try {
View Full Code Here

Examples of org.springframework.beans.BeanWrapper

                    DescribedElement element = (DescribedElement)bean;
                    setText(element.getDisplayName());
                    setToolTipText(element.getCaption());
                }
                else {
                    BeanWrapper wrapper = new BeanWrapperImpl(bean);
                    try {
                        Object text = propertyName != null ? wrapper.getPropertyValue(propertyName) : wrapper
                                .getPropertyValue("name");
                        setText(String.valueOf(text));
                    }
                    catch (FatalBeanException e) {
View Full Code Here

Examples of org.springframework.beans.BeanWrapper

     * @param formModel
     * @param objectToMap
     */
    public static void mapObjectOnFormModel(FormModel formModel, Object objectToMap)
    {
        BeanWrapper beanWrapper = new BeanWrapperImpl(objectToMap);
        for (String fieldName : (Set<String>) formModel.getFieldNames())
        {
            try
            {
                formModel.getValueModel(fieldName).setValue(beanWrapper.getPropertyValue(fieldName));
            }
            catch (BeansException be)
            {
                // silently ignoring, just mapping values, so if there's one missing, don't bother
            }
View Full Code Here

Examples of org.springframework.beans.BeanWrapper

    return binding;
  }

  protected void applyContext(NachoCalendarDateFieldBinding binding, Map context) {
    super.applyContext(binding, context);
        BeanWrapper wrapper = new BeanWrapperImpl(binding.getControl());
    Object dateFormat = context.get(DATE_FORMAT);
    // remove DATE_FORMAT temporarily since it is handled in the super class
    context.remove(DATE_FORMAT);
    wrapper.setPropertyValues(context);
    if (dateFormat != null) {
      // restore the original context
      context.put(DATE_FORMAT, dateFormat);
        }
  }
View Full Code Here

Examples of org.springframework.beans.BeanWrapper

        Assert.isTrue((o instanceof View), "View class '" + viewClass
                + "' was instantiated, but instance is not a View!");
        View view = (View) o;
        view.setDescriptor(this);
        if (viewProperties != null) {
            BeanWrapper wrapper = new BeanWrapperImpl(view);
            wrapper.setPropertyValues(viewProperties);
        }

        if (view instanceof InitializingBean) {
            try {
                ((InitializingBean) view).afterPropertiesSet();
View Full Code Here

Examples of org.springframework.beans.BeanWrapper

    ApplicationEventMulticaster multicaster = getApplicationEventMulticaster();
    if(editor instanceof ApplicationListener &&  multicaster != null){
      multicaster.addApplicationListener((ApplicationListener)editor);
    }
    if(editorProperties != null){
      BeanWrapper wrapper = new BeanWrapperImpl(editor);
      wrapper.setPropertyValues(editorProperties);
    }
    if(editor instanceof InitializingBean){
       try {
         ((InitializingBean)editor).afterPropertiesSet();
           }
View Full Code Here

Examples of org.springframework.beans.BeanWrapper

    tb1.setNestedIndexedBean(new IndexedTestBean());
    tb2.setNestedIndexedBean(new IndexedTestBean());
    tb3.setNestedIndexedBean(new IndexedTestBean());
    tb4.setNestedIndexedBean(new IndexedTestBean());
    tb5.setNestedIndexedBean(new IndexedTestBean());
    BeanWrapper bw = new BeanWrapperImpl(bean);
    bw.registerCustomEditor(String.class, "array.nestedIndexedBean.array.name", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("array" + text);
      }

      public String getAsText() {
        return ((String) getValue()).substring(5);
      }
    });
    bw.registerCustomEditor(String.class, "list.nestedIndexedBean.list.name", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("list" + text);
      }

      public String getAsText() {
        return ((String) getValue()).substring(4);
      }
    });
    bw.registerCustomEditor(String.class, "map.nestedIndexedBean.map.name", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("map" + text);
      }

      public String getAsText() {
        return ((String) getValue()).substring(4);
      }
    });
    assertEquals("name0", tb0.getName());
    assertEquals("name1", tb1.getName());
    assertEquals("name2", tb2.getName());
    assertEquals("name3", tb3.getName());
    assertEquals("name4", tb4.getName());
    assertEquals("name5", tb5.getName());
    assertEquals("name0", bw.getPropertyValue("array[0].nestedIndexedBean.array[0].name"));
    assertEquals("name1", bw.getPropertyValue("array[1].nestedIndexedBean.array[1].name"));
    assertEquals("name2", bw.getPropertyValue("list[0].nestedIndexedBean.list[0].name"));
    assertEquals("name3", bw.getPropertyValue("list[1].nestedIndexedBean.list[1].name"));
    assertEquals("name4", bw.getPropertyValue("map[key1].nestedIndexedBean.map[key1].name"));
    assertEquals("name5", bw.getPropertyValue("map['key2'].nestedIndexedBean.map[\"key2\"].name"));

    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("array[0].nestedIndexedBean.array[0].name", "name5");
    pvs.addPropertyValue("array[1].nestedIndexedBean.array[1].name", "name4");
    pvs.addPropertyValue("list[0].nestedIndexedBean.list[0].name", "name3");
    pvs.addPropertyValue("list[1].nestedIndexedBean.list[1].name", "name2");
    pvs.addPropertyValue("map[key1].nestedIndexedBean.map[\"key1\"].name", "name1");
    pvs.addPropertyValue("map['key2'].nestedIndexedBean.map[key2].name", "name0");
    bw.setPropertyValues(pvs);
    assertEquals("arrayname5", tb0.getNestedIndexedBean().getArray()[0].getName());
    assertEquals("arrayname4", tb1.getNestedIndexedBean().getArray()[1].getName());
    assertEquals("listname3", ((TestBean) tb2.getNestedIndexedBean().getList().get(0)).getName());
    assertEquals("listname2", ((TestBean) tb3.getNestedIndexedBean().getList().get(1)).getName());
    assertEquals("mapname1", ((TestBean) tb4.getNestedIndexedBean().getMap().get("key1")).getName());
    assertEquals("mapname0", ((TestBean) tb5.getNestedIndexedBean().getMap().get("key2")).getName());
    assertEquals("arrayname5", bw.getPropertyValue("array[0].nestedIndexedBean.array[0].name"));
    assertEquals("arrayname4", bw.getPropertyValue("array[1].nestedIndexedBean.array[1].name"));
    assertEquals("listname3", bw.getPropertyValue("list[0].nestedIndexedBean.list[0].name"));
    assertEquals("listname2", bw.getPropertyValue("list[1].nestedIndexedBean.list[1].name"));
    assertEquals("mapname1", bw.getPropertyValue("map['key1'].nestedIndexedBean.map[key1].name"));
    assertEquals("mapname0", bw.getPropertyValue("map[key2].nestedIndexedBean.map[\"key2\"].name"));
  }
View Full Code Here

Examples of org.springframework.beans.BeanWrapper

      if (target == null) {
        throw new IllegalStateException("Neither BindingResult nor plain target object for bean name '" +
            beanName + "' available as request attribute");
      }
      if (this.expression != null && !"*".equals(this.expression) && !this.expression.endsWith("*")) {
        BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(target);
        this.valueType = bw.getPropertyType(this.expression);
        this.value = bw.getPropertyValue(this.expression);
      }
      this.errorCodes = new String[0];
      this.errorMessages = new String[0];
    }

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.