public boolean shutdownService ( String serviceClass , Object service ) { if ( service == null ) return false ; if ( bundleContext == null ) return false ; String filter = null ; if ( serviceClass == null ) if ( ! ( service instanceof String ) ) serviceClass = service . getClass ( ) . getName ( ) ; if ( service instanceof String ) filter = ClassServiceUtility . addToFilter ( "" , BundleConstants . SERVICE_PID , ( String ) service ) ; ServiceReference [ ] refs ; try { refs = bundleContext . getServiceReferences ( serviceClass , filter ) ; if ( ( refs == null ) || ( refs . length == 0 ) ) return false ; for ( ServiceReference reference : refs ) { if ( ( bundleContext . getService ( reference ) == service ) || ( service instanceof String ) ) { if ( refs . length == 1 ) { // Last/only one, shut down the service // Lame code String dependentBaseBundleClassName = service . getClass ( ) . getName ( ) ; String packageName = ClassFinderActivator . getPackageName ( dependentBaseBundleClassName , false ) ; if ( service instanceof String ) packageName = ( String ) service ; Bundle bundle = this . findBundle ( null , bundleContext , packageName , null ) ; if ( bundle != null ) if ( ( bundle . getState ( ) & Bundle . ACTIVE ) != 0 ) { try { bundle . stop ( ) ; } catch ( BundleException e ) { e . printStackTrace ( ) ; } } return true ; } } } } catch ( InvalidSyntaxException e1 ) { e1 . printStackTrace ( ) ; } return false ; // Not found? }
Shutdown the bundle for this service .