public Object getService ( BeanContextChild child , Object requestor , Class serviceClass , Object serviceSelector , BeanContextServiceRevokedListener bcsrl ) throws TooManyListenersException { if ( child == null || requestor == null || serviceClass == null || bcsrl == null ) { throw new NullPointerException ( ) ; } BCSSChild bcssChild = null ; BeanContextServiceProvider provider = null ; Object service = null ; boolean isDelegate = false ; synchronized ( globalHierarchyLock ) { // check child synchronized ( children ) { bcssChild = ( BCSSChild ) children . get ( child ) ; } if ( bcssChild == null ) { throw new IllegalArgumentException ( Messages . getString ( "beans.65" ) ) ; } // try local service provider = getLocalServiceProvider ( serviceClass ) ; if ( provider != null ) { service = provider . getService ( getBeanContextServicesPeer ( ) , requestor , serviceClass , serviceSelector ) ; } // no local service, try delegate if ( service == null && proxy != null ) { provider = proxy ; service = proxy . getService ( getBeanContextServicesPeer ( ) , requestor , serviceClass , serviceSelector , bcsrl ) ; isDelegate = true ; } } if ( service != null ) { // save record synchronized ( child ) { if ( bcssChild . serviceRecords == null ) { bcssChild . serviceRecords = new ArrayList < ServiceRecord > ( ) ; } bcssChild . serviceRecords . add ( new ServiceRecord ( provider , child , requestor , serviceClass , bcsrl , service , isDelegate ) ) ; } } return service ; }
Get a service instance on behalf of the specified child of this context by calling the registered service provider or by delegating to the parent context .