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

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> 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> type;

    public TypeBound(Class> type) {
      this.type = type;
    }

    @Override
    T load(Injector injector, Mapping mapping) {
      return injector.getInstance(type).load(mapping);
    }

  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy