Package org.springframework.beans

Examples of org.springframework.beans.BeanWrapperImpl$PropertyTokenHolder


    assertEquals("M", editor.getAsText());
  }

  public void testCharacterEditorWithAllowEmpty() {
    CharBean cb = new CharBean();
    BeanWrapper bw = new BeanWrapperImpl(cb);
    bw.registerCustomEditor(Character.class, new CharacterEditor(true));

    bw.setPropertyValue("myCharacter", new Character('c'));
    assertEquals(new Character('c'), cb.getMyCharacter());

    bw.setPropertyValue("myCharacter", "c");
    assertEquals(new Character('c'), cb.getMyCharacter());

    bw.setPropertyValue("myCharacter", "\u0041");
    assertEquals(new Character('A'), cb.getMyCharacter());

    bw.setPropertyValue("myCharacter", " ");
    assertEquals(new Character(' '), cb.getMyCharacter());

    bw.setPropertyValue("myCharacter", "");
    assertNull(cb.getMyCharacter());
  }
View Full Code Here


    assertEquals("", editor.getAsText());
  }

  public void testIndexedPropertiesWithCustomEditorForType() {
    IndexedTestBean bean = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(bean);
    bw.registerCustomEditor(String.class, new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("prefix" + text);
      }
    });
    TestBean tb0 = bean.getArray()[0];
    TestBean tb1 = bean.getArray()[1];
    TestBean tb2 = ((TestBean) bean.getList().get(0));
    TestBean tb3 = ((TestBean) bean.getList().get(1));
    TestBean tb4 = ((TestBean) bean.getMap().get("key1"));
    TestBean tb5 = ((TestBean) bean.getMap().get("key2"));
    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].name"));
    assertEquals("name1", bw.getPropertyValue("array[1].name"));
    assertEquals("name2", bw.getPropertyValue("list[0].name"));
    assertEquals("name3", bw.getPropertyValue("list[1].name"));
    assertEquals("name4", bw.getPropertyValue("map[key1].name"));
    assertEquals("name5", bw.getPropertyValue("map[key2].name"));
    assertEquals("name4", bw.getPropertyValue("map['key1'].name"));
    assertEquals("name5", bw.getPropertyValue("map[\"key2\"].name"));

    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("array[0].name", "name5");
    pvs.addPropertyValue("array[1].name", "name4");
    pvs.addPropertyValue("list[0].name", "name3");
    pvs.addPropertyValue("list[1].name", "name2");
    pvs.addPropertyValue("map[key1].name", "name1");
    pvs.addPropertyValue("map['key2'].name", "name0");
    bw.setPropertyValues(pvs);
    assertEquals("prefixname5", tb0.getName());
    assertEquals("prefixname4", tb1.getName());
    assertEquals("prefixname3", tb2.getName());
    assertEquals("prefixname2", tb3.getName());
    assertEquals("prefixname1", tb4.getName());
    assertEquals("prefixname0", tb5.getName());
    assertEquals("prefixname5", bw.getPropertyValue("array[0].name"));
    assertEquals("prefixname4", bw.getPropertyValue("array[1].name"));
    assertEquals("prefixname3", bw.getPropertyValue("list[0].name"));
    assertEquals("prefixname2", bw.getPropertyValue("list[1].name"));
    assertEquals("prefixname1", bw.getPropertyValue("map[\"key1\"].name"));
    assertEquals("prefixname0", bw.getPropertyValue("map['key2'].name"));
  }
