package fi.cas.opplugin;


import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.Remote;
import java.util.HashSet;
import java.util.Iterator;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import org.apache.axis.AxisFault;
import org.apache.axis.EngineConfiguration;
import org.apache.axis.client.Service;
import org.apache.axis.client.Stub;

public class TxServiceGateway_ServiceLocator extends Service implements
        TxServiceGateway_Service {
    private String TxServiceGatewayPort_address = "";

    private String TxServiceGatewayPortWSDDServiceName = "TxServiceGatewayPort";

    private HashSet ports = null;

    public TxServiceGateway_ServiceLocator() {
    }
    public TxServiceGateway_ServiceLocator(String url) {
        TxServiceGatewayPort_address = url;
    }
    public TxServiceGateway_ServiceLocator(EngineConfiguration config) {
        super(config);
    }

    public TxServiceGateway_ServiceLocator(String wsdlLoc, QName sName)
            throws ServiceException {
        super(wsdlLoc, sName);
    }

    public String getTxServiceGatewayPortAddress() {
        return this.TxServiceGatewayPort_address;
    }

    public String getTxServiceGatewayPortWSDDServiceName() {
        return this.TxServiceGatewayPortWSDDServiceName;
    }

    public void setTxServiceGatewayPortWSDDServiceName(String name) {
        this.TxServiceGatewayPortWSDDServiceName = name;
    }

    public TxServiceGateway_PortType getTxServiceGatewayPort()
            throws ServiceException {
        URL endpoint;
        try {
            endpoint = new URL(this.TxServiceGatewayPort_address);
        } catch (MalformedURLException e) {
            throw new ServiceException(e);
        }
        return getTxServiceGatewayPort(endpoint);
    }

    public TxServiceGateway_PortType getTxServiceGatewayPort(URL portAddress)
            throws ServiceException {
        try {
            TxServiceGatewaySoapBindingStub _stub = new TxServiceGatewaySoapBindingStub(
                    portAddress, this);
            _stub.setPortName(getTxServiceGatewayPortWSDDServiceName());
            return _stub;
        } catch (AxisFault e) {
        }
        return null;
    }

    public void setTxServiceGatewayPortEndpointAddress(String address) {
        this.TxServiceGatewayPort_address = address;
    }

    public Remote getPort(Class serviceEndpointInterface)
            throws ServiceException {
        try {
            if (TxServiceGateway_PortType.class
                    .isAssignableFrom(serviceEndpointInterface)) {
                TxServiceGatewaySoapBindingStub _stub = new TxServiceGatewaySoapBindingStub(
                        new URL(this.TxServiceGatewayPort_address), this);
                _stub.setPortName(getTxServiceGatewayPortWSDDServiceName());
                return _stub;
            }
        } catch (Throwable t) {
            throw new ServiceException(t);
        }
        throw new ServiceException(
                "There is no stub implementation for the interface:  "
                        + ((serviceEndpointInterface == null) ? "null"
                        : serviceEndpointInterface.getName()));
    }

    public Remote getPort(QName portName, Class serviceEndpointInterface)
            throws ServiceException {
        if (portName == null) {
            return getPort(serviceEndpointInterface);
        }
        String inputPortName = portName.getLocalPart();
        if ("TxServiceGatewayPort".equals(inputPortName)) {
            return getTxServiceGatewayPort();
        }

        Remote _stub = getPort(serviceEndpointInterface);
        ((Stub) _stub).setPortName(portName);
        return _stub;
    }

    public QName getServiceName() {
        return new QName("http://webservice.fdlk.nstc.com", "TxServiceGateway");
    }

    public Iterator getPorts() {
        if (this.ports == null) {
            this.ports = new HashSet();
            this.ports.add(new QName("http://webservice.fdlk.nstc.com",
                    "TxServiceGatewayPort"));
        }
        return this.ports.iterator();
    }

    public void setEndpointAddress(String portName, String address)
            throws ServiceException {
        if ("TxServiceGatewayPort".equals(portName)) {
            setTxServiceGatewayPortEndpointAddress(address);
        } else {
            throw new ServiceException(
                    " Cannot set Endpoint Address for Unknown Port" + portName);
        }
    }

    public void setEndpointAddress(QName portName, String address)
            throws ServiceException {
        setEndpointAddress(portName.getLocalPart(), address);
    }
}