Package org.springframework.beans

Examples of org.springframework.beans.SimpleTypeConverter


    BeanFactory beanFactory = getBeanFactory();
    if (beanFactory instanceof ConfigurableBeanFactory) {
      return ((ConfigurableBeanFactory) beanFactory).getTypeConverter();
    }
    else {
      return new SimpleTypeConverter();
    }
  }
View Full Code Here


    if (customConverter != null) {
      return customConverter;
    }
    else {
      // Build default TypeConverter, registering custom editors.
      SimpleTypeConverter typeConverter = new SimpleTypeConverter();
      typeConverter.setConversionService(getConversionService());
      registerCustomEditors(typeConverter);
      return typeConverter;
    }
  }
View Full Code Here

    @Test
    public void registrars() {
        registrars = (PropertyEditorRegistrarsSupport) factory.getBean("propertyEditorRegistrars");
        assertEquals(1, registrars.size());

        SimpleTypeConverter converter = new SimpleTypeConverter();
        registrars.registerCustomEditors(converter);

        // 只注册了long,没注册Long
        try {
            converter.convertIfNecessary("ten", Long.class);
            fail();
        } catch (TypeMismatchException e) {
        }

        assertEquals(new Long(10L), converter.convertIfNecessary("ten", long.class));
    }
View Full Code Here

    @Test
    public void registrarsRef() {
        registrars = (PropertyEditorRegistrarsSupport) factory.getBean("registrarsRef");
        assertEquals(2, registrars.size());

        SimpleTypeConverter converter = new SimpleTypeConverter();
        registrars.registerCustomEditors(converter);

        assertEquals(new Long(10L), converter.convertIfNecessary("ten", Long.class));
        assertEquals(new Long(10L), converter.convertIfNecessary("ten", long.class));
    }
View Full Code Here

    @Test
    public void registerCustomEditors() {
        PropertyEditorRegistrar registrar = new MyPropertyEditorRegistrar();
        formConfig.setPropertyEditorRegistrars(new PropertyEditorRegistrar[] { registrar });

        SimpleTypeConverter registry = new SimpleTypeConverter();
        formConfig.getPropertyEditorRegistrar().registerCustomEditors(registry);

        assertEquals(new Integer(123), registry.convertIfNecessary("anything", Integer.class));
    }
View Full Code Here

        expect(ctx.getField()).andReturn(field).anyTimes();
        expect(ctx.getMessageContext()).andReturn(mctx).anyTimes();
        expect(field.getGroup()).andReturn(group).anyTimes();
        expect(group.getForm()).andReturn(form).anyTimes();
        expect(form.getTypeConverter()).andReturn(new SimpleTypeConverter()).anyTimes();

        replay(ctx, field, group, form);
    }
View Full Code Here

public class ValueListSupportTests {
    private ValueListSupport values;

    @Before
    public void init() {
        values = new ValueListSupport(new SimpleTypeConverter(), true);
    }
View Full Code Here

  /**
   * Return this binder's underlying SimpleTypeConverter.
   */
  protected SimpleTypeConverter getSimpleTypeConverter() {
    if (this.typeConverter == null) {
      this.typeConverter = new SimpleTypeConverter();
      if (this.conversionService != null) {
        this.typeConverter.setConversionService(this.conversionService);
      }
    }
    return this.typeConverter;
View Full Code Here

        boolean changed = false;
        if (value == null) {
            changed = this.configuration.remove(name) != null;
            log.info("Cleared the configuration setting for name ("+name+")");
        } else {
            SimpleTypeConverter converter = new SimpleTypeConverter();
            String sVal = (String)converter.convertIfNecessary(value, String.class);
            changed = loadConfig(name, sVal);
        }
        return changed;
    }
View Full Code Here

        }
        return serviceNameConfigs;
    }

    private <T> T convert(String value, Class<T> type) {
        SimpleTypeConverter converter = new SimpleTypeConverter();

        if (value != null) {
            if (type.isArray()) {
                String[] values = value.split(",");
                return (T)converter.convertIfNecessary(values, type);
            }

            if (type.isAssignableFrom(String.class)) {
                return (T)value;
            }
        } else {
            if (boolean.class.equals(type)) {
                return (T)Boolean.FALSE;
            } else if (int.class.equals(type) || long.class.equals(type)) {
                return (T)converter.convertIfNecessary(0, type);
            }
        }

        return (T)converter.convertIfNecessary(value, type);
    }
View Full Code Here

TOP

Related Classes of org.springframework.beans.SimpleTypeConverter

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.