Package org.apache.commons.beanutils

Examples of org.apache.commons.beanutils.Converter


        ObjectStringConverter converter = new ConvertUtilsObjectStringConverter();
        commonTestForConvertUtilsConverters( converter );
    }
   
    private void commonTestForConvertUtilsConverters(ObjectStringConverter objectStringConverter) {
        Converter converter = new Converter() {
            public Object convert(Class type, Object value) {
                if ( type == SecurityManager.class) {
                    return "Life, The Universe And Everything";
                }
                return "The answer is " + value.toString();
View Full Code Here


    }
   
    public void testDefaultOSConverterDates() {
       
   
        Converter converter = new Converter() {
            public Object convert(Class type, Object value) {
                return "Arthur Dent";
            }
        };
       
        ConvertUtils.register( converter, java.sql.Date.class );
       
        converter = new Converter() {
            public Object convert(Class type, Object value) {
                return "Ford Prefect";
            }
        };
       
        ConvertUtils.register( converter, String.class );
       
        converter = new Converter() {
            public Object convert(Class type, Object value) {
                return "Marvin";
            }
        };
       
View Full Code Here

    public EnumerationConverterTestCase(String name) {
        super(name);
    }

    public void testEnum() {
        Converter converter = EnumerationConverter.getInstance();

        Thread.State expected = Thread.State.TERMINATED;
        Thread.State actual = (Thread.State) converter.convert(Thread.State.class,
                Thread.State.TERMINATED.name());
        assertEquals(expected, actual);
    }
View Full Code Here

    // See http://www.jidesoft.com for licensing terms.

    //
    // Register a converter from a String to a File with PropertyUtils.

    ConvertUtils.register(new Converter() {
      public Object convert(Class arg0, Object filename) {
        return new File((String) filename);
      }
    }, File.class);
View Full Code Here

        if (returnType.equals(Class.class)) {
            value = toQualifiedClassName(value, defaultPackage);
        }

        /* Converter lookup */
        Converter converter = ConvertUtils.lookup(returnType);
        if (converter == null && returnType.isEnum()) {
            converter = EnumerationConverter.getInstance();
        }
       
        return converter.convert(returnType, value);
    }
View Full Code Here

            if (value != null) {
                return value;
            }
        }

        Converter converter = ConvertUtils.lookup(useType);
        if (converter != null) {
            return converter.convert(useType, object);
        }

        throw new JXPathTypeConversionException("Cannot convert "
                + object.getClass() + " to " + useType);
    }
View Full Code Here

            }
        }
       
        if (destType != null)
        {
            Converter converter = ConvertUtils.lookup(destType);
            if (converter == null)
            {
                throw new UnsupportedOperationException("cant deal with " + destType);
            }

            // setting type to null, in fact the documentation is wrong here and this type is never used
            convertedValue = converter.convert(null, convertedValue);
        }
       
       
        return convertedValue;
    }
View Full Code Here

  public double getParameterAsDouble(String name)
  {
    assert name != null;

    Converter c = ConvertUtils.lookup(java.lang.Double.class);

    return ((Double) c.convert(java.lang.Double.class, getParameterAsString(name))).doubleValue();
  }
View Full Code Here

  public float getParameterAsFloat(String name)
  {
    assert name != null;

    Converter c = ConvertUtils.lookup(java.lang.Float.class);

    return ((Float) c.convert(java.lang.Float.class, getParameterAsString(name))).floatValue();
  }
View Full Code Here

  public int getParameterAsInt(String name)
  {
    assert name != null;

    Converter c = ConvertUtils.lookup(java.lang.Integer.class);

    return ((Integer) c.convert(java.lang.Integer.class, getParameterAsString(name))).intValue();
  }
View Full Code Here

TOP

Related Classes of org.apache.commons.beanutils.Converter

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.