public static Object convert( final Object o, final Class c, final Object defaultValue ) { if ( o == null ) { return defaultValue; } if ( c.isInstance( o ) ) { return o; } try { final String s = String.valueOf( o ); return toPropertyValue( s, c ); } catch ( BeanException e ) { return defaultValue; } } }
final Object o = ConverterRegistry.toPropertyValue( (String) attribute, type ); if ( o != null ) { return o;
/** * This is a design-time default. * * @param position * @return */ public Object getParameterDefault( final int position ) { try { final String value = getBundle( Locale.getDefault() ).getString( "parameter." + position + ".default-value" ); if ( StringUtils.isEmpty( value ) ) { return null; } return ConverterRegistry.toPropertyValue( value, getParameterType( position ) ); } catch ( Exception e ) { return null; } }
protected Object convertValue( final String text ) throws BeanException { if ( text == null ) { return null; } if ( formatter != null ) { try { final Object o = formatter.parseObject( text ); // this magic converts the date or number value to the real type. // the formatter always returns doubles/bigdecimals or java.util.Dates // but we may need sql-dates, long-objects etc .. final String asText = ConverterRegistry.toAttributeValue( o ); return ConverterRegistry.toPropertyValue( asText, getType() ); } catch ( ParseException e ) { throw new BeanException( "Failed to format object" ); } } if ( Object.class == type || String.class == type ) { return text; } return ConverterRegistry.toPropertyValue( text, type ); }
/** * Returns the value for the cell at <code>columnIndex</code> and <code>rowIndex</code>. * * @param rowIndex * the row whose value is to be queried * @param columnIndex * the column whose value is to be queried * @return the value Object at the specified cell */ public Object getValueAt( final int rowIndex, final int columnIndex ) { try { final Class colType = getColumnClass( columnIndex ); if ( Number.class.isAssignableFrom( colType ) ) { return ConverterRegistry.toPropertyValue( String.valueOf( ( rowIndex * getColumnCount() ) + columnIndex ), colType ); } if ( Date.class.isAssignableFrom( colType ) ) { final Date date = new Date( ( ( rowIndex * getColumnCount() ) + columnIndex ) * ( 12 * 60 * 60 * 1000 ) ); return ConverterRegistry.toPropertyValue( ConverterRegistry.toAttributeValue( date ), colType ); } if ( String.class.isAssignableFrom( colType ) ) { return getColumnName( columnIndex ) + rowIndex; } return null; } catch ( Exception e ) { return null; } }
private static String continueLookupVariable( final CSVTokenizer tokenizer, final Object parent ) throws BeanException { if ( tokenizer.hasMoreTokens() ) { final String name = tokenizer.nextToken(); final Object base = ConverterRegistry.toPropertyValue( name, parent.getClass() ); if ( tokenizer.hasMoreTokens() ) { return continueLookupVariable( tokenizer, base ); } else { return ConverterRegistry.toAttributeValue( base ); } } return null; }
/** * Done parsing. * * @throws SAXException * if there is a parsing error. */ protected void doneParsing() throws SAXException { super.doneParsing(); if ( nullValue ) { value = null; return; } try { value = ConverterRegistry.toPropertyValue( getResult(), type ); } catch ( BeanException e ) { try { value = ConverterRegistry.toPropertyValue( getResult().trim(), type ); } catch ( BeanException ex ) { throw new ParseException( "Unable to convert value '" + getResult() + "' into a object of type '" + type + "'.", ex, getLocator() ); } } }
final Date date = (Date) ConverterRegistry.toPropertyValue( (String) value, dateType ); dateChooserPanel.setDateSelected( false ); dateChooserPanel.setDate( date );
final ClassLoader loader = ObjectUtilities.getClassLoader( DefaultReportEnvironment.class ); final Class aClass = Class.forName( configType, false, loader ); return ConverterRegistry.toPropertyValue( configProperty, aClass ); } catch ( Throwable t ) {
if ( defaultValueText != null ) { try { defaultValue = ConverterRegistry.toPropertyValue( defaultValueText, type ); } catch ( BeanException e ) { throw new ParseException( "Specified parameter 'default-value' is invalid.", getLocator() );
if ( tableLayout != null ) { try { final TableLayout o = (TableLayout) ConverterRegistry.toPropertyValue( tableLayout, TableLayout.class ); styleSheet.setStyleProperty( BandStyleKeys.TABLE_LAYOUT, o ); } catch ( BeanException e ) {
final ClassLoader loader = ObjectUtilities.getClassLoader( MetaSelectorReadHandler.class ); final Class aClass = Class.forName( CompatibilityMapperUtil.mapClassName( type ), false, loader ); value = ConverterRegistry.toPropertyValue( rawValue, aClass ); } catch ( ClassNotFoundException e ) { throw new ParseException( "Required attribute 'type' is invalid.", e, getLocator() );
if ( valueConverter != null ) { final Object o = ConverterRegistry.toPropertyValue( String.valueOf( value ), key.getValueType() ); style.setStyleProperty( key, o ); } else {
final Object o = ConverterRegistry.toPropertyValue( String.valueOf( value ), type ); e.setAttribute( namespace, name, o ); } else {
final ValueConverter valueConverter = instance.getValueConverter( type ); if ( valueConverter != null ) { final Object o = ConverterRegistry.toPropertyValue( attributeValue, type ); element.setAttribute( namespace, name, o ); } else if ( String.class.isAssignableFrom( type ) ) {
/** * Done parsing. * * @throws SAXException * if there is a parsing error. */ protected void doneParsing() throws SAXException { final SequenceDescription sequenceDescription = data.getSequenceDescription(); for ( final PropertyReadHandler propertyReadHandler : properties ) { final String propertyName = propertyReadHandler.getName(); final String propertyValue = propertyReadHandler.getResult(); final int pos = getPropertyLocation( sequenceDescription, propertyName ); if ( pos == -1 ) { throw new ParseException( "Unable to set property " + propertyName + ". There is no such property.", getLocator() ); } final Class ptype = sequenceDescription.getParameterType( pos ); try { final Object o = ConverterRegistry.toPropertyValue( propertyValue, ptype ); data.setParameter( propertyName, o ); } catch ( BeanException e ) { throw new ParseException( "Unable to set property " + propertyName + ". Conversion error.", e, getLocator() ); } } }
return ConverterRegistry.toPropertyValue( textValue, entry.getValueType() ); } catch ( BeanException e ) { if ( logger.isDebugEnabled() ) {