public static Session getSession ( String wrapper , Object ... parameters ) { // This will be the session loaded depending the selected wrapper org . riverframework . wrapper . Session < ? > _session = null ; // Trying to retrieve the session from the map Session session = map . get ( wrapper ) ; if ( session != null && session . isOpen ( ) ) { // There is an open session if ( parameters . length > 0 ) { // and the user is trying to open a new one throw new RiverException ( "There is already an open session for the wrapper " + wrapper + ". You must close the current before opening a new one." ) ; } // If there are no parameters, we just return the current opened session } else { // If not exists or is closed, we create it using the factory Class < ? > clazzFactory = null ; try { clazzFactory = Class . forName ( wrapper + ".DefaultFactory" ) ; } catch ( ClassNotFoundException e ) { throw new RiverException ( "The wrapper '" + wrapper + "' can not be loaded. If you are using an non-official wrapper, " + "check the wrapper name and its design. Check the CLASSPATH." ) ; } try { Method method = clazzFactory . getDeclaredMethod ( "getInstance" ) ; method . setAccessible ( true ) ; org . riverframework . wrapper . Factory < ? > _factory = ( org . riverframework . wrapper . Factory < ? > ) method . invoke ( null ) ; if ( _factory == null ) throw new RiverException ( "The factory could not be loaded." ) ; if ( parameters . length > 0 ) { // There are parameters. So, we try to create a new one. _session = ( org . riverframework . wrapper . Session < ? > ) _factory . getSession ( parameters ) ; } else { // There are no parameters. We create a closed session. _session = null ; } Constructor < ? > constructor = DefaultSession . class . getDeclaredConstructor ( org . riverframework . wrapper . Session . class ) ; constructor . setAccessible ( true ) ; session = ( DefaultSession ) constructor . newInstance ( _session ) ; } catch ( Exception e ) { throw new RiverException ( "There's a problem opening the session. Maybe, you will need to check the parameters." , e ) ; } map . put ( wrapper , session ) ; } return session ; }
Loads a wrapper that wraps libraries as lotus . domino or org . openntf . domino and creates a core Session object . Its behavior will depend on how the wrapper is implemented . Anyway this method creates the session just one time and returns the same every time is called . To free the memory resources etc . it s necessary to call the close method at the end of the program or process .