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

br.com.objectos.way.etc.EtcsGuice Maven / Gradle / Ivy

The newest version!
/*
 * SnakeYaml.java criado em 04/09/2012
 * 
 * Propriedade de Objectos Fábrica de Software LTDA.
 * Reprodução parcial ou total proibida.
 */
package br.com.objectos.way.etc;

import com.google.inject.Inject;
import com.google.inject.Injector;

/**
 * @author [email protected] (Marcio Endo)
 */
class EtcsGuice implements Etcs {

  private final Injector injector;

  private final Mappings mappings;
  private final EtcMap model;

  @Inject
  public EtcsGuice(Injector injector, Mappings mappings, EtcMap model) {
    this.injector = injector;
    this.mappings = mappings;
    this.model = model;
  }

  @Override
  public  T read(Class type) {
    Etc etc = checkType(type);
    Object load = etc.read(injector, mappings);

    @SuppressWarnings("unchecked")
    T res = (T) load; // safe as per checkType
    return res;
  }

  @Override
  public Object readProperty(String key) {
    EtcProperty property = EtcProperty.fromString(key);
    Etc etc = model.get(property);
    return etc.readProperty(mappings, property);
  }

  @Override
  public void write(Object model) {
    Class type = model.getClass();
    Etc etc = checkType(type);
    etc.write(mappings, model);
  }

  @Override
  public void writeProperty(String key, String value) {
    EtcProperty property = EtcProperty.fromString(key);
    Etc etc = model.get(property);
    property = etc.set(property, value);
    etc.writeProperty(mappings, property);
  }

  @Override
  public String toString(Object model) {
    return "";
  }

  private Etc checkType(Class type) {
    return model.get(type);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy