Package org.springframework.beans

Examples of org.springframework.beans.BeanWrapperImpl$OptionalUnwrapper


  }

  public void testCustomNumberEditorWithoutAllowEmpty() {
    NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN);
    NumberTestBean tb = new NumberTestBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.registerCustomEditor(short.class, new CustomNumberEditor(Short.class, nf, false));
    bw.registerCustomEditor(Short.class, new CustomNumberEditor(Short.class, nf, false));
    bw.registerCustomEditor(int.class, new CustomNumberEditor(Integer.class, nf, false));
    bw.registerCustomEditor(Integer.class, new CustomNumberEditor(Integer.class, nf, false));
    bw.registerCustomEditor(long.class, new CustomNumberEditor(Long.class, nf, false));
    bw.registerCustomEditor(Long.class, new CustomNumberEditor(Long.class, nf, false));
    bw.registerCustomEditor(BigInteger.class, new CustomNumberEditor(BigInteger.class, nf, false));
    bw.registerCustomEditor(float.class, new CustomNumberEditor(Float.class, nf, false));
    bw.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, nf, false));
    bw.registerCustomEditor(double.class, new CustomNumberEditor(Double.class, nf, false));
    bw.registerCustomEditor(Double.class, new CustomNumberEditor(Double.class, nf, false));
    bw.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, nf, false));

    bw.setPropertyValue("short1", "1");
    bw.setPropertyValue("short2", "2");
    bw.setPropertyValue("int1", "7");
    bw.setPropertyValue("int2", "8");
    bw.setPropertyValue("long1", "5");
    bw.setPropertyValue("long2", "6");
    bw.setPropertyValue("bigInteger", "3");
    bw.setPropertyValue("float1", "7,1");
    bw.setPropertyValue("float2", "8,1");
    bw.setPropertyValue("double1", "5,1");
    bw.setPropertyValue("double2", "6,1");
    bw.setPropertyValue("bigDecimal", "4,5");

    assertTrue("Correct short1 value", new Short("1").equals(bw.getPropertyValue("short1")));
    assertTrue("Correct short1 value", tb.getShort1() == 1);
    assertTrue("Correct short2 value", new Short("2").equals(bw.getPropertyValue("short2")));
    assertTrue("Correct short2 value", new Short("2").equals(tb.getShort2()));
    assertTrue("Correct int1 value", new Integer("7").equals(bw.getPropertyValue("int1")));
    assertTrue("Correct int1 value", tb.getInt1() == 7);
    assertTrue("Correct int2 value", new Integer("8").equals(bw.getPropertyValue("int2")));
    assertTrue("Correct int2 value", new Integer("8").equals(tb.getInt2()));
    assertTrue("Correct long1 value", new Long("5").equals(bw.getPropertyValue("long1")));
    assertTrue("Correct long1 value", tb.getLong1() == 5);
    assertTrue("Correct long2 value", new Long("6").equals(bw.getPropertyValue("long2")));
    assertTrue("Correct long2 value", new Long("6").equals(tb.getLong2()));
    assertTrue("Correct bigInteger value", new BigInteger("3").equals(bw.getPropertyValue("bigInteger")));
    assertTrue("Correct bigInteger value", new BigInteger("3").equals(tb.getBigInteger()));
    assertTrue("Correct float1 value", new Float("7.1").equals(bw.getPropertyValue("float1")));
    assertTrue("Correct float1 value", new Float("7.1").equals(new Float(tb.getFloat1())));
    assertTrue("Correct float2 value", new Float("8.1").equals(bw.getPropertyValue("float2")));
    assertTrue("Correct float2 value", new Float("8.1").equals(tb.getFloat2()));
    assertTrue("Correct double1 value", new Double("5.1").equals(bw.getPropertyValue("double1")));
    assertTrue("Correct double1 value", tb.getDouble1() == 5.1);
    assertTrue("Correct double2 value", new Double("6.1").equals(bw.getPropertyValue("double2")));
    assertTrue("Correct double2 value", new Double("6.1").equals(tb.getDouble2()));
    assertTrue("Correct bigDecimal value", new BigDecimal("4.5").equals(bw.getPropertyValue("bigDecimal")));
    assertTrue("Correct bigDecimal value", new BigDecimal("4.5").equals(tb.getBigDecimal()));
  }
View Full Code Here


  }

  public void testCustomNumberEditorWithAllowEmpty() {
    NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN);
    NumberTestBean tb = new NumberTestBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.registerCustomEditor(long.class, new CustomNumberEditor(Long.class, nf, true));
    bw.registerCustomEditor(Long.class, new CustomNumberEditor(Long.class, nf, true));

    bw.setPropertyValue("long1", "5");
    bw.setPropertyValue("long2", "6");
    assertTrue("Correct long1 value", new Long("5").equals(bw.getPropertyValue("long1")));
    assertTrue("Correct long1 value", tb.getLong1() == 5);
    assertTrue("Correct long2 value", new Long("6").equals(bw.getPropertyValue("long2")));
    assertTrue("Correct long2 value", new Long("6").equals(tb.getLong2()));

    bw.setPropertyValue("long2", "");
    assertTrue("Correct long2 value", bw.getPropertyValue("long2") == null);
    assertTrue("Correct long2 value", tb.getLong2() == null);

    try {
      bw.setPropertyValue("long1", "");
      fail("Should have thrown BeansException");
    }
    catch (BeansException ex) {
      // expected
      assertTrue("Correct long1 value", new Long("5").equals(bw.getPropertyValue("long1")));
      assertTrue("Correct long1 value", tb.getLong1() == 5);
    }
  }
