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

io.quarkus.resteasy.reactive.jaxb.runtime.JAXBContextContextResolver Maven / Gradle / Ivy

There is a newer version: 3.15.1
Show newest version
package io.quarkus.resteasy.reactive.jaxb.runtime;

import java.util.concurrent.ConcurrentHashMap;

import jakarta.enterprise.inject.Instance;
import jakarta.ws.rs.ext.ContextResolver;
import jakarta.xml.bind.JAXBContext;

import io.quarkus.jaxb.runtime.JaxbContextCustomizer;
import io.quarkus.jaxb.runtime.JaxbContextProducer;

public class JAXBContextContextResolver implements ContextResolver {

    private final ConcurrentHashMap, JAXBContext> cache = new ConcurrentHashMap<>();

    private final Instance customizers;

    private final JaxbContextProducer jaxbContextProducer;

    public JAXBContextContextResolver(Instance customizers,
            JaxbContextProducer jaxbContextProducer) {
        this.customizers = customizers;
        this.jaxbContextProducer = jaxbContextProducer;
    }

    @Override
    public JAXBContext getContext(Class clazz) {
        JAXBContext jaxbContext = cache.get(clazz);
        if (jaxbContext == null) {
            jaxbContext = jaxbContextProducer.createJAXBContext(customizers, clazz);
            cache.put(clazz, jaxbContext);
        }

        return jaxbContext;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy