/**
 * Do not edit.
 *
 * This file was auto-generated
 * by the Web Service Director Eclipse Plugin Edition.
 */

package com.nec.webotx.webservice.director.Hello;

import com.nec.webotx.webservice.xml.rpc.server.http.MessageContextProperties;
import com.nec.webotx.webservice.xml.rpc.streaming.*;
import com.nec.webotx.webservice.xml.rpc.encoding.*;
import com.nec.webotx.webservice.xml.rpc.encoding.soap.SOAPConstants;
import com.nec.webotx.webservice.xml.rpc.encoding.soap.SOAP12Constants;
import com.nec.webotx.webservice.xml.rpc.encoding.literal.*;
import com.nec.webotx.webservice.xml.rpc.soap.streaming.*;
import com.nec.webotx.webservice.xml.rpc.soap.message.*;
import com.nec.webotx.webservice.xml.rpc.soap.SOAPVersion;
import com.nec.webotx.webservice.xml.rpc.soap.SOAPEncodingConstants;
import com.nec.webotx.webservice.xml.rpc.wsdl.document.schema.SchemaConstants;
import javax.xml.namespace.QName;
import java.rmi.RemoteException;
import java.util.Iterator;
import java.lang.reflect.*;
import java.lang.Class;
import com.nec.webotx.webservice.xml.rpc.server.*;
import javax.xml.rpc.handler.HandlerInfo;
import com.nec.webotx.webservice.xml.rpc.client.HandlerChainImpl;

