Spring Framework SimpleTypeConverter - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework SimpleTypeConverter class.

This code example shows how to use the following methods:
public class ValueListSupportTests { 
    private ValueListSupport values; 
 
    @Before 
    public void init() { 
        values = new ValueListSupport(new SimpleTypeConverter(), true); 
    } 
 
    @Test 
    public void getFileItem() { 
        FileItem item = createMock(FileItem.class); 
 
        values.addValue(item); 
 
        assertSame(item, values.getFileItem()); 
    } 
 
    @Test 
    public void getFileItem_nonFileItem() { 
        values.addValue("str"); 
6
CodeRank
This code example shows how to use the following methods:
 * Copied from Spring Integration for purposes of reproducing 
 * {@link Spr7538Tests}. 
 */ 
class BeanFactoryTypeConverter implements TypeConverter, BeanFactoryAware {
 
	private SimpleTypeConverter delegate = new SimpleTypeConverter();
 
	private static ConversionService defaultConversionService;
 
	private ConversionService conversionService;
 
	public BeanFactoryTypeConverter() { 
		synchronized (this) {
			if (defaultConversionService == null) {
				defaultConversionService = new DefaultConversionService();
			} 
		} 
		this.conversionService = defaultConversionService;
	} 
 
6
CodeRank
This code example shows how to use the following methods:
 
        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); 
    } 
 
    @Test 
    public void init_expression() throws Exception { 
        // empty expression 
        JexlCondition cond = new JexlCondition(null); 
 
        try { 
            cond.afterPropertiesSet(); 
            fail(); 
        } catch (IllegalArgumentException e) { 
            assertThat(e, exception("missing condition expression")); 
6
CodeRank
This code example shows how to use the following methods:
	 * The default implementation builds a 
	 * {@link org.springframework.beans.SimpleTypeConverter}. 
	 * Can be overridden in subclasses. 
	 */ 
	protected TypeConverter getDefaultTypeConverter() {
		return new SimpleTypeConverter();
	} 
 
	/** 
	 * Register the given custom property editor for all properties of the given type. 
	 * <p>Typically used in conjunction with the default 
	 * {@link org.springframework.beans.SimpleTypeConverter}; will work with any 
	 * TypeConverter that implements the PropertyEditorRegistry interface as well. 
	 * @param requiredType type of the property 
	 * @param propertyEditor editor to register 
	 * @see #setTypeConverter 
	 * @see org.springframework.beans.PropertyEditorRegistry#registerCustomEditor 
	 */ 
	public void registerCustomEditor(Class<?> requiredType, PropertyEditor propertyEditor) {
		TypeConverter converter = getTypeConverter();
5
CodeRank
This code example shows how to use the following methods:
            inf.end();
        } 
    } 
 
    protected final TypeConverter getTypeConverter() {
        SimpleTypeConverter typeConverter = new SimpleTypeConverter();
        propertyEditorRegistrars.registerCustomEditors(typeConverter);
        return typeConverter;
    } 
 
    protected final String convertToString(Class<?> type, Object value, TypeConverter converter) {
        if (value instanceof String) {
            return (String) value;
        } else { 
            if (converter instanceof PropertyEditorRegistry && type != null && type.isInstance(value)) {
                PropertyEditor editor = ((PropertyEditorRegistry) converter).findCustomEditor(type, null);
 
                if (editor != null) {
                    editor.setValue(value);
                    return editor.getAsText();
5
CodeRank
This code example shows how to use the following methods:
            return false; 
        } else if (value instanceof Boolean) {
            return (Boolean) value;
        } else { 
            try { 
                return (Boolean) new SimpleTypeConverter().convertIfNecessary(value, Boolean.class);
            } catch (TypeMismatchException e) {
                throw new PipelineException( 
                        "Failed to evaluating expression for JexlCondition into a boolean value: \"" 
                        + getEscapedExpression(expressionString) + "\"", e);
            } 
        } 
    } 
 
    @Override 
    public String toString() {
        return "JexlCondition[" + getEscapedExpression(expressionString) + "]";
    } 
 
    private String getEscapedExpression(String expr) {
5
CodeRank
This code example shows how to use the following methods:
 */ 
public class BeanFactoryTypeConverter implements TypeConverter, BeanFactoryAware {
 
	private static ConversionService defaultConversionService;
 
	private volatile SimpleTypeConverter delegate = new SimpleTypeConverter();
 
	private volatile boolean haveCalledDelegateGetDefaultEditor;
 
	private volatile ConversionService conversionService;
 
	/** 
	 * Instantiates a new bean factory type converter. 
	 */ 
	public BeanFactoryTypeConverter() { 
		synchronized (BeanFactoryTypeConverter.class) { 
			if (defaultConversionService == null) {
				defaultConversionService = new DefaultConversionService();
			} 
		} 
3
CodeRank
This code example shows how to use the following methods:
    private Object convertId(String idString, Class<?> clazz) {
        Object id;
        try{ 
            id = Formatters.conversion.convert(idString, modelInfo.getId().getFieldClass());
        }catch (Exception e) {
            id = new SimpleTypeConverter().convertIfNecessary(idString, modelInfo.getId().getFieldClass());
        } 
        return id;
    } 
 
    public Object getId() {
        String idString = form.field(modelInfo.getId().getField().getName()).value();
        return convertId(idString, modelInfo.getId().getFieldClass());
    } 
 
    public String getUrlId() {
        return Formatters.print(getId()); 
    } 
 
    public String getRowId() {
3
CodeRank
This code example shows how to use the following methods:
	 * Gets the {@link SimpleTypeConverter} that should be used for conversion. 
	 * @return the simple type converter 
	 */ 
	protected SimpleTypeConverter getSimpleTypeConverter() {
		if (this.simpleTypeConverter == null) {
			this.simpleTypeConverter = new SimpleTypeConverter();
		} 
		return this.simpleTypeConverter;
	} 
 
	/** 
	 * Find a default editor for the given type. This code is based on <tt>TypeConverterDelegate.findDefaultEditor</tt>. 
	 * @param requiredType the type to find an editor for 
	 * @param typeDescriptor the type description of the property 
	 * @return the corresponding editor, or <code>null</code> if none 
	 *  
	 * @param propertyEditorRegistry 
	 * @param targetObject 
	 *  
	 * @author Juergen Hoeller 
4
CodeRank
This code example shows how to use the following methods:registerCustomEditor
    protected final Map<String, String> parameterKeys = createLinkedHashMap();
    protected final ParserRequestContext requestContext;
 
    public AbstractValueParser(ParserRequestContext requestContext) {
        this.requestContext = requestContext;
        this.converter = new SimpleTypeConverter();
        this.converter.registerCustomEditor(String.class, new StringFileItemEditor());
 
        if (requestContext.getPropertyEditorRegistrar() != null) {
            requestContext.getPropertyEditorRegistrar().registerCustomEditors(converter);
        } 
    } 
 
    protected abstract Logger getLogger(); 
 
    public TypeConverter getTypeConverter() {
        return converter;
    } 
 
    // ============================================================= 
4
CodeRank