
package de.ivu.elect.presentation.security;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import de.ivu.elect.business.security.UseCasePermission;

@FacesConverter(value = ElectCommonPermissionConverterForId.CONVERTER_ID)
public class ElectCommonPermissionConverterForId implements Converter {

  public static final String CONVERTER_ID = "electCommonPermissionConverter";
  private static final ElectCommonPermissionConverterForId INSTANCE = new ElectCommonPermissionConverterForId();

  @Override
  public Object getAsObject(FacesContext ctx, UIComponent component, String value) {
    return UseCasePermission.valueOf(value);
  }

  @Override
  public String getAsString(FacesContext ctx, UIComponent component, Object value) {
    return ((UseCasePermission) value).name();
  }

  public static ElectCommonPermissionConverterForId getInstance() {
    return INSTANCE;
  }

}
