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

com.peterphi.std.guice.common.serviceprops.jaxbref.JAXBResourceFactory Maven / Gradle / Ivy

There is a newer version: 10.1.5
Show newest version
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