
/*
 *                Omnigene Development Code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public License.  This should
 * be distributed with the code.  If you do not have a copy, 
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for the code is held jointly by Whitehead Institute
 * and the the individual authors.  These should be listed in 
 * @author doc comments.
 *
 * For more information on the Omnigene project and its aims
 * visit the www.sourceforge.net site.
 *
 */

package dt.soap.EchoService;

import java.io.*;
import org.w3c.dom.*;
import org.apache.soap.*;
import org.apache.soap.encoding.soapenc.*;
import org.apache.soap.rpc.*;
import org.apache.soap.util.*;
import org.apache.soap.util.xml.*;

/**
 * A <code>java.lang.String</code> Serializer.
 *
 * @author David Turner
 * @version 
 */

public class StringSerializer implements Serializer
{
    public void marshall(String inScopeEncStyle, Class javaType, Object src,
                       Object context, Writer sink, NSStack nsStack,
                       XMLJavaMappingRegistry xjmr, SOAPContext ctx)
                        throws IllegalArgumentException, IOException
    {
        if (!javaType.equals(java.lang.String.class))
        {
	        throw new IllegalArgumentException("Can only serialize java.lang.String instances");
        }

        nsStack.pushScope();

        if (src != null)
        {
	        SoapEncUtils.generateStructureHeader(inScopeEncStyle, javaType, context,
					  sink, nsStack, xjmr);

	        sink.write( (String)src );

	        sink.write("</" + context + ">");
        }
        else
        {
	        SoapEncUtils.generateNullStructure(inScopeEncStyle, javaType, context,
					  sink, nsStack, xjmr);	  
        }

        nsStack.popScope();
    }

}
