Package de.dfki.util.xmlrpc.converters

Source Code of de.dfki.util.xmlrpc.converters.URLConverter

package de.dfki.util.xmlrpc.converters;

import java.net.MalformedURLException;
import java.net.URL;

import de.dfki.util.xmlrpc.XmlRpc;
import de.dfki.util.xmlrpc.XmlRpc.Type;
import de.dfki.util.xmlrpc.conversion.ParameterConverter;
import de.dfki.util.xmlrpc.conversion.TypeConversionException;

/**
* This parameter converter converts {@link URL}s from and to XML-RPC representation.
* It has to be associated with the type {@link URL} by using a &#x40ConverterMapping annotation
* in the API where parameters of type {@link URL} are used.
*
* @see Api
*
* @author Andreas Lauer
*/
public class URLConverter implements ParameterConverter<URL, String>
{
    /** Converter uses XML-RPC type {@value XmlRpc.Type.STRING} as XML-RPC representation.*/
    public Type getXmlRpcRepresentationType()
    {
        return( XmlRpc.Type.STRING );
    }
   
    public URL createFrom( String xmlRepresentation )
        throws TypeConversionException
    {
        URL url = null;
        try
        {
            url = new URL(xmlRepresentation);
        }
        catch( MalformedURLException e )
        {
            throw( new TypeConversionException( e ) );
        }
        return( url );
    }

    public String toXmlRpc( URL param )
        throws TypeConversionException
    {
        return( param.toExternalForm() );
    }
}
TOP

Related Classes of de.dfki.util.xmlrpc.converters.URLConverter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.