public static JSONObject getStepAsJSON ( Machine machine , boolean verbose , boolean showUnvisited ) { JSONObject object = new JSONObject ( ) ; if ( verbose ) { object . put ( "modelName" , FilenameUtils . getBaseName ( machine . getCurrentContext ( ) . getModel ( ) . getName ( ) ) ) ; } if ( machine . getCurrentContext ( ) . getCurrentElement ( ) . hasName ( ) ) { object . put ( "currentElementName" , machine . getCurrentContext ( ) . getCurrentElement ( ) . getName ( ) ) ; } else { object . put ( "currentElementName" , "" ) ; } if ( verbose ) { object . put ( "currentElementID" , machine . getCurrentContext ( ) . getCurrentElement ( ) . getId ( ) ) ; JSONArray jsonKeys = new JSONArray ( ) ; for ( Map . Entry < String , String > key : machine . getCurrentContext ( ) . getKeys ( ) . entrySet ( ) ) { JSONObject jsonKey = new JSONObject ( ) ; jsonKey . put ( key . getKey ( ) , key . getValue ( ) ) ; jsonKeys . put ( jsonKey ) ; } object . put ( "data" , jsonKeys ) ; JSONArray jsonProperties = new JSONArray ( ) ; RuntimeBase runtimeBase = ( RuntimeBase ) machine . getCurrentContext ( ) . getCurrentElement ( ) ; for ( Map . Entry < String , Object > key : runtimeBase . getProperties ( ) . entrySet ( ) ) { JSONObject jsonKey = new JSONObject ( ) ; jsonKey . put ( key . getKey ( ) , key . getValue ( ) ) ; jsonProperties . put ( jsonKey ) ; } object . put ( "properties" , jsonProperties ) ; JSONArray jsonActions = new JSONArray ( ) ; if ( runtimeBase . hasActions ( ) ) { for ( Action action : runtimeBase . getActions ( ) ) { JSONObject jsonAction = new JSONObject ( ) ; jsonAction . put ( "Action" , action . getScript ( ) ) ; jsonActions . put ( jsonAction ) ; } object . put ( "actions" , jsonActions ) ; } } if ( showUnvisited ) { Context context = machine . getCurrentContext ( ) ; object . put ( "numberOfElements" , context . getModel ( ) . getElements ( ) . size ( ) ) ; object . put ( "numberOfUnvisitedElements" , context . getProfiler ( ) . getUnvisitedElements ( context ) . size ( ) ) ; JSONArray jsonElements = new JSONArray ( ) ; for ( Element element : context . getProfiler ( ) . getUnvisitedElements ( context ) ) { JSONObject jsonElement = new JSONObject ( ) ; jsonElement . put ( "elementName" , element . getName ( ) ) ; if ( verbose ) { jsonElement . put ( "elementId" , element . getId ( ) ) ; } jsonElements . put ( jsonElement ) ; } object . put ( "unvisitedElements" , jsonElements ) ; } return object ; }
Will create a JSON formatted string representing the current step . The step is the current element which can be either a vertex orn an edge .