private void setValueForArrayType ( DataMemberInformation memberInfo ) throws IllegalAccessException , ArrayIndexOutOfBoundsException , IllegalArgumentException , InstantiationException { logger . entering ( memberInfo ) ; Field eachField = memberInfo . getField ( ) ; Object objectToSetDataInto = memberInfo . getObjectToSetDataInto ( ) ; String data = memberInfo . getDataToUse ( ) ; Class < ? > eachFieldType = eachField . getType ( ) ; // We are dealing with arrays String [ ] arrayData = data . split ( "," ) ; Object arrayObject ; // Check if its an array of primitive data type if ( ReflectionUtils . isPrimitiveArray ( eachFieldType ) ) { arrayObject = ReflectionUtils . instantiatePrimitiveArray ( eachFieldType , arrayData ) ; eachField . set ( objectToSetDataInto , arrayObject ) ; logger . exiting ( ) ; return ; } if ( ReflectionUtils . isWrapperArray ( eachFieldType ) || ReflectionUtils . hasOneArgStringConstructor ( eachFieldType . getComponentType ( ) ) ) { // Check if its an array of either Wrapper classes or classes that have a 1 arg string constructor arrayObject = ReflectionUtils . instantiateWrapperArray ( eachFieldType , arrayData ) ; eachField . set ( objectToSetDataInto , arrayObject ) ; logger . exiting ( ) ; return ; } DefaultCustomType customType = fetchMatchingCustomType ( eachFieldType ) ; if ( customType != null ) { // Maybe it belongs to one of the custom types arrayObject = ReflectionUtils . instantiateDefaultCustomTypeArray ( customType , arrayData ) ; eachField . set ( objectToSetDataInto , arrayObject ) ; logger . exiting ( ) ; return ; } // If we are here then it means that the field is a Pojo class that points to another sheet in the excel sheet arrayObject = Array . newInstance ( eachFieldType . getComponentType ( ) , arrayData . length ) ; for ( int counter = 0 ; counter < arrayData . length ; counter ++ ) { Array . set ( arrayObject , counter , getSingleExcelRow ( eachFieldType . getComponentType ( ) . newInstance ( ) , arrayData [ counter ] . trim ( ) , true ) ) ; } eachField . set ( objectToSetDataInto , arrayObject ) ; logger . exiting ( ) ; }
A utility method that setups up data members which are arrays .