private Object createHandlerFromParams ( Object xmlHandler ) { if ( xmlHandler == null ) return null ; Object handler = null ; String handlerClass = xmlHandler . getClass ( ) . getSimpleName ( ) ; if ( handlerClass == null || handlerClass . length ( ) == 0 ) { return null ; } try { // To avoid name collisions, the java class will have the suffix "Implementation". Class < ? > c = Class . forName ( "com.microsoft.Malmo.MissionHandlers." + handlerClass + "Implementation" ) ; handler = c . newInstance ( ) ; if ( ! ( ( HandlerBase ) handler ) . parseParameters ( xmlHandler ) ) this . failedHandlers += handlerClass + " failed to parse parameters.\n" ; } catch ( ClassNotFoundException e ) { System . out . println ( "Duff MissionHandler requested: " + handlerClass ) ; this . failedHandlers += "Failed to find " + handlerClass + "\n" ; } catch ( InstantiationException e ) { System . out . println ( "Could not instantiate specified MissionHandler." ) ; this . failedHandlers += "Failed to create " + handlerClass + "\n" ; } catch ( IllegalAccessException e ) { System . out . println ( "Could not instantiate specified MissionHandler." ) ; this . failedHandlers += "Failed to access " + handlerClass + "\n" ; } return handler ; }
Attempt to create an instance of the specified handler class using reflection .