package org.fcrepo.serialization;

import org.slf4j.Logger;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

import static org.slf4j.LoggerFactory.getLogger;

/**
 * Helper service that aggregates serializers and makes them accessible by key
 */
@Component
public class SerializerUtil implements ApplicationContextAware {
    private static final Logger LOGGER = getLogger(SerializerUtil.class);
    private ApplicationContext applicationContext;
    private Map<String, FedoraObjectSerializer> serializerMap;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public FedoraObjectSerializer getSerializer(final String format) {
        return getFedoraObjectSerializers().get(format);
    }

    public Map<String, FedoraObjectSerializer> getFedoraObjectSerializers() {
        return serializerMap;
    }

    @PostConstruct
    public void buildFedoraObjectSerializersMap() {
        final Map<String, FedoraObjectSerializer> beans = applicationContext.getBeansOfType(FedoraObjectSerializer.class);

        final Map<String, FedoraObjectSerializer> m = new HashMap<>();

        for(Map.Entry<String, FedoraObjectSerializer> e : beans.entrySet()) {
            m.put(e.getValue().getKey(), e.getValue());
        }

        serializerMap = m;

    }
}

@@ -1544,49 +1544,214 @@
     
-m.put(e.getValue().getKey(), e.getValue()
+final FedoraObjectSerializer serializer = e.getValue();%0A            LOGGER.info(%22Registering serializer %7B%7D for format %7B%7D%22, serializer, serializer.getKey());%0A            m.put(serializer.getKey(), serializer
 );%0A 

add logging to serializer map builder