com.peterphi.std.guice.common.serviceprops.jaxbref.JAXBResourceFactory Maven / Gradle / Ivy
package com.peterphi.std.guice.common.serviceprops.jaxbref;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.peterphi.std.guice.common.serviceprops.composite.GuiceConfig;
import com.peterphi.std.util.jaxb.JAXBSerialiserFactory;
import java.util.HashMap;
import java.util.Map;
@Singleton
public class JAXBResourceFactory
{
private final GuiceConfig config;
private final JAXBSerialiserFactory factory;
private final Map cachedReferences = new HashMap<>();
@Inject
public JAXBResourceFactory(GuiceConfig config, JAXBSerialiserFactory factory)
{
this.config = config;
this.factory = factory;
}
/**
* Resolve the JAXB resource, permitting caching behind the scenes
*
* @param clazz
* @param name
* @param
*
* @return
*/
public T get(Class clazz, final String name)
{
JAXBNamedResourceFactory cached = cachedReferences.get(name);
if (cached == null)
{
cached = new JAXBNamedResourceFactory(this.config, this.factory, name, clazz);
cachedReferences.put(name, cached);
}
return cached.get();
}
/**
* Resolve the JAXB resource once without caching anything
*
* @param clazz
* @param name
* @param
*
* @return
*/
public T getOnce(final Class clazz, final String name)
{
return new JAXBNamedResourceFactory(this.config, this.factory, name, clazz).get();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy