All Downloads are FREE. Search and download functionalities are using the official Maven repository.

uk.dioxic.mgenerate.common.TransformerRegistry Maven / Gradle / Ivy

The newest version!
package uk.dioxic.mgenerate.common;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uk.dioxic.mgenerate.common.annotation.ValueTransformer;

import java.util.HashMap;
import java.util.Map;

public class TransformerRegistry {

    private final Logger logger = LoggerFactory.getLogger(getClass());
    private final Map transformerMap = new HashMap<>();

    public void addTransformer(Transformer transformer) {
        ValueTransformer annotation = transformer.getClass().getAnnotation(ValueTransformer.class);
        logger.debug("adding [{}] to transformer registry", annotation.value());
        transformerMap.put(annotation.value(), transformer);
    }

    @SuppressWarnings("unchecked")
    public  Transformer get(Class desiredClass) {
        return (Transformer) transformerMap.get(desiredClass);
    }

    public boolean canHandle(Class desiredClass) {
        return transformerMap.containsKey(desiredClass);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy