/**
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 1999-2009 Bull S.A.S.
 * Contact: jonas-team@ow2.org
 *
 * This library 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 any later version.
 *
 * This library 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 library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * --------------------------------------------------------------------------
 * $Id$
 * --------------------------------------------------------------------------
*/

package org.ow2.jonas.ws.axis;

import javax.xml.namespace.QName;

import org.apache.axis.AxisProperties;
import org.apache.axis.deployment.wsdd.WSDDConstants;
import org.apache.axis.deployment.wsdd.WSDDProvider;
import org.objectweb.util.monolog.api.BasicLevel;
import org.ow2.jonas.lib.loader.ThreadContextClassLoader;
import org.ow2.jonas.ws.jaxrpc.WSException;
import org.ow2.jonas.ws.jaxrpc.base.JAXRPCService;
import org.ow2.jonas.ws.jaxrpc.factory.JServiceFactory;

/**
 * Implements commons methods declared within the abstract class. It's used
 * AXIS classes for specific deployment aspects.
 *
 * @author Guillaume Sauthier
 * @author Xavier Delplanque
 */
public class AxisService extends JAXRPCService {

    /**
     * Start the AxisWSService.
     * @throws WSException when start fails.
     */
    @Override
    public void doStart() throws WSException {

        super.doStart();

        // Set our custom provider
        QName javaURI = new QName(WSDDConstants.URI_WSDD_JAVA, WSDDJOnASEJBProvider.PROVIDER_NAME);
        WSDDProvider.registerProvider(javaURI, new WSDDJOnASEJBProvider());

        // This method do nothing, but is required here to init AxisProperties class
        AxisProperties.getProperties();

        // Fix for Bug #300844
        // Use a ClassLoader that will delegate to call-time real context ClassLoader
        ClassLoader old = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(new ThreadContextClassLoader());
        AxisProperties.getNameDiscoverer();
        Thread.currentThread().setContextClassLoader(old);

        getLogger().log(BasicLevel.INFO, "Axis Service Started");
    }

    /**
     * Return JServiceFactory instance
     */
     @Override
    public JServiceFactory createServiceFactory() {
         return new JAxisServiceFactory();
     }
}
