package de.javaakademie.cb.gui;

import java.util.Optional;
import java.util.ServiceLoader;

import de.javaakademie.cb.api.ConferenceService;
import de.javaakademie.cb.api.annotation.Sessions;
import de.javaakademie.cb.api.annotation.Speaker;
import de.javaakademie.cb.api.model.Session;

/**
 * ServiceFactory.
 * 
 * @author Guido.Oelmann
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public class ServiceFactory {

	private ServiceLoader<ConferenceService> services = ServiceLoader.load(ConferenceService.class);

	private ConferenceService<?> getServiceByAnnotation(Class clazz) {
		Optional<ConferenceService> service = services.stream()
				.filter(provider -> provider.type().isAnnotationPresent(clazz)).map(ServiceLoader.Provider::get)
				.findAny();
		return service.get();
	}

	public ConferenceService<de.javaakademie.cb.api.model.Speaker> getSpeakerService() {
		return (ConferenceService<de.javaakademie.cb.api.model.Speaker>) getServiceByAnnotation(Speaker.class);
	}

	public ConferenceService<Session> getSessionService() {
		return (ConferenceService<Session>) getServiceByAnnotation(Sessions.class);
	}

}

@@ -289,16 +289,58 @@
 ession;%0D
+%0Aimport java.util.ServiceLoader.Provider;%0D
 %0A%0D%0A/**%0D%0A
@@ -676,23 +676,25 @@
 ervice%3E 
-service
+providers
  = servi
@@ -783,53 +783,65 @@
 map(
-ServiceLoader.Provider::get)%0D%0A%09%09%09%09.findAny();
+Provider::get).findFirst();%0D%0A%09%09services.reload(); // TODO
 %0D%0A%09%09
@@ -847,23 +847,25 @@
 %09return 
-service
+providers
 .get();%0D

Update ServiceFactory.java