public ValueConverter getValueConverter( final Class c ) { final ValueConverter plain = registeredClasses.get( c ); if ( plain != null ) { return plain; } if ( c.isArray() ) { final Class componentType = c.getComponentType(); final ValueConverter componentConverter = getValueConverter( componentType ); if ( componentConverter != null ) { return new ArrayValueConverter( componentType, componentConverter ); } } if ( c.isEnum() ) { return new EnumValueConverter( c ); } return null; }
/** * Converts an object to an attribute value. * * @param o * the object. * @return the attribute value. * @throws BeanException * if there was an error during the conversion. */ public static String toAttributeValue( final Object o ) throws BeanException { if ( o == null ) { return null; } final ValueConverter vc = ConverterRegistry.getInstance().getValueConverter( o.getClass() ); if ( vc == null ) { return null; } return vc.toAttributeValue( o ); }
/** * Converts a string to a property value. * * @param s * the string. * @param c * the target class. * @return the object converted from the given string into a object of the target class. * @throws BeanException * if there was an error during the conversion. */ public static Object toPropertyValue( final String s, final Class c ) throws BeanException { if ( s == null ) { return null; } if ( c == null ) { return null; } final ValueConverter vc = ConverterRegistry.getInstance().getValueConverter( c ); if ( vc == null ) { return null; } return vc.toPropertyValue( s ); }
public void setPropertyAsString( final String name, final Class type, final String txt ) throws BeanException { if ( name == null ) { throw new NullPointerException( "Name must not be null" ); } if ( type == null ) { throw new NullPointerException( "Type must not be null" ); } if ( txt == null ) { throw new NullPointerException( "Text must not be null" ); } final PropertySpecification ps = new PropertySpecification( name ); final ValueConverter vc; if ( ps.getIndex() != null && type.isArray() ) { vc = ConverterRegistry.getInstance().getValueConverter( type.getComponentType() ); } else { vc = ConverterRegistry.getInstance().getValueConverter( type ); } if ( vc == null ) { throw new BeanException( "Unable to handle '" + type + "' for property '" + name + '\'' ); } final Object o = vc.toPropertyValue( txt ); setProperty( ps, o ); }
public String getPropertyAsString( final String name ) throws BeanException { final PropertySpecification ps = new PropertySpecification( name ); final PropertyDescriptor pd = properties.get( ps.getName() ); if ( pd == null ) { throw new BeanException( "No such property:" + name ); } final Object o = getPropertyForSpecification( ps ); if ( o == null ) { return null; } final ValueConverter vc = ConverterRegistry.getInstance().getValueConverter( o.getClass() ); if ( vc == null ) { throw new BeanException( "Unable to handle property of type " + o.getClass().getName() ); } return vc.toAttributeValue( o ); }
final ClassLoader classLoader = ObjectUtilities.getClassLoader( getClass() ); final Class c = Class.forName( className ); valueType = ConverterRegistry.getInstance().getValueConverter( c ); if ( valueType == null ) { PropertyReferenceReadHandler.logger.warn( "Unable to find a suitable value-converter for " + c );
final ValueConverter valueConverter = ConverterRegistry.getInstance().getValueConverter( key.getValueType() ); if ( valueConverter != null ) {
e.setAttribute( namespace, name, propertyEditor.getValue() ); } else { final ValueConverter valueConverter = instance.getValueConverter( type ); if ( type.isAssignableFrom( String.class ) ) {
} else { final ConverterRegistry instance = ConverterRegistry.getInstance(); final ValueConverter valueConverter = instance.getValueConverter( type ); if ( valueConverter != null ) { final Object o = ConverterRegistry.toPropertyValue( attributeValue, type );
final ValueConverter valueConverter = ConverterRegistry.getInstance().getValueConverter( entry.getValueType() ); if ( valueConverter != null ) {