/*
 * Copyright 2003-2006 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * This file was auto-generated by the Axis C++ Web Service Generator (WSDL2Ws)
 * This file contains Web Service Wrapper implementations
 */

#include "AxisAdminServiceWrapper.hpp"
#include "../../common/IAdminUtils.h"

AxisAdminServiceWrapper::AxisAdminServiceWrapper()
{
}

AxisAdminServiceWrapper::~AxisAdminServiceWrapper()
{
}

/* implementation of WrapperClassHandler interface */
void AxisAdminServiceWrapper::onFault(void *pMsg)
{
}

/*
 * This method invokes the right service method 
 */
int AxisAdminServiceWrapper::invoke(void *pMsg)
{
    IMessageData* mc = (IMessageData*)pMsg;
    const AxisChar *method = mc->getOperationName();
    if( 0 == strcmp(method, "updateWSDD") )
    {
        return updateWSDD(mc);
    }
    else if ( 0 == strcmp(method, "stopAxis") )
    {
        return stopAxis(mc);
    }
    else
    {
        return AXIS_FAIL;
    }
}

/* Methods corresponding to the web service methods */

/*
 * This method wrap the service method 
 */
int AxisAdminServiceWrapper::updateWSDD(void* pMsg)
{
    IMessageData* mc = (IMessageData*)pMsg;
    int nStatus;
    IWrapperSoapSerializer* pIWSSZ = NULL;
    mc->getSoapSerializer(&pIWSSZ);
    if (!pIWSSZ)
    {
        return AXIS_FAIL;
    }
    IWrapperSoapDeSerializer* pIWSDZ = NULL;
    mc->getSoapDeSerializer(&pIWSDZ);
    if (!pIWSDZ)
    {
        return AXIS_FAIL;
    }
    /* check whether we have got correct message */
    if (AXIS_SUCCESS != pIWSDZ->checkMessageBody("updateWSDD", "http://www.opensource.lk/xsd"))
    {
        return AXIS_FAIL;
    }
    pIWSSZ->createSoapMethod("updateWSDDResponse", "http://www.opensource.lk/xsd");

    xsd__base64Binary v0;
    xsd__base64Binary * pValue0 = pIWSDZ->getElementAsBase64Binary("wsdd", 0);
    if (pValue0)
    {
        v0 = *pValue0;
        Axis::AxisDelete( (void *) pValue0, XSD_BASE64BINARY);
    }

    if (AXIS_SUCCESS != (nStatus = pIWSDZ->getStatus()))
    {
        return nStatus;
    }

    try
    {
        xsd__int size = 0;
        xsd__boolean ret = false_;
        IAdminUtils* pAdminUtils;
        mc->getAdminUtils (&pAdminUtils);
        if (pAdminUtils)
        {
            if (AXIS_SUCCESS == pAdminUtils->updateWSDD ((char*) v0.get(size)))
            {
                ret = true_;
            }
        }
        return pIWSSZ->addOutputParam ("return", (void*) &ret, XSD_BOOLEAN);
    }
    catch(...)
    {
        return AXIS_FAIL;
    }
}


/*
 * This method wrap the service method 
 */
int AxisAdminServiceWrapper::stopAxis(void* pMsg)
{
	IMessageData* mc = (IMessageData*)pMsg;
	int nStatus;
	IWrapperSoapSerializer* pIWSSZ = NULL;
	mc->getSoapSerializer(&pIWSSZ);
	if (!pIWSSZ)
	{
		return AXIS_FAIL;
	}
	IWrapperSoapDeSerializer* pIWSDZ = NULL;
	mc->getSoapDeSerializer(&pIWSDZ);
	if (!pIWSDZ)
	{
		return AXIS_FAIL;
	}
	/* check whether we have got correct message */
	if (AXIS_SUCCESS != pIWSDZ->checkMessageBody("stopAxis", "http://www.opensource.lk/xsd"))
	{
		return AXIS_FAIL;
	}
	pIWSSZ->createSoapMethod("stopAxisResponse", "http://www.opensource.lk/xsd");

	if (AXIS_SUCCESS != (nStatus = pIWSDZ->getStatus()))
	{
		return nStatus;
	}

	try
	{
        xsd__boolean ret = false_;
		IAdminUtils* pAdminUtils;
        mc->getAdminUtils (&pAdminUtils);
        if (pAdminUtils)
        {
            pAdminUtils->stopAxis ();
            ret = true_;
        }
        return pIWSSZ->addOutputParam ("return", (void*) &ret, XSD_BOOLEAN);
	}
	catch(...)
	{
		return AXIS_FAIL;
	}
}

