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

net.peachjean.commons.base.service.factoryClass.st Maven / Gradle / Ivy

The newest version!
$if(serviceType.packageName)$package $serviceType.packageName$;$endif$

import net.peachjean.commons.base.service.ServiceLoader;
import net.peachjean.commons.base.service.ServiceImplementation;

public class $serviceType.simpleName$Factory {

	public static final Class<$serviceType.simpleName$> SERVICE_TYPE = $serviceType.simpleName$.class;
	private static final ServiceLoader<$serviceType.simpleName$> SERVICE_LOADER = new ServiceLoader<$serviceType.simpleName$>(SERVICE_TYPE);

	private final ServiceImplementation implementation;

	public $serviceType.simpleName$Factory(final ServiceImplementation implementation)
	{
		this.implementation = implementation;
	}

$serviceType.constructorArgList:{argList|
	public $serviceType.simpleName$ create($argList:{arg|$arg.type$ $arg.name$}; separator=", "$)
	{
		return implementation.instantiate($argList:{arg|$arg.name$}; separator=", "$);
	}

	public static $serviceType.simpleName$ instantiate(String name$argList:{arg|, $arg.type$ $arg.name$}$)
	{
		return createFactory(name).create($argList:{arg|$arg.name$}; separator=", "$);
	}

}$
	public static $serviceType.simpleName$Factory createFactory(String name)
	{
		final ServiceImplementation implementation = SERVICE_LOADER.lookup(name);
		return new $serviceType.simpleName$Factory(implementation);
	}


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy