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

import java.util.List;

import javax.inject.Inject;
import javax.xml.ws.BindingProvider;

import de.ivu.elect.business.konfiguration.entity.MandantKonfigurationWerte;
import de.ivu.elect.business.mandant.entity.Mandant;

public abstract class AbstractMandantSoapWebService<T> extends AbstractMandantWebService {

  @Inject
  private transient SoapWebServiceHelper soapWebServiceHelper;

  public AbstractMandantSoapWebService() {
    super();
  }

  protected abstract Class<T> getWebServiceClass();

  protected T getServiceEndpoint(Mandant mandant) {
    T serviceEndpoint = soapWebServiceHelper.createService(getWebServiceClass()).getPort(getWebServiceClass());
    soapWebServiceHelper.setupServiceEndpoint((BindingProvider) serviceEndpoint, getServiceUrl(mandant), collectSoapWebServiceHandlers(), isServiceLoggingEnabled(mandant));

    return serviceEndpoint;
  }

  protected abstract List< ? extends AbstractSoapWebServiceHandler> collectSoapWebServiceHandlers();

  protected boolean isServiceLoggingEnabled(Mandant mandant) {
    return getConfiguredBooleanValue(mandant, getServiceLoggingEnabledKonfigurationWert());
  }

  protected abstract MandantKonfigurationWerte getServiceLoggingEnabledKonfigurationWert();
}
