/*
 * #%L
 * fujion
 * %%
 * Copyright (C) 2008 - 2017 Regenstrief Institute, Inc.
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * #L%
 */
package org.fujion.annotation;

import java.util.Map;

import org.fujion.common.RegistryMap;
import org.fujion.common.RegistryMap.DuplicateAction;
import org.fujion.event.Event;

/**
 * Builds a map of event types to implementation classes by scanning class annotations.
 */
public class EventTypeScanner extends AbstractClassScanner<Event, EventType> {

    private static final EventTypeScanner instance = new EventTypeScanner();

    private final Map<String, Class<? extends Event>> typeToClass = new RegistryMap<>(DuplicateAction.ERROR);

    /**
     * Returns a singleton instance of the event type scanner.
     *
     * @return Singleton instance of the event type scanner.
     */
    public static EventTypeScanner getInstance() {
        return instance;
    }

    private EventTypeScanner() {
        super(Event.class, EventType.class);
    }

    /**
     * Creates mapping between event type and its implementation class.
     *
     * @param eventClass Class containing EventType annotation.
     */
    @Override
    protected void doScanClass(Class<Event> eventClass) {
        typeToClass.put(getEventType(eventClass), eventClass);
    }

    /**
     * Returns an implementation class given an event type. Will never return null; for any event
     * types that do not have an explicit implementation class this method will return a generic
     * Event class.
     *
     * @param eventType The event type whose implementation class is sought.
     * @return The implementation class.
     */
    public Class<? extends Event> getEventClass(String eventType) {
        Class<? extends Event> eventClass = typeToClass.get(eventType);
        return eventClass == null ? Event.class : eventClass;
    }

    /**
     * Given an event class, returns the event type implemented by that class.
     *
     * @param eventClass An event class.
     * @return The event type, or null if none is associated with the class.
     */
    public String getEventType(Class<? extends Event> eventClass) {
        EventType eventType = eventClass.getAnnotation(EventType.class);
        return eventType == null ? null : eventType.value();
    }
}

@@ -701,19 +701,71 @@
 va.util.
-Map
+Collections;%0Aimport java.util.Map;%0Aimport java.util.Set
 ;%0A%0Aimpor
@@ -1058,17 +1058,21 @@
 Type%3E %7B%0A
+    
 %0A
-
     priv
@@ -1140,17 +1140,21 @@
 nner();%0A
+    
 %0A
-
     priv
@@ -1255,17 +1255,21 @@
 ERROR);%0A
+    
 %0A
-
     /**%0A
@@ -1485,25 +1485,29 @@
 ance;%0A    %7D%0A
+    
 %0A
-
     private 
@@ -1570,33 +1570,37 @@
 e.class);%0A    %7D%0A
+    
 %0A
-
     /**%0A     * C
@@ -1875,33 +1875,37 @@
 ntClass);%0A    %7D%0A
+    
 %0A
-
     /**%0A     * R
@@ -2452,17 +2452,21 @@
 ;%0A    %7D%0A
+    
 %0A
-
     /**%0A
@@ -2814,24 +2814,24 @@
 ype.class);%0A
-
         retu
@@ -2884,11 +2884,248 @@
 );%0A    %7D
+%0A%0A    /**%0A     * Returns the set of registered event types.%0A     *%0A     * @return The set of registered event types.%0A     */%0A    public Set%3CString%3E getEventTypes() %7B%0A        return Collections.unmodifiableSet(typeToClass.keySet());%0A    %7D
 %0A%7D%0A

Add getEventTypes method.