protected Action toAction ( Object item ) { if ( item instanceof Action ) { return ( Action ) item ; } else if ( item instanceof String ) { final String definition = ( String ) item ; return new DefaultAction ( definition + "@" + RANDOM . nextInt ( ) , resolveDataFunction ( ( String ) item ) , getMiddleware ( definition ) ) ; } else { String name ; List < Middleware > middleware ; try { name = ( String ) ClassApi . findMethod ( item . getClass ( ) , "getName" ) . invoke ( item ) ; middleware = getMiddleware ( name ) ; } catch ( Throwable t ) { name = item . getClass ( ) . getName ( ) ; middleware = Collections . emptyList ( ) ; } return new DefaultAction ( name + "@" + RANDOM . nextInt ( ) , getDataFunctionExtractor ( ) . apply ( item , DEFAULT_FUNCTION ) , middleware ) ; } }
Convert supplied object to of action if possible .