private static ApplicationSession openApplication ( ApplicationDefinition appDef , RESTClient restClient ) { String storageService = appDef . getStorageService ( ) ; if ( storageService == null || storageService . length ( ) <= "Service" . length ( ) || ! storageService . endsWith ( "Service" ) ) { throw new RuntimeException ( "Unknown storage-service for application '" + appDef . getAppName ( ) + "': " + storageService ) ; } // Using the application's StorageService, attempt to create an instance of the // ApplicationSession subclass XxxSession where Xxx is the storage prefix. try { String prefix = storageService . substring ( 0 , storageService . length ( ) - "Service" . length ( ) ) ; String className = Client . class . getPackage ( ) . getName ( ) + "." + prefix + "Session" ; @ SuppressWarnings ( "unchecked" ) Class < ApplicationSession > appClass = ( Class < ApplicationSession > ) Class . forName ( className ) ; Constructor < ApplicationSession > constructor = appClass . getConstructor ( ApplicationDefinition . class , RESTClient . class ) ; ApplicationSession appSession = constructor . newInstance ( appDef , restClient ) ; return appSession ; } catch ( Exception e ) { restClient . close ( ) ; throw new RuntimeException ( "Unable to load session class" , e ) ; } }
the given restClient . If the open fails the restClient is closed .