View Full Code Here

  }

  public void testCustomNumberEditorWithFrenchBigDecimal() throws Exception {
    NumberFormat nf = NumberFormat.getNumberInstance(Locale.FRENCH);
    NumberTestBean tb = new NumberTestBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, nf, true));
    bw.setPropertyValue("bigDecimal", "1000");
    assertEquals(1000.0f, tb.getBigDecimal().floatValue(), 0f);
    bw.setPropertyValue("bigDecimal", "1000,5");
    assertEquals(1000.5f, tb.getBigDecimal().floatValue(), 0f);
    bw.setPropertyValue("bigDecimal", "1 000,5");
    assertEquals(1000.5f, tb.getBigDecimal().floatValue(), 0f);
  }
View Full Code Here

    }

    protected EnvironmentTemplate parseRoot(Element root) {

        EnvironmentTemplate result = new EnvironmentTemplate();
        BeanWrapper beanWrapper = new BeanWrapperImpl(result);
        result.setName(root.getAttribute("env-name"));
        String cygwinAttribute = root.getAttribute("cygwin");
        if (cygwinAttribute != null && cygwinAttribute.length() > 0)
            beanWrapper.setPropertyValue("cygwin", cygwinAttribute);

        NodeList nl = root.getChildNodes();
        Map<String, VariableDefinition> definitions = new LinkedHashMap<String, VariableDefinition>();
        Map<String, VariableDefinition> rDefinitions = new LinkedHashMap<String, VariableDefinition>();
View Full Code Here

    }

    private VariableDefinition importVariableDefinition(Element element) {
        VariableDefinition result = new VariableDefinition();

        BeanWrapper beanWrapper = new BeanWrapperImpl(result);

        final Boolean optional = element.getAttribute("optional") == null ? false : true;             

        beanWrapper.setPropertyValue("variableName", element.getAttribute("var-name"));
        beanWrapper.setPropertyValue("optional", optional);
        beanWrapper.setPropertyValue("path", element.getAttribute("path"));

        NodeList childNodes = element.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node node = childNodes.item(i);
            if ("description".equals(node.getNodeName())) {
View Full Code Here

        return result;
    }

    private CalculatedVariableDefinition importVariableCalculation(Element element) {
        CalculatedVariableDefinition result = new CalculatedVariableDefinition();
        BeanWrapper beanWrapper = new BeanWrapperImpl(result);
        beanWrapper.setPropertyValue("variableName", element.getAttribute("var-name"));
        beanWrapper.setPropertyValue("path", element.getAttribute("path"));

        NodeList childNodes = element.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node node = childNodes.item(i);
            if ("description".equals(node.getNodeName())) {
View Full Code Here

        }
        return result;
    }

    private void setProperty(Object object, Element element) {
        BeanWrapper beanWrapper = new BeanWrapperImpl(object);
        NodeList childNodes = element.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node node = childNodes.item(i);
            if ("value".equals(node.getNodeName())) {
                String value = node.getTextContent();
                beanWrapper.setPropertyValue(element.getAttribute("name"), value);
            }
        }
    }
View Full Code Here

    }.runTest();
  }

  public void testByteArrayPropertyEditor() {
    PrimitiveArrayBean bean = new PrimitiveArrayBean();
    BeanWrapper bw = new BeanWrapperImpl(bean);
    bw.setPropertyValue("byteArray", "myvalue");
    assertEquals("myvalue", new String(bean.getByteArray()));
  }
View Full Code Here

    assertEquals("myvalue", new String(bean.getByteArray()));
  }

  public void testCharArrayPropertyEditor() {
    PrimitiveArrayBean bean = new PrimitiveArrayBean();
    BeanWrapper bw = new BeanWrapperImpl(bean);
    bw.setPropertyValue("charArray", "myvalue");
    assertEquals("myvalue", new String(bean.getCharArray()));
  }
View Full Code Here

    assertEquals("myvalue", new String(bean.getCharArray()));
  }

  public void testCharacterEditor() {
    CharBean cb = new CharBean();
    BeanWrapper bw = new BeanWrapperImpl(cb);

    bw.setPropertyValue("myChar", new Character('c'));
    assertEquals('c', cb.getMyChar());

    bw.setPropertyValue("myChar", "c");
    assertEquals('c', cb.getMyChar());

    bw.setPropertyValue("myChar", "\u0041");
    assertEquals('A', cb.getMyChar());

    bw.setPropertyValue("myChar", "\\u0022");
    assertEquals('"', cb.getMyChar());
   
    CharacterEditor editor = new CharacterEditor(false);
    editor.setAsText("M");
    assertEquals("M", editor.getAsText());
View Full Code Here

TOP

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

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.