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 ЌonverterMapping 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() );
}
}