public static PropertyDescriptor [ ] getPropertiesAssignableToType ( Class < ? > clazz , Class < ? > propertySuperType ) { if ( clazz == null || propertySuperType == null ) return new PropertyDescriptor [ 0 ] ; Set < PropertyDescriptor > properties = new HashSet < PropertyDescriptor > ( ) ; PropertyDescriptor descriptor = null ; try { PropertyDescriptor [ ] descriptors = BeanUtils . getPropertyDescriptors ( clazz ) ; for ( int i = 0 ; i < descriptors . length ; i ++ ) { descriptor = descriptors [ i ] ; Class < ? > currentPropertyType = descriptor . getPropertyType ( ) ; if ( propertySuperType . isAssignableFrom ( descriptor . getPropertyType ( ) ) ) { properties . add ( descriptor ) ; } } } catch ( Exception e ) { if ( descriptor == null ) { LOG . error ( String . format ( "Got exception while checking property descriptors for class %s" , clazz . getName ( ) ) , e ) ; } else { LOG . error ( String . format ( "Got exception while checking PropertyDescriptor.propertyType for field %s.%s" , clazz . getName ( ) , descriptor . getName ( ) ) , e ) ; } return new PropertyDescriptor [ 0 ] ; } return properties . toArray ( new PropertyDescriptor [ properties . size ( ) ] ) ; }
Retrieves all the properties of the given class which are assignable to the given type