br.com.objectos.way.etc.EtcLoaderWrapper Maven / Gradle / Ivy
The newest version!
/*
* EtcLoaderWrapper.java criado em 27/12/2013
*
* Propriedade de Objectos Fábrica de Software LTDA.
* Reprodução parcial ou total proibida.
*/
package br.com.objectos.way.etc;
import com.google.inject.Injector;
/**
* @author [email protected] (Marcio Endo)
*/
abstract class EtcLoaderWrapper {
private EtcLoaderWrapper() {
}
public static EtcLoaderWrapper forInstance(EtcLoader instance) {
return new InstanceBound(instance);
}
public static EtcLoaderWrapper forType(Class extends EtcLoader> type) {
return new TypeBound(type);
}
abstract T load(Injector injector, Mapping mapping);
private static class InstanceBound extends EtcLoaderWrapper {
private final EtcLoader loader;
public InstanceBound(EtcLoader loader) {
this.loader = loader;
}
@Override
T load(Injector injector, Mapping mapping) {
return loader.load(mapping);
}
}
private static class TypeBound extends EtcLoaderWrapper {
private final Class extends EtcLoader> type;
public TypeBound(Class extends EtcLoader> type) {
this.type = type;
}
@Override
T load(Injector injector, Mapping mapping) {
return injector.getInstance(type).load(mapping);
}
}
}