private ServiceInfo generateServiceInfo ( ServiceReference reference ) { Map < String , String > map = Utils . toMap ( reference ) ; Set < String > keys = map . keySet ( ) ; String slpUrl = Utils . subst ( ( String ) reference . getProperty ( SLP_URL ) , map ) ; ServiceURL serviceURL ; if ( keys . contains ( SLP_URL_LIFETIME ) ) { try { int lifetime = Integer . parseInt ( ( String ) reference . getProperty ( SLP_URL_LIFETIME ) ) ; serviceURL = new ServiceURL ( slpUrl , lifetime ) ; } catch ( NumberFormatException e ) { serviceURL = new ServiceURL ( slpUrl ) ; } } else { serviceURL = new ServiceURL ( slpUrl ) ; } String language ; if ( keys . contains ( SLP_LANGUAGE ) ) language = ( String ) reference . getProperty ( SLP_LANGUAGE ) ; else language = Locale . getDefault ( ) . getLanguage ( ) ; Scopes scopes = Scopes . NONE ; if ( keys . contains ( SLP_SCOPES ) ) { String [ ] values = ( ( String ) reference . getProperty ( SLP_SCOPES ) ) . split ( "," ) ; for ( int i = 0 ; i < values . length ; i ++ ) values [ i ] = values [ i ] . trim ( ) ; scopes = Scopes . from ( values ) ; } ServiceType serviceType = null ; if ( keys . contains ( SLP_SERVICE_TYPE ) ) { serviceType = new ServiceType ( ( String ) reference . getProperty ( SLP_SERVICE_TYPE ) ) ; } map . remove ( SLP_URL ) ; map . remove ( SLP_URL_LIFETIME ) ; map . remove ( SLP_LANGUAGE ) ; map . remove ( SLP_SCOPES ) ; map . remove ( SLP_SERVICE_TYPE ) ; Attributes attributes = Attributes . from ( map ) ; ServiceInfo serviceInfo ; if ( serviceType != null ) { serviceInfo = new ServiceInfo ( serviceType , serviceURL , language , scopes , attributes ) ; } else { serviceInfo = new ServiceInfo ( serviceURL , language , scopes , attributes ) ; } return serviceInfo ; }
Generate SLP service information by scraping relevant information from the OSGi service reference s properties .