/*
 * 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.net.axis.server;

import org.jboss.axis.AxisFault;
import org.jboss.axis.Message;
import org.jboss.axis.MessageContext;
import org.jboss.axis.handlers.BasicHandler;

import javax.xml.soap.SOAPEnvelope;

/**
 * This class implements the Apache Axis Handler interface.  As such, it is
 * inserted into the chain of Axis Engine Handlers by specifying it in the
 * server-config.wsdd file of the jboss-net-flash.sar file.  This particular
 * handler flags the generated SOAP Envelope to not include namespace
 * declarations.  This is because Flash versions 5 and MX do not support
 * namespaces and only support simple strings.
 * <br>
 * <h3>Change notes</h3>
 *   <ul>
 *   </ul>
 * @created  22.04.2002
 * @author <a href="mailto:fbrier@multideck.com">Frederick N. Brier</a>
 * @version $Revision: 1.5.2.3 $
 */

public class FlashNamespaceHandler extends BasicHandler
{
   /**
    * The instance logger for the service.  Not using a class logger
    * because we want to dynamically obtain the logger name from
    * concrete sub-classes.
    */
//	protected Logger log;

//	public FlashNamespaceHandler()
//	{
//		super();

//		log = Logger.getLogger( getClass() );
//		log.trace( "Constructing" );
//	}

   /**
    * Implements 
    * @see Handler#invoke( MessageContext )
    */
   public void invoke(MessageContext msgContext)
   {
      // log.trace("FlashNamespaceHandler.invoke(): Entered.");
      removeNamespaces(msgContext);
   }


   /*
      * @see Handler#onFault(MessageContext)
   */
   public void onFault(MessageContext msgContext)
   {
//		log.error( "FlashNamespaceHandler.onFault(): Entered." );
   }


   /**
    * Flag the SOAP envelope not to use namespaces.
    */
   protected void removeNamespaces(MessageContext msgContext)
   {
      Message msg = msgContext.getResponseMessage();
      try
      {
         SOAPEnvelope soapEnvelope = msg.getSOAPEnvelope();
         boolean result = soapEnvelope.removeNamespaceDeclaration("SOAP-ENV");
      }
      catch (AxisFault e)
      {
      }
   } // of method removeNamespaces

} // of class FlashNamespaceHandler
