public static T getService()

in utils/src/main/java/org/jclouds/karaf/utils/ServiceHelper.java [63:106]


    public static <T> T getService(String id, String providerOrApi, List<T> services) {
        if (!Strings.isNullOrEmpty(id)) {
            T service = null;
            for (T svc : services) {
                if (id.equals(toName(svc))) {
                    service = svc;
                    break;
                }
            }
            if (service == null) {
                throw new IllegalArgumentException("No service with id" + id + " found.");
            }
            return service;
        }

        if (!Strings.isNullOrEmpty(providerOrApi)) {
            T service = null;
            for (T svc : services) {
                if (providerOrApi.equals(toId(svc))) {
                    service = svc;
                    break;
                }
            }
            if (service == null) {
                throw new IllegalArgumentException("No Provider or Api named " + providerOrApi + " found.");
            }
            return service;
        } else {
            if (services.size() == 0) {
                throw new IllegalArgumentException("No providers are present.  Note: It takes a couple of seconds for the provider to initialize.");
            } else if (services.size() != 1) {
                StringBuilder sb = new StringBuilder();
                for (T svc : services) {
                    if (sb.length() > 0) {
                        sb.append(", ");
                    }
                    sb.append(toId(svc));
                }
                throw new IllegalArgumentException("Multiple providers/apis are present, please select one using the --provider/--api argument in the following values: " + sb.toString());
            } else {
                return services.get(0);
            }
        }
    }