package de.ivu.elect.business.internet.control;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

import de.ivu.elect.jee.cdi.BeanManagerUtil;
import de.ivu.elect.jee.faces.FacesMessageUtil;

public class InternetPreasentationUploadServiceTypValidator implements Validator {

  @Override
  public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {

    if (value != null) {
      if (!BeanManagerUtil.getBeanByClass(InternetPreasentationUploadServiceWahlParameterGeaendertEventListener.class).getSupportedTypen()
          .contains(value.toString())) {
        throw new ValidatorException(FacesMessageUtil.createErrorMessage(context, "internet.upload.service.not.supported", "internet.upload.service.not.supported"));
      }
    }

  }
}
