public static ConstructorParameterPair getConstructorParameterPairIgnoreCase ( Class clazz , Object [ ] parameters ) throws NoSuchMethodException { // set all values // Class objectClass=object.getClass(); if ( parameters == null ) parameters = new Object [ 0 ] ; // set parameter classes Class [ ] parameterClasses = new Class [ parameters . length ] ; for ( int i = 0 ; i < parameters . length ; i ++ ) { parameterClasses [ i ] = parameters [ i ] . getClass ( ) ; } // search right method Constructor [ ] constructor = clazz . getConstructors ( ) ; for ( int mode = 0 ; mode < 2 ; mode ++ ) { outer : for ( int i = 0 ; i < constructor . length ; i ++ ) { Constructor c = constructor [ i ] ; Class [ ] paramTrg = c . getParameterTypes ( ) ; // Same Parameter count if ( parameterClasses . length == paramTrg . length ) { for ( int y = 0 ; y < parameterClasses . length ; y ++ ) { if ( mode == 0 && parameterClasses [ y ] != primitiveToWrapperType ( paramTrg [ y ] ) ) { continue outer ; } else if ( mode == 1 ) { Object o = compareClasses ( parameters [ y ] , paramTrg [ y ] ) ; if ( o == null ) continue outer ; parameters [ y ] = o ; parameterClasses [ y ] = o . getClass ( ) ; } } return new ConstructorParameterPair ( c , parameters ) ; } } } // Exeception String parameter = "" ; for ( int i = 0 ; i < parameterClasses . length ; i ++ ) { if ( i != 0 ) parameter += ", " ; parameter += parameterClasses [ i ] . getName ( ) ; } throw new NoSuchMethodException ( "class constructor " + clazz . getName ( ) + "(" + parameter + ") doesn't exist" ) ; }
search the matching constructor to defined parameter list also translate parameters for matching