Package org.springframework.binding.convert

Examples of org.springframework.binding.convert.ConversionExecutor


  private Expression parseFieldExpression(String field) {
    return expressionParser.parseExpression(field, new FluentParserContext().evaluate(boundObject.getClass()));
  }

  private Object getFormattedValue(Expression fieldExpression) {
    ConversionExecutor converter = getConverter(fieldExpression);
    if (converter != null) {
      return converter.execute(fieldExpression.getValue(boundObject));
    } else {
      return fieldExpression.getValue(boundObject);
    }
  }
View Full Code Here


  }

  private void parseAndSetMappingConversionExecutor(AbstractMappingModel mappingModel, DefaultMapping mapping) {
    if (StringUtils.hasText(mappingModel.getType())) {
      Class type = toClass(mappingModel.getType());
      ConversionExecutor typeConverter = new RuntimeBindingConversionExecutor(type, getLocalContext()
          .getConversionService());
      mapping.setTypeConverter(typeConverter);
    }
  }
View Full Code Here

    }
  }

  public void testValidConversion() {
    DefaultConversionService service = new DefaultConversionService();
    ConversionExecutor executor = service.getConversionExecutor(String.class, Integer.class);
    Integer three = (Integer) executor.execute("3");
    assertEquals(3, three.intValue());

    ConversionExecutor executor2 = service.getConversionExecutor(Integer.class, String.class);
    String threeString = (String) executor2.execute(new Integer(3));
    assertEquals("3", threeString);
  }
View Full Code Here

  public void setValue(Object context, Object value) {
    try {
      BeanWrapperImpl beanWrapper = new BeanWrapperImpl(context);
      Set converters = conversionService.getConversionExecutors(String.class);
      for (Iterator it = converters.iterator(); it.hasNext();) {
        ConversionExecutor converter = (ConversionExecutor) it.next();
        beanWrapper.registerCustomEditor(converter.getTargetClass(), new PropertyEditorConverter(converter));
      }
      beanWrapper.setPropertyValue(expression, value);
    } catch (NotWritablePropertyException e) {
      throw new PropertyNotFoundException(context.getClass(), expression, e);
    } catch (TypeMismatchException e) {
View Full Code Here

    FormattedStringToNumber converter = new FormattedStringToNumber();
    DefaultNumberFormatFactory numberFormatFactory = new DefaultNumberFormatFactory();
    numberFormatFactory.setLocale(Locale.US);
    converter.setNumberFormatFactory(numberFormatFactory);
    service.addConverter(converter);
    ConversionExecutor executor = service.getConversionExecutor(String.class, Integer.class);
    Integer three = (Integer) executor.execute("3,000");
    assertEquals(3000, three.intValue());
    ConversionExecutor executor2 = service.getConversionExecutor(Integer.class, String.class);
    String string = (String) executor2.execute(new Integer(3000));
    assertEquals("3,000", string);
  }
View Full Code Here

    FormattedStringToNumber converter = new FormattedStringToNumber();
    DefaultNumberFormatFactory numberFormatFactory = new DefaultNumberFormatFactory();
    numberFormatFactory.setLocale(Locale.US);
    converter.setNumberFormatFactory(numberFormatFactory);
    service.addConverter("usaNumber", converter);
    ConversionExecutor executor = service.getConversionExecutor("usaNumber", String.class, Integer.class);
    Integer three = (Integer) executor.execute("3,000");
    assertEquals(3000, three.intValue());
    ConversionExecutor executor2 = service.getConversionExecutor("usaNumber", Integer.class, String.class);
    String string = (String) executor2.execute(new Integer(3000));
    assertEquals("3,000", string);
  }
View Full Code Here

  }

  public void testRegisterCustomConverterForSameType() {
    DefaultConversionService service = new DefaultConversionService();
    service.addConverter("trimmer", new Trimmer());
    ConversionExecutor executor = service.getConversionExecutor("trimmer", String.class, String.class);
    assertEquals("a string", executor.execute("a string   "));
  }
View Full Code Here

  }

  public void testRegisterCustomConverterReverseComparsion() {
    DefaultConversionService service = new DefaultConversionService();
    service.addConverter("princy", new CustomTwoWayConverter());
    ConversionExecutor executor = service.getConversionExecutor("princy", Principal.class, String.class);
    assertEquals("name", executor.execute(new Principal() {
      public String getName() {
        return "name";
      }
    }));
  }
View Full Code Here

    }
  }

  public void testConversionPrimitive() {
    DefaultConversionService service = new DefaultConversionService();
    ConversionExecutor executor = service.getConversionExecutor(String.class, int.class);
    Integer three = (Integer) executor.execute("3");
    assertEquals(3, three.intValue());
  }
View Full Code Here

    assertEquals(3, three.intValue());
  }

  public void testArrayConversion() {
    DefaultConversionService service = new DefaultConversionService();
    ConversionExecutor executor = service.getConversionExecutor(String[].class, Integer[].class);
    Integer[] result = (Integer[]) executor.execute(new String[] { "1", "2", "3" });
    assertEquals(new Integer(1), result[0]);
    assertEquals(new Integer(2), result[1]);
    assertEquals(new Integer(3), result[2]);
  }
View Full Code Here

TOP

Related Classes of org.springframework.binding.convert.ConversionExecutor

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.