private void initialize ( Object callee ) { // This is used to build up all the setter methods in. Map < String , List < Method > > settersTemp = new HashMap < String , List < Method > > ( ) ; // Get all the property getters and setters on this class. Method [ ] methods = callee . getClass ( ) . getMethods ( ) ; for ( Method nextMethod : methods ) { String methodName = nextMethod . getName ( ) ; // Check if it is a getter method. if ( methodName . startsWith ( "get" ) && ( methodName . length ( ) >= 4 ) && Character . isUpperCase ( methodName . charAt ( 3 ) ) && Modifier . isPublic ( nextMethod . getModifiers ( ) ) && ( nextMethod . getParameterTypes ( ) . length == 0 ) ) { String propertyName = methodName . substring ( 3 , 4 ) . toLowerCase ( ) + methodName . substring ( 4 ) ; getters . put ( propertyName , nextMethod ) ; } // Check if it is a setter method. else if ( methodName . startsWith ( "set" ) && Modifier . isPublic ( nextMethod . getModifiers ( ) ) && ( nextMethod . getParameterTypes ( ) . length == 1 ) ) { /*log.fine("Found setter method.");*/ String propertyName = methodName . substring ( 3 , 4 ) . toLowerCase ( ) + methodName . substring ( 4 ) ; /*log.fine("propertyName = " + propertyName);*/ // Check the setter to see if any for this name already exist, and start a new list if not. List < Method > setterMethodsForName = settersTemp . get ( propertyName ) ; if ( setterMethodsForName == null ) { setterMethodsForName = new ArrayList < Method > ( ) ; settersTemp . put ( propertyName , setterMethodsForName ) ; } // Add the setter method to the list of setter methods for the named property. setterMethodsForName . add ( nextMethod ) ; } } // Convert all the lists of setter methods into arrays. for ( Map . Entry < String , List < Method > > entries : settersTemp . entrySet ( ) ) { String nextPropertyName = entries . getKey ( ) ; List < Method > nextMethodList = entries . getValue ( ) ; Method [ ] methodArray = nextMethodList . toArray ( new Method [ nextMethodList . size ( ) ] ) ; setters . put ( nextPropertyName , methodArray ) ; } // Initialization completed, set the initialized flag. initialized = true ; }
Initialized this property introspector on a specified object building the caches of getter and setter methods .