/* (non-Javadoc)
@see org.jboss.arquillian.core.spi.ServiceLoader#onlyOne(java.lang.Class, java.lang.Class)
435210
@Override
    public <T> T onlyOne(Class<T> serviceClass, Class<? extends T> defaultServiceClass) {
        T one = null;
        try {
            one = onlyOne(serviceClass);
        } catch (Exception e) {
        }

        if (one == null) {
            one = createServiceInstance(defaultServiceClass);
        }
        return one;
    }
629419
<T> List<T> all(ClassLoader classLoader, Class<T> serviceClass) {
        Validate.notNull(classLoader, "ClassLoader must be provided");
        Validate.notNull(serviceClass, "ServiceClass must be provided");

        return new ArrayList<T>(createInstances(load(serviceClass, classLoader)));
    }
837586
@Override
    public boolean isOrdinaryClass() {
        if (isEnum() || isInterface() || isAnnotationType()) {
            return false;
        }
        for (Type t = type; t.hasTag(CLASS); t = env.types.supertype(t)) {
            if (t.tsym == env.syms.errorType.tsym ||
                t.tsym == env.syms.exceptionType.tsym) {
                return false;
            }
        }
        return true;
    }
737859
public static <T> T loadAnyServiceProvider( Class<T> klass )
    {
        T provider = findAnyServiceProvider( klass );
        if (provider == null) {
            throw new NoServiceProviderException( klass.getName()
                + ": no service provider found in META-INF/services on classpath" );            
        }
        return provider;
    }
227542
final Search loadExternalSearch(String classSimpleName) {
		ServiceLoader<Search> searchLoader = ServiceLoader.load(Search.class, Para.getParaClassLoader());
		for (Search search : searchLoader) {
			if (search != null && classSimpleName.equalsIgnoreCase(search.getClass().getSimpleName())) {
				return search;
			}
		}
		return null;
	}
1229031
public static <C> Class<? extends C> findImplementation(Class<? super C> restrictionClass, String value) {
    // Add all from service files (i.e. jars)
    if(!contains(restrictionClass)) {
      ELKIServiceLoader.load(restrictionClass);
      ELKIServiceScanner.load(restrictionClass);
    }
    Entry e = data.get(restrictionClass);
    int pos = -1;
    Class<?> clazz = null;
    // First, try the lookup cache:
    if(e != null) {
      for(pos = 0; pos < e.len; pos++) {
        if(e.names[pos].equals(value)) {
          break;
        }
      }
      if(pos < e.len) {
        clazz = e.clazzes[pos];
      }
      else {
        pos = -1;
      }
    }
    else {
      if(LOG.isDebugging()) {
        LOG.debug("Requested implementations for unregistered type: " + restrictionClass.getName() + " " + value);
      }
    }
    // Next, try alternative versions:
    clazz = clazz != null ? clazz : tryAlternateNames(restrictionClass, value, e);
    if(clazz == null) {
      return null;
    }

    if(!restrictionClass.isAssignableFrom(clazz)) {
      LOG.warning("Invalid entry in service file for class " + restrictionClass.getName() + ": " + value);
      clazz = FAILED_LOAD;
    }
    if(e != null) {
      if(pos < 0) {
        e.addHit(value, clazz);
      }
      else {
        assert (e.names[pos].equalsIgnoreCase(value));
        e.clazzes[pos] = clazz;
      }
    }
    if(clazz == FAILED_LOAD) {
      return null;
    }
    @SuppressWarnings("unchecked")
    Class<? extends C> ret = (Class<? extends C>) clazz.asSubclass(restrictionClass);
    return ret;
  }
694790
@SuppressWarnings("unchecked")
   private <T> T loadService(Class<T> spiType, Class<?> defaultImpl, ClassLoader loader)
   {
      final String defaultImplName = defaultImpl != null ? defaultImpl.getName() : null;
      return (T)ServiceLoader.loadService(spiType.getName(), defaultImplName, loader);
   }
56228
public <T> Collection<T> all(ClassLoader classLoader, Class<T> serviceClass) {
        Validate.notNull(classLoader, "ClassLoader must be provided");
        Validate.notNull(serviceClass, "ServiceClass must be provided");

        return createInstances(
            serviceClass,
            load(serviceClass, classLoader));
    }
112719
@SuppressWarnings("unchecked")
    public static <T> Class<T> forClass(final String clsName) throws IllegalArgumentException {
        return (Class<T>) forClass(clsName, true);
    }
827577
@SuppressWarnings("unchecked")
    public static <T> Optional<Class<T>> optional(String dependency) {
        try {
            return Optional.of((Class<T>) Class.forName(dependency));
        } catch (ClassNotFoundException | NoClassDefFoundError e) {
            return Optional.empty();
        }
    }
727163
public <S extends Service> S getService(Class<S> type) {
		for (final Service serv : this.serviceManager.servicesByState().values()) {
			if (serv.isRunning() && type.isInstance(serv)) {
				return type.cast(serv);
			}
		}
		return null;
	}
885711
@Override
  public <T> ServiceBuilder service(Class<T> type)
  {
    Key<?> key = Key.of(type, ServiceImpl.class);

    return service(key, type);
  }
705312
@VisibleForTesting
  public static <T> Iterable<T> getCandidatesViaServiceLoader(Class<T> klass, ClassLoader cl) {
    return ServiceProviders.getCandidatesViaServiceLoader(klass, cl);
  }
816651
static <T,X extends T> T createProviderForClass(final PluggableService<T> service, final Class<X> cls) throws PluginException,
            ProviderCreationException {
        debug("Try loading provider " + cls.getName());
        if(!(service instanceof JavaClassProviderLoadable)){
            return null;
        }
        JavaClassProviderLoadable<T> loadable = (JavaClassProviderLoadable<T>) service;
        final Plugin annotation = getPluginMetadata(cls);

        final String pluginname = annotation.name();

        if (!loadable.isValidProviderClass(cls)) {
            throw new PluginException("Class " + cls.getName() + " was not a valid plugin class for service: " 
                    + service.getName() + ". Expected class " + cls.getName() + ", with a public constructor with no parameter");
        }
        debug("Succeeded loading plugin " + cls.getName() + " for service: " + service.getName());
        return loadable.createProviderInstance(cls, pluginname);
    }
570801
public Object getService(String interfaceClassName, String serviceClassName, String versionRange, Dictionary<String,String> filter)
    {
        return ClassServiceUtility.getClassService().getClassFinder(context).getClassBundleService(interfaceClassName, serviceClassName, versionRange, filter, -1);
    }
955885
public static <T> Observable<T> justOne(T t) {
		return Observable.unsafeCreate(new OnSubscribeJustOneWithBackpressure<T>(t));
	}
211083
@Override
    public T addAsServiceProviderAndClasses(Class<?> serviceInterface, Class<?>... serviceImpls)
        throws IllegalArgumentException {
        Validate.notNull(serviceInterface, "ServiceInterface must be specified");
        Validate.notNullAndNoNullValues(serviceImpls, "ServiceImpls must be specified and can not contain null values");

        addAsServiceProvider(serviceInterface, serviceImpls);
        addClass(serviceInterface);
        return addClasses(serviceImpls);
    }