elements.add( null ); } else { elements.add( elementConverter.toPropertyValue( token ) );
/** * Done parsing. * * @throws org.xml.sax.SAXException * if there is a parsing error. */ public void doneParsing() throws SAXException { super.doneParsing(); final String result = getResult(); final boolean strictPropertyErrorHandling = ( result.trim().length() != 0 ); try { value = valueType.toPropertyValue( result ); } catch ( BeanException e ) { if ( strictPropertyErrorHandling ) { throw new ParseException( "Failed to parse property value for property " + propertyName, e ); } else { PropertyReferenceReadHandler.logger.warn( "Failed to parse property value for property: " + propertyName, e ); } } }
/** * 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 ); }