public class Hello_PortType_Tie
    extends com.nec.webotx.webservice.xml.rpc.server.TieBase implements SerializerConstants {
    
    
    public Hello_PortType_Tie() throws Exception {
        super(new com.nec.webotx.webservice.director.Hello.Hello_Service_SerializerRegistry().getRegistry());
        initialize(internalTypeMappingRegistry);
    }
    
    /*
     * This method does the actual method invocation for operation: say_hello_Hello
     */
    private void invoke_say_hello_Hello(StreamingHandlerState state) throws Exception {
        
        com.nec.webotx.webservice.director.Hello.Hello_say_hello_Hello_RequestStruct2 myHello_say_hello_Hello_RequestStruct2 = null;
        Object myHello_say_hello_Hello_RequestStruct2Obj =
            state.getRequest().getBody().getValue();
        
        if (myHello_say_hello_Hello_RequestStruct2Obj instanceof SOAPDeserializationState) {
            myHello_say_hello_Hello_RequestStruct2 = (com.nec.webotx.webservice.director.Hello.Hello_say_hello_Hello_RequestStruct2)((SOAPDeserializationState)myHello_say_hello_Hello_RequestStruct2Obj).getInstance();
        } else {
            myHello_say_hello_Hello_RequestStruct2 = (com.nec.webotx.webservice.director.Hello.Hello_say_hello_Hello_RequestStruct2)myHello_say_hello_Hello_RequestStruct2Obj;
        }
        
        try {
            java.lang.String result = 
                ((com.nec.webotx.webservice.director.Hello.Hello_PortType) getTarget()).say_hello_Hello(myHello_say_hello_Hello_RequestStruct2.getString_1());
            com.nec.webotx.webservice.director.Hello.Hello_say_hello_Hello_ResponseStruct2 myHello_say_hello_Hello_ResponseStruct2 =
                new com.nec.webotx.webservice.director.Hello.Hello_say_hello_Hello_ResponseStruct2();
            SOAPHeaderBlockInfo headerInfo;
            myHello_say_hello_Hello_ResponseStruct2.setResult(result);
            
            SOAPBlockInfo bodyBlock = new SOAPBlockInfo(ns1_say_hello_Hello_say_hello_HelloResponse_QNAME);
            bodyBlock.setValue(myHello_say_hello_Hello_ResponseStruct2);
            bodyBlock.setSerializer(ns1_myHello_say_hello_Hello_ResponseStruct2_SOAPSerializer);
            state.getResponse().setBody(bodyBlock);
        } catch (javax.xml.rpc.soap.SOAPFaultException e) {
            SOAPFaultInfo fault = new SOAPFaultInfo(e.getFaultCode(),
                e.getFaultString(), e.getFaultActor(), e.getDetail());
            SOAPBlockInfo faultBlock = new SOAPBlockInfo(com.nec.webotx.webservice.xml.rpc.encoding.soap.SOAPConstants.QNAME_SOAP_FAULT);
            faultBlock.setValue(fault);
            faultBlock.setSerializer(new SOAPFaultInfoSerializer(false, e.getDetail()==null));
            state.getResponse().setBody(faultBlock);
            state.getResponse().setFailure(true);
        }
    }
    
    /*
     * This method must determine the opcode of the operation that has been invoked.
     */
    protected void peekFirstBodyElement(XMLReader bodyReader, SOAPDeserializationContext deserializationContext, StreamingHandlerState state) throws Exception {
        if (bodyReader.getName().equals(ns1_say_hello_Hello_say_hello_Hello_QNAME)) {
            state.getRequest().setOperationCode(say_hello_Hello_OPCODE);
        }
        else {
            throw new SOAPProtocolViolationException("soap.operation.unrecognized", bodyReader.getName().toString());
        }
    }
    
    /*
     *  this method deserializes the request/response structure in the body
     */
    protected void readFirstBodyElement(XMLReader bodyReader, SOAPDeserializationContext deserializationContext, StreamingHandlerState  state) throws Exception {
        int opcode = state.getRequest().getOperationCode();
        switch (opcode) {
            case say_hello_Hello_OPCODE:
                deserialize_say_hello_Hello(bodyReader, deserializationContext, state);
                break;
            default:
                throw new SOAPProtocolViolationException("soap.operation.unrecognized", Integer.toString(opcode));
        }
    }
    
    
    
    /*
     * This method deserializes the body of the say_hello_Hello operation.
     */
    private void deserialize_say_hello_Hello(XMLReader bodyReader, SOAPDeserializationContext deserializationContext, StreamingHandlerState state) throws Exception {
        Object myHello_say_hello_Hello_RequestStruct2Obj =
            ns1_myHello_say_hello_Hello_RequestStruct2_SOAPSerializer.deserialize(ns1_say_hello_Hello_say_hello_Hello_QNAME,
                bodyReader, deserializationContext);
        
        SOAPBlockInfo bodyBlock = new SOAPBlockInfo(ns1_say_hello_Hello_say_hello_Hello_QNAME);
        bodyBlock.setValue(myHello_say_hello_Hello_RequestStruct2Obj);
        state.getRequest().setBody(bodyBlock);
    }
    
    
    /*
     * This method must invoke the correct method on the servant based on the opcode.
     */
    protected void processingHook(StreamingHandlerState state) throws Exception {
        switch (state.getRequest().getOperationCode()) {
            case say_hello_Hello_OPCODE:
                invoke_say_hello_Hello(state);
                break;
            default:
                throw new SOAPProtocolViolationException("soap.operation.unrecognized", Integer.toString(state.getRequest().getOperationCode()));
        }
    }
    
    public String getDefaultEnvelopeEncodingStyle() {
        return SOAPNamespaceConstants.ENCODING;
    }
    
    public String getImplicitEnvelopeEncodingStyle() {
        return "";
    }
    
    
    /*
     * This method must determine the opcode of the operation given the QName of the first body element.
     */
    public int getOpcodeForFirstBodyElementName(QName name) {
        if (name == null) {
            return InternalSOAPMessage.NO_OPERATION;
        }
        if (name.equals(ns1_say_hello_Hello_say_hello_Hello_QNAME)) {
            return say_hello_Hello_OPCODE;
        }
        return super.getOpcodeForFirstBodyElementName(name);
    }
    
    
    private Method internalGetMethodForOpcode(int opcode) throws ClassNotFoundException, NoSuchMethodException {
        
        Method theMethod = null;
        
        switch(opcode) {
            case say_hello_Hello_OPCODE:
                {
                    Class[] carray = { java.lang.String.class };
                    theMethod = (com.nec.webotx.webservice.director.Hello.Hello_PortType.class).getMethod("say_hello_Hello", carray);
                }
                break;
            
            default:
        }
        return theMethod;
    }
    
    private Method[] methodMap = new Method[1];
    
    /*
     * This method returns the Method Obj for a specified opcode.
     */
    public Method getMethodForOpcode(int opcode) throws ClassNotFoundException, NoSuchMethodException {
         
        if (opcode <= InternalSOAPMessage.NO_OPERATION ) {
            return null;
        }
         
        if (opcode >= 1 ) {
            return null;
        }
         
        if (methodMap[opcode] == null)  {
            methodMap[opcode] = internalGetMethodForOpcode(opcode);
        }
         
        return methodMap[opcode];
    }
    
    /*
     * This method returns an array containing (prefix, nsURI) pairs.
     */
    protected String[] getNamespaceDeclarations() {
        return myNamespace_declarations;
    }
    
    /*
     * This method returns an array containing the names of the headers we understand.
     */
    public QName[] getUnderstoodHeaders() {
        return understoodHeaderNames;
    }
    
    private void initialize(InternalTypeMappingRegistry registry) throws Exception {
        ns1_myHello_say_hello_Hello_RequestStruct2_SOAPSerializer = (CombinedSerializer)registry.getSerializer(SOAPConstants.NS_SOAP_ENCODING, com.nec.webotx.webservice.director.Hello.Hello_say_hello_Hello_RequestStruct2.class, ns1_say_hello_Hello_TYPE_QNAME);
        ns1_myHello_say_hello_Hello_ResponseStruct2_SOAPSerializer = (CombinedSerializer)registry.getSerializer(SOAPConstants.NS_SOAP_ENCODING, com.nec.webotx.webservice.director.Hello.Hello_say_hello_Hello_ResponseStruct2.class, ns1_say_hello_HelloResponse_TYPE_QNAME);
    }
    
    private static final QName portName = new QName("http://sample/Hello", "HelloPort");
    private static final int say_hello_Hello_OPCODE = 0;
    private static final QName ns1_say_hello_Hello_say_hello_Hello_QNAME = new QName("http://sample/Hello", "say_hello_Hello");
    private static final QName ns1_say_hello_Hello_TYPE_QNAME = new QName("http://sample/Hello", "say_hello_Hello");
    private CombinedSerializer ns1_myHello_say_hello_Hello_RequestStruct2_SOAPSerializer;
    private static final QName ns1_say_hello_Hello_say_hello_HelloResponse_QNAME = new QName("http://sample/Hello", "say_hello_HelloResponse");
    private static final QName ns1_say_hello_HelloResponse_TYPE_QNAME = new QName("http://sample/Hello", "say_hello_HelloResponse");
    private CombinedSerializer ns1_myHello_say_hello_Hello_ResponseStruct2_SOAPSerializer;
    private static final String[] myNamespace_declarations =
                                        new String[] {
                                            "ns0", "http://sample/Hello"
                                        };
    
    private static final QName[] understoodHeaderNames = new QName[] {  };
}