View Full Code Here

    assertEquals("prefixname0", bw.getPropertyValue("map['key2'].name"));
  }

  public void testIndexedPropertiesWithCustomEditorForProperty() {
    IndexedTestBean bean = new IndexedTestBean(false);
    BeanWrapper bw = new BeanWrapperImpl(bean);
    bw.registerCustomEditor(String.class, "array.name", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("array" + text);
      }
    });
    bw.registerCustomEditor(String.class, "list.name", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("list" + text);
      }
    });
    bw.registerCustomEditor(String.class, "map.name", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("map" + text);
      }
    });
    bean.populate();

    TestBean tb0 = bean.getArray()[0];
    TestBean tb1 = bean.getArray()[1];
    TestBean tb2 = ((TestBean) bean.getList().get(0));
    TestBean tb3 = ((TestBean) bean.getList().get(1));
    TestBean tb4 = ((TestBean) bean.getMap().get("key1"));
    TestBean tb5 = ((TestBean) bean.getMap().get("key2"));
    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].name"));
    assertEquals("name1", bw.getPropertyValue("array[1].name"));
    assertEquals("name2", bw.getPropertyValue("list[0].name"));
    assertEquals("name3", bw.getPropertyValue("list[1].name"));
    assertEquals("name4", bw.getPropertyValue("map[key1].name"));
    assertEquals("name5", bw.getPropertyValue("map[key2].name"));
    assertEquals("name4", bw.getPropertyValue("map['key1'].name"));
    assertEquals("name5", bw.getPropertyValue("map[\"key2\"].name"));

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

    assertEquals("mapname0", bw.getPropertyValue("map['key2'].name"));
  }

  public void testIndexedPropertiesWithIndividualCustomEditorForProperty() {
    IndexedTestBean bean = new IndexedTestBean(false);
    BeanWrapper bw = new BeanWrapperImpl(bean);
    bw.registerCustomEditor(String.class, "array[0].name", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("array0" + text);
      }
    });
    bw.registerCustomEditor(String.class, "array[1].name", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("array1" + text);
      }
    });
    bw.registerCustomEditor(String.class, "list[0].name", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("list0" + text);
      }
    });
    bw.registerCustomEditor(String.class, "list[1].name", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("list1" + text);
      }
    });
    bw.registerCustomEditor(String.class, "map[key1].name", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("mapkey1" + text);
      }
    });
    bw.registerCustomEditor(String.class, "map[key2].name", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("mapkey2" + text);
      }
    });
    bean.populate();

    TestBean tb0 = bean.getArray()[0];
    TestBean tb1 = bean.getArray()[1];
    TestBean tb2 = ((TestBean) bean.getList().get(0));
    TestBean tb3 = ((TestBean) bean.getList().get(1));
    TestBean tb4 = ((TestBean) bean.getMap().get("key1"));
    TestBean tb5 = ((TestBean) bean.getMap().get("key2"));
    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].name"));
    assertEquals("name1", bw.getPropertyValue("array[1].name"));
    assertEquals("name2", bw.getPropertyValue("list[0].name"));
    assertEquals("name3", bw.getPropertyValue("list[1].name"));
    assertEquals("name4", bw.getPropertyValue("map[key1].name"));
    assertEquals("name5", bw.getPropertyValue("map[key2].name"));
    assertEquals("name4", bw.getPropertyValue("map['key1'].name"));
    assertEquals("name5", bw.getPropertyValue("map[\"key2\"].name"));

    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("array[0].name", "name5");
    pvs.addPropertyValue("array[1].name", "name4");
    pvs.addPropertyValue("list[0].name", "name3");
    pvs.addPropertyValue("list[1].name", "name2");
    pvs.addPropertyValue("map[key1].name", "name1");
    pvs.addPropertyValue("map['key2'].name", "name0");
    bw.setPropertyValues(pvs);
    assertEquals("array0name5", tb0.getName());
    assertEquals("array1name4", tb1.getName());
    assertEquals("list0name3", tb2.getName());
    assertEquals("list1name2", tb3.getName());
    assertEquals("mapkey1name1", tb4.getName());
    assertEquals("mapkey2name0", tb5.getName());
    assertEquals("array0name5", bw.getPropertyValue("array[0].name"));
    assertEquals("array1name4", bw.getPropertyValue("array[1].name"));
    assertEquals("list0name3", bw.getPropertyValue("list[0].name"));
    assertEquals("list1name2", bw.getPropertyValue("list[1].name"));
    assertEquals("mapkey1name1", bw.getPropertyValue("map[\"key1\"].name"));
    assertEquals("mapkey2name0", bw.getPropertyValue("map['key2'].name"));
  }
View Full Code Here

    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

    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[0].nestedIndexedBean.array[0].name", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("array" + text);
      }
    });
    bw.registerCustomEditor(String.class, "list.nestedIndexedBean.list[1].name", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("list" + text);
      }
    });
    bw.registerCustomEditor(String.class, "map[key1].nestedIndexedBean.map.name", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("map" + text);
      }
    });

    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("name4", tb1.getNestedIndexedBean().getArray()[1].getName());
    assertEquals("name3", ((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());
View Full Code Here

    assertEquals("name0", ((TestBean) tb5.getNestedIndexedBean().getMap().get("key2")).getName());
  }

  public void testIndexedPropertiesWithDirectAccessAndPropertyEditors() {
    IndexedTestBean bean = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(bean);
    bw.registerCustomEditor(TestBean.class, "array", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue(new TestBean("array" + text, 99));
      }

      public String getAsText() {
        return ((TestBean) getValue()).getName();
      }
    });
    bw.registerCustomEditor(TestBean.class, "list", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue(new TestBean("list" + text, 99));
      }

      public String getAsText() {
        return ((TestBean) getValue()).getName();
      }
    });
    bw.registerCustomEditor(TestBean.class, "map", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue(new TestBean("map" + text, 99));
      }

      public String getAsText() {
        return ((TestBean) getValue()).getName();
      }
    });

    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("array[0]", "a");
    pvs.addPropertyValue("array[1]", "b");
    pvs.addPropertyValue("list[0]", "c");
    pvs.addPropertyValue("list[1]", "d");
    pvs.addPropertyValue("map[key1]", "e");
    pvs.addPropertyValue("map['key2']", "f");
    bw.setPropertyValues(pvs);
    assertEquals("arraya", bean.getArray()[0].getName());
    assertEquals("arrayb", bean.getArray()[1].getName());
    assertEquals("listc", ((TestBean) bean.getList().get(0)).getName());
    assertEquals("listd", ((TestBean) bean.getList().get(1)).getName());
    assertEquals("mape", ((TestBean) bean.getMap().get("key1")).getName());
