/*
 * JBoss, Home of Professional Open Source
 * Copyright 2005, JBoss Inc., and individual contributors as indicated
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.jboss.remoting.transport.soap.axis;

import java.io.IOException;

/**
 * SOAP stub
 *
 * @author <a href="mailto:telrod@e2technologies.net">Tom Elrod</a>
 * @author <a href="jhaynie@vocalcoity.net">Jeff Haynie</a>
 */
public class AxisSOAPConnectorSoapBindingStub extends org.jboss.axis.client.Stub
        implements AxisSOAPConnector
{

    static org.jboss.axis.description.OperationDesc[] _operations;

    static
    {
        _operations = new org.jboss.axis.description.OperationDesc[3];
        org.jboss.axis.description.OperationDesc oper;
        oper = new org.jboss.axis.description.OperationDesc ();
        oper.setName ( "transport" );
        oper.addParameter ( new javax.xml.namespace.QName ( "", "in0" ), new javax.xml.namespace.QName ( "http://www.w3.org/2001/XMLSchema", "base64Binary" ), byte[].class, org.jboss.axis.description.ParameterDesc.IN, false, false );
        oper.setReturnType ( new javax.xml.namespace.QName ( "http://www.w3.org/2001/XMLSchema", "base64Binary" ) );
        oper.setReturnClass ( byte[].class );
        oper.setReturnQName ( new javax.xml.namespace.QName ( "", "invokeReturn" ) );
        oper.setStyle ( org.jboss.axis.enums.Style.RPC );
        oper.setUse ( org.jboss.axis.enums.Use.ENCODED );
        _operations[0] = oper;

        oper = new org.jboss.axis.description.OperationDesc ();
        oper.setName ( "initialize" );
        oper.addParameter ( new javax.xml.namespace.QName ( "", "in0" ), new javax.xml.namespace.QName ( "http://www.w3.org/2001/XMLSchema", "string" ), String.class, org.jboss.axis.description.ParameterDesc.IN, false, false );
        oper.setReturnType ( org.jboss.axis.encoding.XMLType.AXIS_VOID );
        oper.setStyle ( org.jboss.axis.enums.Style.RPC );
        oper.setUse ( org.jboss.axis.enums.Use.ENCODED );
        _operations[1] = oper;

    }

    public AxisSOAPConnectorSoapBindingStub () throws org.jboss.axis.AxisFault
    {
        this ( null );
    }

    public AxisSOAPConnectorSoapBindingStub ( java.net.URL endpointURL, javax.xml.rpc.Service service ) throws org.jboss.axis.AxisFault
    {
        this ( service );
        super.cachedEndpoint = endpointURL;
    }

    public AxisSOAPConnectorSoapBindingStub ( javax.xml.rpc.Service service ) throws org.jboss.axis.AxisFault
    {
        if ( service == null )
        {
            super.service = new org.jboss.axis.client.Service ();
        }
        else
        {
            super.service = service;
        }
    }

    private org.jboss.axis.client.Call createCall () throws java.rmi.RemoteException
    {
        try
        {
            org.jboss.axis.client.Call _call =
                    (org.jboss.axis.client.Call) super.service.createCall ();
            if ( super.maintainSessionSet )
            {
                _call.setMaintainSession ( super.maintainSession );
            }
            if ( super.cachedUsername != null )
            {
                _call.setUsername ( super.cachedUsername );
            }
            if ( super.cachedPassword != null )
            {
                _call.setPassword ( super.cachedPassword );
            }
            if ( super.cachedEndpoint != null )
            {
                _call.setTargetEndpointAddress ( super.cachedEndpoint );
            }
            if ( super.cachedTimeout != null )
            {
                _call.setTimeout ( super.cachedTimeout );
            }
            if ( super.cachedPortName != null )
            {
                _call.setPortName ( super.cachedPortName );
            }
            java.util.Enumeration keys = super.cachedProperties.keys ();
            while ( keys.hasMoreElements () )
            {
                String key = (String) keys.nextElement ();
                _call.setProperty ( key, super.cachedProperties.get ( key ) );
            }
            return _call;
        }
        catch ( Throwable t )
        {
            throw new org.jboss.axis.AxisFault ( "Failure trying to get the Call object", t );
        }
    }

    public byte[] transport ( byte[] in0 ) throws IOException, java.rmi.RemoteException
    {
        if ( super.cachedEndpoint == null )
        {
            throw new org.jboss.axis.NoEndPointException ();
        }
        org.jboss.axis.client.Call _call = createCall ();
        _call.setOperation ( _operations[0] );
        _call.setUseSOAPAction ( true );
        _call.setSOAPActionURI ( "" );
        _call.setOperationName ( new javax.xml.namespace.QName ( "urn:AxisSOAPConnector", "transport" ) );

        setRequestHeaders ( _call );
        Object _resp = _call.invoke ( new Object[]{in0} );

        if ( _resp instanceof java.rmi.RemoteException )
        {
            throw (java.rmi.RemoteException) _resp;
        }
        else if ( _resp instanceof IOException )
        {
            throw (IOException) _resp;
        }
        else
        {
            getResponseHeaders ( _call );
            try
            {
                return (byte[]) _resp;
            }
            catch ( Exception _exception )
            {
                return (byte[]) org.jboss.axis.utils.JavaUtils.convert ( _resp, byte[].class );
            }
        }
    }

    public void initialize ( String in0 ) throws java.rmi.RemoteException
    {
        if ( super.cachedEndpoint == null )
        {
            throw new org.jboss.axis.NoEndPointException ();
        }
        org.jboss.axis.client.Call _call = createCall ();
        _call.setOperation ( _operations[1] );
        _call.setUseSOAPAction ( true );
        _call.setSOAPActionURI ( "" );
        _call.setOperationName ( new javax.xml.namespace.QName ( "urn:AxisSOAPConnector", "initialize" ) );

        setRequestHeaders ( _call );
        Object _resp = _call.invoke ( new Object[]{in0} );

        if ( _resp instanceof java.rmi.RemoteException )
        {
            throw (java.rmi.RemoteException) _resp;
        }
        getResponseHeaders ( _call );
    }


}
