/** * 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 ); }
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 ); } } }
final String original = elementConverter.toAttributeValue( o1 ); if ( original.length() == 0 ) { buffer.append( "\"\"" );
/** * 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 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 ); }
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 ); }