private void updateArrayProperty( final PropertyDescriptor pd, final PropertySpecification name, final Object o ) throws BeanException { final Method readMethod = pd.getReadMethod(); if ( readMethod == null ) { throw new BeanException( "Property is not readable, cannot perform array update: " + name ); } try { // System.out.println(readMethod); final Object value = readMethod.invoke( bean ); // we have (possibly) an array. final int index = Integer.parseInt( name.getIndex() ); final Object array = validateArray( BeanUtility.getPropertyType( pd ), value, index ); Array.set( array, index, o ); final Method writeMethod = pd.getWriteMethod(); writeMethod.invoke( bean, array ); } catch ( BeanException e ) { throw e; } catch ( Exception e ) { BeanUtility.logger.warn( "Failed to read property, cannot perform array update: " + name, e ); throw new BeanException( "Failed to read property, cannot perform array update: " + name ); } }
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 ); }
if ( pd instanceof IndexedPropertyDescriptor && name.getIndex() != null ) { final IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd; final Method readMethod = ipd.getIndexedReadMethod(); return readMethod.invoke( bean, new Integer( name.getIndex() ) ); } catch ( Exception e ) { throw BeanException.getInstance( "InvokationError", e ); throw BeanException.getInstance( "Property is not readable: " + name, null ); if ( name.getIndex() != null ) { final int index = Integer.parseInt( name.getIndex() ); return Array.get( value, index ); } catch ( BeanException be ) {
if ( pd instanceof IndexedPropertyDescriptor && name.getIndex() != null ) { final IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd; final Method writeMethod = ipd.getIndexedWriteMethod(); if ( writeMethod != null ) { try { writeMethod.invoke( bean, new Integer( name.getIndex() ), o ); } catch ( Exception e ) { throw BeanException.getInstance( "InvokationError", e ); if ( name.getIndex() != null ) {
/** * Creates a new PropertySpecification object for the given property string. * * @param raw * the property string, posssibly with index specifications. */ private PropertySpecification( final String raw ) { this.raw = raw; this.name = getNormalizedName( raw ); this.index = getIndex( raw ); }