package com.github.aesteve.vertx.nubes.handlers;

import java.lang.annotation.Annotation;
import java.util.HashMap;
import java.util.Map;

import com.github.aesteve.vertx.nubes.reflections.factories.AnnotationProcessorFactory;

public class AnnotationProcessorRegistry {

	private Map<Class<? extends Annotation>, AnnotationProcessorFactory<? extends Annotation>> map;

	public AnnotationProcessorRegistry() {
		map = new HashMap<>();
	}

	public <T extends Annotation> void registerProcessor(Class<T> annotation, AnnotationProcessorFactory<T> processor) {
		map.put(annotation, processor);
	}

	@SuppressWarnings("unchecked")
	public <T extends Annotation> AnnotationProcessor<T> getProcessor(T annotation) {
		AnnotationProcessorFactory<T> processor = (AnnotationProcessorFactory<T>) getProcessor(annotation.annotationType());
		if (processor == null) {
			return null;
		}
		return processor.create(annotation);
	}

	@SuppressWarnings("unchecked")
	private <T extends Annotation> AnnotationProcessorFactory<T> getProcessor(Class<T> annotation) {
		return (AnnotationProcessorFactory<T>) map.get(annotation);
	}
}

@@ -357,17 +357,123 @@
 ation%3E%3E 
-m
+factoryMap;%0A%09private Map%3CClass%3C? extends Annotation%3E, AnnotationProcessor%3C? extends Annotation%3E%3E processorM
 ap;%0A%0A%09pu
@@ -511,17 +511,58 @@
 y() %7B%0A%09%09
-m
+factoryMap = new HashMap%3C%3E();%0A%09%09processorM
 ap = new
@@ -699,17 +699,182 @@
 or) %7B%0A%09%09
-m
+factoryMap.put(annotation, processor);%0A%09%7D%0A%0A%09public %3CT extends Annotation%3E void registerProcessor(Class%3CT%3E annotation, AnnotationProcessor%3CT%3E processor) %7B%0A%09%09processorM
 ap.put(a
@@ -1047,25 +1047,23 @@
 tory%3CT%3E 
-process
+fact
 or
+y
  = (Anno
@@ -1092,25 +1092,23 @@
 %3CT%3E) get
-Process
+Fact
 or
+y
 (annotat
@@ -1140,19 +1140,17 @@
 if (
-processor =
+factory !
 = nu
@@ -1169,43 +1169,257 @@
 urn 
-null;%0A%09%09%7D%0A%09%09return processor.create
+factory.create(annotation);%0A%09%09%7D%0A%09%09return getSimpleProcessor(annotation);%0A%09%7D%0A%0A%09@SuppressWarnings(%22unchecked%22)%0A%09private %3CT extends Annotation%3E AnnotationProcessor%3CT%3E getSimpleProcessor(T annotation) %7B%0A%09%09return (AnnotationProcessor%3CT%3E) processorMap.get
 (ann
@@ -1529,25 +1529,23 @@
 y%3CT%3E get
-Process
+Fact
 or
+y
 (Class%3CT
@@ -1601,17 +1601,24 @@
 ory%3CT%3E) 
-m
+factoryM
 ap.get(a

add the ability to set a simple annotation processor (for marker annotations, with no value)