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

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

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

import java.io.File;
import java.util.Map;

import com.google.common.annotations.VisibleForTesting;
import com.google.inject.Injector;

/**
 * @author [email protected] (Marcio Endo)
 */
class Etc {

  private final Class type;

  private final File file;

  private final EtcLoaderWrapper loader;

  public Etc(Class type, File file, EtcLoaderWrapper loader) {
    this.type = type;
    this.file = file;
    this.loader = loader;
  }

  @VisibleForTesting
  public Class getType() {
    return type;
  }

  public Object read(Injector injector, Mappings mappings) {
    Mapping mapping = mappings.read(file);
    return loader.load(injector, mapping);
  }

  public Object readProperty(Mappings mappings, EtcProperty property) {
    Map map = mappings.readAsMap(file);
    String key = property.getProperty();
    return map.get(key);
  }

  public EtcProperty set(EtcProperty property, String value) {
    return property.set(type, value);
  }

  public void write(Mappings mappings, Object model) {
    mappings.write(model, file);
  }

  public void writeProperty(Mappings mappings, EtcProperty property) {
    mappings.writeProperty(property, file);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy