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

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

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 Aggregator_PortType_Tie
    extends com.nec.webotx.webservice.xml.rpc.server.TieBase implements SerializerConstants {
    
    
    public Aggregator_PortType_Tie() throws Exception {
        super(new com.nec.webotx.webservice.director.aggregator.Aggregator_Service_SerializerRegistry().getRegistry());
        initialize(internalTypeMappingRegistry);
    }
    
    /*
     * This method does the actual method invocation for operation: sampleAggregation_Aggregation
     */
    private void invoke_sampleAggregation_Aggregation(StreamingHandlerState state) throws Exception {
        
        com.nec.webotx.webservice.director.aggregator.Aggregator_sampleAggregation_Aggregation_RequestStruct2 myAggregator_sampleAggregation_Aggregation_RequestStruct2 = null;
        Object myAggregator_sampleAggregation_Aggregation_RequestStruct2Obj =
            state.getRequest().getBody().getValue();
        
        if (myAggregator_sampleAggregation_Aggregation_RequestStruct2Obj instanceof SOAPDeserializationState) {
            myAggregator_sampleAggregation_Aggregation_RequestStruct2 = (com.nec.webotx.webservice.director.aggregator.Aggregator_sampleAggregation_Aggregation_RequestStruct2)((SOAPDeserializationState)myAggregator_sampleAggregation_Aggregation_RequestStruct2Obj).getInstance();
        } else {
            myAggregator_sampleAggregation_Aggregation_RequestStruct2 = (com.nec.webotx.webservice.director.aggregator.Aggregator_sampleAggregation_Aggregation_RequestStruct2)myAggregator_sampleAggregation_Aggregation_RequestStruct2Obj;
        }
        
        try {
            com.nec.webotx.webservice.sample.Info result = 
                ((com.nec.webotx.webservice.director.aggregator.Aggregator_PortType) getTarget()).sampleAggregation_Aggregation(myAggregator_sampleAggregation_Aggregation_RequestStruct2.getString_1(), myAggregator_sampleAggregation_Aggregation_RequestStruct2.getString_2(), myAggregator_sampleAggregation_Aggregation_RequestStruct2.getString_3(), myAggregator_sampleAggregation_Aggregation_RequestStruct2.getString_4());
            com.nec.webotx.webservice.director.aggregator.Aggregator_sampleAggregation_Aggregation_ResponseStruct2 myAggregator_sampleAggregation_Aggregation_ResponseStruct2 =
                new com.nec.webotx.webservice.director.aggregator.Aggregator_sampleAggregation_Aggregation_ResponseStruct2();
            SOAPHeaderBlockInfo headerInfo;
            myAggregator_sampleAggregation_Aggregation_ResponseStruct2.setResult(result);
            
            SOAPBlockInfo bodyBlock = new SOAPBlockInfo(ns1_sampleAggregation_Aggregation_sampleAggregation_AggregationResponse_QNAME);
            bodyBlock.setValue(myAggregator_sampleAggregation_Aggregation_ResponseStruct2);
            bodyBlock.setSerializer(ns1_myAggregator_sampleAggregation_Aggregation_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_sampleAggregation_Aggregation_sampleAggregation_Aggregation_QNAME)) {
            state.getRequest().setOperationCode(sampleAggregation_Aggregation_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 sampleAggregation_Aggregation_OPCODE:
                deserialize_sampleAggregation_Aggregation(bodyReader, deserializationContext, state);
                break;
            default:
                throw new SOAPProtocolViolationException("soap.operation.unrecognized", Integer.toString(opcode));
        }
    }
    
    
    
    /*
     * This method deserializes the body of the sampleAggregation_Aggregation operation.
     */
    private void deserialize_sampleAggregation_Aggregation(XMLReader bodyReader, SOAPDeserializationContext deserializationContext, StreamingHandlerState state) throws Exception {
        Object myAggregator_sampleAggregation_Aggregation_RequestStruct2Obj =
            ns1_myAggregator_sampleAggregation_Aggregation_RequestStruct2_SOAPSerializer.deserialize(ns1_sampleAggregation_Aggregation_sampleAggregation_Aggregation_QNAME,
                bodyReader, deserializationContext);
        
        SOAPBlockInfo bodyBlock = new SOAPBlockInfo(ns1_sampleAggregation_Aggregation_sampleAggregation_Aggregation_QNAME);
        bodyBlock.setValue(myAggregator_sampleAggregation_Aggregation_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 sampleAggregation_Aggregation_OPCODE:
                invoke_sampleAggregation_Aggregation(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_sampleAggregation_Aggregation_sampleAggregation_Aggregation_QNAME)) {
            return sampleAggregation_Aggregation_OPCODE;
        }
        return super.getOpcodeForFirstBodyElementName(name);
    }
    
    
    private Method internalGetMethodForOpcode(int opcode) throws ClassNotFoundException, NoSuchMethodException {
        
        Method theMethod = null;
        
        switch(opcode) {
            case sampleAggregation_Aggregation_OPCODE:
                {
                    Class[] carray = { java.lang.String.class,java.lang.String.class,java.lang.String.class,java.lang.String.class };
                    theMethod = (com.nec.webotx.webservice.director.aggregator.Aggregator_PortType.class).getMethod("sampleAggregation_Aggregation", 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_myAggregator_sampleAggregation_Aggregation_ResponseStruct2_SOAPSerializer = (CombinedSerializer)registry.getSerializer(SOAPConstants.NS_SOAP_ENCODING, com.nec.webotx.webservice.director.aggregator.Aggregator_sampleAggregation_Aggregation_ResponseStruct2.class, ns1_sampleAggregation_AggregationResponse_TYPE_QNAME);
        ns1_myAggregator_sampleAggregation_Aggregation_RequestStruct2_SOAPSerializer = (CombinedSerializer)registry.getSerializer(SOAPConstants.NS_SOAP_ENCODING, com.nec.webotx.webservice.director.aggregator.Aggregator_sampleAggregation_Aggregation_RequestStruct2.class, ns1_sampleAggregation_Aggregation_TYPE_QNAME);
    }
    
    private static final QName portName = new QName("http://sample/WebOTX", "AggregatorPort");
    private static final int sampleAggregation_Aggregation_OPCODE = 0;
    private static final QName ns1_sampleAggregation_Aggregation_sampleAggregation_Aggregation_QNAME = new QName("http://sample/WebOTX", "sampleAggregation_Aggregation");
    private static final QName ns1_sampleAggregation_Aggregation_TYPE_QNAME = new QName("http://sample/WebOTX", "sampleAggregation_Aggregation");
    private CombinedSerializer ns1_myAggregator_sampleAggregation_Aggregation_RequestStruct2_SOAPSerializer;
    private static final QName ns1_sampleAggregation_Aggregation_sampleAggregation_AggregationResponse_QNAME = new QName("http://sample/WebOTX", "sampleAggregation_AggregationResponse");
    private static final QName ns1_sampleAggregation_AggregationResponse_TYPE_QNAME = new QName("http://sample/WebOTX", "sampleAggregation_AggregationResponse");
    private CombinedSerializer ns1_myAggregator_sampleAggregation_Aggregation_ResponseStruct2_SOAPSerializer;
    private static final String[] myNamespace_declarations =
                                        new String[] {
                                            "ns0", "http://sample/WebOTX",
                                            "ns1", "http://sample"
                                        };
    
    private static final QName[] understoodHeaderNames = new QName[] {  };
}
