Gets the service objects from the {@link BundleContext} and compares the
class names to the given key. For the comparison see
{@link #checkRegisteredOsgiServices(String, String)}.

@param references
@param key
@return
160250
private <T> Collection<T> checkIfClassNamesMatchKey(Collection<ServiceReference<T>> references, String key) {
    Set<T> result = new HashSet<T>();
    for (ServiceReference<T> ref : references) {
      T service = getBundleContext().getService(ref);
      if (service != null) {
        String keyWithFirstLetterUppercase = Character.toUpperCase(key.charAt(0)) + key.substring(1);
        if (service.getClass().getSimpleName().equals(keyWithFirstLetterUppercase)) {
          result.add(service);
        }
      }
    }
    return result;
  }
497905
public static List<ServiceModel> services(BundleContext context) {
        List<ServiceModel> services = new ArrayList<>();
        try {
            ServiceReference[] references = context.getAllServiceReferences(null, null);
            if (references != null) {
                for (ServiceReference ref : references) {
                    services.add(new ServiceModel(ref));
                }
            }
        } catch (InvalidSyntaxException e) {  //NOSONAR
            // Ignore it.
        }
        return services;
    }
540461
def get_bundle_registered_services(self, bundle):
        # type: (Any) -> List[ServiceReference]
        
        with self.__svc_lock:
            return sorted(self.__bundle_svc.get(bundle, []))
1238908
public static ServiceReference getClassServiceReference(BundleContext context, String interfaceClassName, String versionRange, Dictionary<String, String> filter)
    {
        try {
            String serviceFilter = null;//ClassServiceUtility.addToFilter((String)null, BundleActivatorModel.PACKAGE_NAME, ClassFinderActivator.getPackageName(className, true));
            String interfaceName = null;
            if (filter != null)
            {
                interfaceName = filter.get(BundleConstants.INTERFACE);

                Enumeration<String> keys = filter.keys();
                while (keys.hasMoreElements())
                {
                    String key = keys.nextElement();
                    if (key.equals(BundleConstants.INTERFACE))
                        continue;
                    serviceFilter = ClassServiceUtility.addToFilter(serviceFilter, key, filter.get(key));
                }
            }
            if (interfaceName == null)
                interfaceName = interfaceClassName;
            serviceFilter = ClassFinderActivator.addVersionFilter(serviceFilter, versionRange);
            ServiceReference[] refs = null;
            if (context != null)
                refs = context.getServiceReferences(interfaceName, serviceFilter);

            if ((refs != null) && (refs.length > 0))
                return refs[0];
        } catch (InvalidSyntaxException e) {
            e.printStackTrace();
        }
        return null;
    }
827166
def service_references(self):
        
        services_blue_print = self._scheme_references.get('services')
        if services_blue_print is None:
            raise LookupError('unable to find any services in the config.')

        # TODO: this needs to be cleaned up and made solid. maybe when creating the blueprint ref normalize the damn keys
        return {key.replace('-', '_'): key for key in services_blue_print['keys']}
863713
public static String get(String key, Object... args) {
        return get(BUNDLE_NAME, key, args);
    }
601870
@Override
    public MethodDescriptor<String> getServiceDescriptor(String key) {
        Preconditions.checkNotNull(key, "Key cannot be null");
        return serviceRegistry.getServiceDescriptorByKey(key);
    }
956802
public boolean removeReference(K key, ServiceReference<V> reference) {
        if (key == null)
            return false;

        ConcurrentServiceReferenceSet<V> csrs = elementMap.get(key);
        if (csrs == null) {
            return false;
        }
        return csrs.removeReference(reference);
    }
554471
static Library getSharedLibrary(String id) {

        if (bundleContext == null) {
            return null;
        }

        // Filter the SharedLibrary service references by ID.
        String filter = "(" + "id=" + id + ")";
        Collection<ServiceReference<Library>> refs = null;
        try {
            refs = bundleContext.getServiceReferences(Library.class, filter);
        } catch (InvalidSyntaxException e) {
            if (tc.isErrorEnabled()) {
                Tr.error(tc, "cls.library.id.invalid", id, e.toString());
            }
            return null;
        }

        if (refs.isEmpty())
            return null;

        return bundleContext.getService(getHighestRankedService(refs));
    }
755162
public Collection<ServiceReference> serviceReferences() {
    return serviceRegistrations.stream()
        .flatMap(sr -> sr.methods().stream().map(sm -> new ServiceReference(sm, sr, this)))
        .collect(Collectors.toList());
  }
1288160
@SuppressWarnings("unchecked")
    public static <T> Set<T> getServices(Class<T> serviceInterface) {
        synchronized(servicesCache) {
            if (servicesCache.containsKey(serviceInterface)) {
                return (Set<T>) servicesCache.get(serviceInterface);
            }
    
            Set<T> services = new LinkedHashSet<>();
            try {
                for (T service : ServiceLoader.load(serviceInterface)) {
                    services.add(service);
                }
            } catch (ServiceConfigurationError sce) {
                // No services found - don't check again.
            }
            servicesCache.put(serviceInterface, services);
            return services;
        }
    }
174212
private <T> Provider<T> lookupProvider(Key<T> key)
  {
    BindingInject<T> bean = findBean(key);

    if (bean != null) {
      return bean.provider();
    }

    BindingAmp<T> binding = findBinding(key);

    if (binding != null) {
      return binding.provider();
    }

    binding = findObjectBinding(key);

    if (binding != null) {
      return binding.provider(InjectionPoint.of(key));
    }


    return null;
  }
304870
public ServiceReference<V> getReference(K key) {
        if (key == null)
            return null;

        ConcurrentServiceReferenceElement<V> e = elementMap.get(key);
        if (e == null) {
            return null;
        } else {
            return e.getReference();
        }
    }
350257
@SuppressWarnings({"unchecked", "UnusedDeclaration"})
  // Checked by runtime cast. Public API.
  public static <T> T get(Bundle bundle, String key) {
    return (T) bundle.get(key);
  }
1326042
public V get (K key)
    {
        V value = null;
        SoftReference<V> ref = _map.get(key);
        if (ref != null) {
            value = ref.get();
            if (value == null) {
                _map.remove(key);
            }
        }
        return value;
    }
572894
public Object addingService(ServiceReference reference)
    {
        HttpService httpService = (HttpService) context.getService(reference);

        this.properties = this.updateDictionaryConfig(this.properties, true);
        try {
            String alias = this.getAlias();
            String servicePid = this.properties.get(BundleConstants.SERVICE_PID);
            if (servlet == null)
            {
                servlet = this.makeServlet(alias, this.properties);
                if (servlet instanceof WebappServlet)
                    ((WebappServlet) servlet).init(context, servicePid, this.properties);
            }
            else
                if (servlet instanceof WebappServlet)
                    ((WebappServlet) servlet).setProperties(properties);
            if (servicePid != null)   // Listen for configuration changes
                serviceRegistration = context.registerService(ManagedService.class.getName(), new HttpConfigurator(context, servicePid), this.properties);

            httpService.registerServlet(alias, servlet, this.properties, httpContext);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return httpService;
    }
1205951
@SuppressWarnings("unchecked")
    public T cloneObject(String key) {
        if (this.objects.containsKey(key)) {
            T object = this.objects.get(key);
            if (object != null) {
                try {
                    return (T) object.clone();
                } catch (Exception ex) {
                    throw new RuntimeException(ex);
                }
            }
            return null;
        }
        throw new RuntimeException("[cloning error] object by name <" + key
                + "> not registered in " + getClass().getSimpleName());
    }