
/*
 *                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.*;

import java.net.URL;

/**
 * A <code>java.net.URL</code> Deserializer.
 *
 * @author David Turner
 * @version 
 */

public class URLDeserializer implements Deserializer
{
    public Bean unmarshall(String inScopeEncStyle, QName elementType, Node src,
                         XMLJavaMappingRegistry xjmr, SOAPContext ctx)
                          throws IllegalArgumentException
    {
        URL url = null;

        Element root = (Element)src;
        String value = DOMUtils.getChildCharacterData(root);
    
        if (value != null & !((value=value.trim()).equals("")))
        {
    	    try
    	    {
    	        url = new URL(value);
    	    }
    	    catch (java.net.MalformedURLException me)
    	    {
    	        throw new IllegalArgumentException("String represents no valid URL (URLDeserializer)");
    	    }
        }

        return new Bean(java.net.URL.class, url);
    }
  
}
