public Class getPropertyType( final String name ) throws BeanException { if ( name == null ) { throw new NullPointerException( "Name must not be null" ); } final PropertySpecification ps = new PropertySpecification( name ); final PropertyDescriptor pd = properties.get( ps.getName() ); if ( pd == null ) { throw new BeanException( "No such property:" + name ); } return BeanUtility.getPropertyType( pd ); }
public String[] getProperties() throws BeanException { final ArrayList<String> propertyNames = new ArrayList<String>(); final PropertyDescriptor[] pd = getPropertyInfos(); for ( int i = 0; i < pd.length; i++ ) { final PropertyDescriptor property = pd[i]; if ( property.isHidden() ) { continue; } if ( property.getReadMethod() == null || property.getWriteMethod() == null ) { // it will make no sense to write a property now, that // we can't read in later... continue; } if ( BeanUtility.getPropertyType( property ).isArray() ) { final int max = findMaximumIndex( property ); for ( int idx = 0; idx < max; idx++ ) { propertyNames.add( property.getName() + '[' + idx + ']' ); } } else { propertyNames.add( property.getName() ); } } return propertyNames.toArray( new String[propertyNames.size()] ); }
public void setPropertyAsString( final String name, final String txt ) throws BeanException { if ( name == null ) { throw new NullPointerException( "Name must not be null" ); } if ( txt == null ) { throw new NullPointerException( "Text must not be null" ); } final PropertySpecification ps = new PropertySpecification( name ); final PropertyDescriptor pd = properties.get( ps.getName() ); if ( pd == null ) { throw new BeanException( bean.getClass() + ": No such property:" + name ); } setPropertyAsString( name, BeanUtility.getPropertyType( pd ), txt ); }
/** * Converts the attribute to a string. * * @param o * the attribute ({@link Integer} expected). * @return A string representing the {@link Integer} value. * @throws BeanException * if there was an error during the conversion. */ public String toAttributeValue( final Object o ) throws BeanException { if ( o == null ) { throw new NullPointerException(); } final Class aClass = BeanUtility.getPropertyType( propertyDescriptor ); if ( aClass.isInstance( o ) == false ) { throw new BeanException( "Failed to convert object of type " + o.getClass() + ": Not a " + aClass.getName() ); } propertyEditor.setValue( o ); return propertyEditor.getAsText(); }
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 ); } }
final Class propertyType = beanUtility.getPropertyType( propertyName ); final AttributeList attList = new AttributeList(); attList.setAttribute( namespaceUri, "name", propertyName );
public void writeExpressionParameter( final XmlWriter writer, final BeanUtility beanUtility, final String propertyName, final String namespaceUri ) throws IOException, BeanException { // filter some of the standard properties. These are system-properties // and are set elsewhere final Object property = beanUtility.getProperty( propertyName ); final Class propertyType = beanUtility.getPropertyType( propertyName ); final String value = beanUtility.getPropertyAsString( propertyName ); if ( value != null && property != null ) { final AttributeList attList = new AttributeList(); attList.setAttribute( namespaceUri, "name", propertyName ); if ( BeanUtility.isSameType( propertyType, property.getClass() ) == false ) { attList.setAttribute( namespaceUri, "class", property.getClass().getName() ); } writer.writeTag( namespaceUri, "property", attList, XmlWriterSupport.OPEN ); writer.writeTextNormalized( value, false ); writer.writeCloseTag(); } }
private void writePreProcessor( final XmlWriter writer, final ReportPreProcessor preProcessor ) throws IntrospectionException, BeanException, IOException { if ( writer == null ) { throw new NullPointerException(); } if ( preProcessor == null ) { throw new NullPointerException(); } // the classic way, in case the expression does not provide any meta-data. This is // in the code for legacy reasons, as there are many expression implementations out there // that do not yet provide meta-data descriptions .. final BeanUtility beanUtility = new BeanUtility( preProcessor ); final String[] propertyNames = beanUtility.getProperties(); for ( int i = 0; i < propertyNames.length; i++ ) { final String key = propertyNames[i]; final Object property = beanUtility.getProperty( key ); final Class propertyType = beanUtility.getPropertyType( key ); final String value = beanUtility.getPropertyAsString( key ); if ( value != null && property != null ) { final AttributeList attList = new AttributeList(); attList.setAttribute( BundleNamespaces.LAYOUT, "name", key ); if ( BeanUtility.isSameType( propertyType, property.getClass() ) == false ) { attList.setAttribute( BundleNamespaces.LAYOUT, "class", property.getClass().getName() ); } writer.writeTag( BundleNamespaces.LAYOUT, "property", attList, XmlWriterSupport.OPEN ); writer.writeTextNormalized( value, false ); writer.writeCloseTag(); } } }
final Class propertyType = beanUtility.getPropertyType( key ); final String value = beanUtility.getPropertyAsString( key ); if ( value != null && property != null ) {
final Class propertyType = beanUtility.getPropertyType( propertyName ); final AttributeList attList = new AttributeList(); attList.setAttribute( namespaceUri, "name", propertyName );