View Full Code Here

    assertEquals("mapf", ((TestBean) bean.getMap().get("key2")).getName());
  }

  public void testIndexedPropertiesWithDirectAccessAndSpecificPropertyEditors() {
    IndexedTestBean bean = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(bean);
    bw.registerCustomEditor(TestBean.class, "array[0]", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue(new TestBean("array0" + text, 99));
      }

      public String getAsText() {
        return ((TestBean) getValue()).getName();
      }
    });
    bw.registerCustomEditor(TestBean.class, "array[1]", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue(new TestBean("array1" + text, 99));
      }

      public String getAsText() {
        return ((TestBean) getValue()).getName();
      }
    });
    bw.registerCustomEditor(TestBean.class, "list[0]", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue(new TestBean("list0" + text, 99));
      }

      public String getAsText() {
        return ((TestBean) getValue()).getName();
      }
    });
    bw.registerCustomEditor(TestBean.class, "list[1]", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue(new TestBean("list1" + text, 99));
      }

      public String getAsText() {
        return ((TestBean) getValue()).getName();
      }
    });
    bw.registerCustomEditor(TestBean.class, "map[key1]", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue(new TestBean("mapkey1" + text, 99));
      }

      public String getAsText() {
        return ((TestBean) getValue()).getName();
      }
    });
    bw.registerCustomEditor(TestBean.class, "map[key2]", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue(new TestBean("mapkey2" + text, 99));
      }

      public String getAsText() {
        return ((TestBean) getValue()).getName();
      }
    });

    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("array[0]", "a");
    pvs.addPropertyValue("array[1]", "b");
    pvs.addPropertyValue("list[0]", "c");
    pvs.addPropertyValue("list[1]", "d");
    pvs.addPropertyValue("map[key1]", "e");
    pvs.addPropertyValue("map['key2']", "f");
    bw.setPropertyValues(pvs);
    assertEquals("array0a", bean.getArray()[0].getName());
    assertEquals("array1b", bean.getArray()[1].getName());
    assertEquals("list0c", ((TestBean) bean.getList().get(0)).getName());
    assertEquals("list1d", ((TestBean) bean.getList().get(1)).getName());
    assertEquals("mapkey1e", ((TestBean) bean.getMap().get("key1")).getName());
View Full Code Here

    assertEquals("mapkey2f", ((TestBean) bean.getMap().get("key2")).getName());
  }

  public void testIndexedPropertiesWithListPropertyEditor() {
    IndexedTestBean bean = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(bean);
    bw.registerCustomEditor(List.class, "list", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        List result = new ArrayList();
        result.add(new TestBean("list" + text, 99));
        setValue(result);
      }
    });
    bw.setPropertyValue("list", "1");
    assertEquals("list1", ((TestBean) bean.getList().get(0)).getName());
    bw.setPropertyValue("list[0]", "test");
    assertEquals("test", bean.getList().get(0));
  }
View Full Code Here

    assertEquals("test", bean.getList().get(0));
  }

  public void testConversionToOldCollections() throws PropertyVetoException {
    OldCollectionsBean tb = new OldCollectionsBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.registerCustomEditor(Vector.class, new CustomCollectionEditor(Vector.class));
    bw.registerCustomEditor(Hashtable.class, new CustomMapEditor(Hashtable.class));

    bw.setPropertyValue("vector", new String[] {"a", "b"});
    assertEquals(2, tb.getVector().size());
    assertEquals("a", tb.getVector().get(0));
    assertEquals("b", tb.getVector().get(1));

    bw.setPropertyValue("hashtable", Collections.singletonMap("foo", "bar"));
    assertEquals(1, tb.getHashtable().size());
    assertEquals("bar", tb.getHashtable().get("foo"));
  }
View Full Code Here

TOP

Related Classes of org.springframework.beans.BeanWrapperImpl$PropertyTokenHolder

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.