/*
* Created on 11.03.2004
*
*/
package de.dfki.util.xmlrpc.client;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import de.dfki.util.xmlrpc.common.MethodSignature;
import de.dfki.util.xmlrpc.common.XmlRpcConnection;
import de.dfki.util.xmlrpc.conversion.TypeConversionException;
import org.apache.xmlrpc.XmlRpcException;
/**
* Standard implementation of a <code>XmlRpcClient</code>.
*
* @author lauer
*/
public class StandardXmlRpcClient implements XmlRpcClient
{
private static Logger mLog = Logger.getLogger( StandardXmlRpcClient.class.getName() );
public static Logger log()
{
return ( mLog );
}
public StandardXmlRpcClient()
{
this( null );
}
public StandardXmlRpcClient( XmlRpcConnection conn )
{
setConnection( conn );
}
public void setConnection( XmlRpcConnection c )
{
mConnection = c;
}
public XmlRpcConnection getConnection()
{
return( mConnection );
}
public boolean isConnected()
{
return( getConnection() != null );
}
public void setHandlerName( String handlerName )
{
if (handlerName == null)
{
mHandlerName = "";
return;
}
mHandlerName = handlerName;
}
public String getHandlerName()
{
return( mHandlerName );
}
@SuppressWarnings("unchecked")
public <T> T invoke( MethodCall methodCall )
throws XmlRpcException, Exception,
IOException, MethodCallParameterException,
TypeConversionException
{
if (log().isLoggable( Level.FINE ))
log().fine( "Invoking XML-RPC method " + methodCall.getName() );
if (log().isLoggable( Level.FINER ))
log().finer( "Sending method arguments: " + methodCall.getParameters() );
Object result = getConnection().invoke( methodCall );
if (log().isLoggable( Level.FINE ))
log().fine( "Received '" + result + "'" + (result!=null?"("+result.getClass().getName()+")":"") + " from XML-RPC method " + methodCall.getName() );
result = methodCall.convertReturnValueToUserRepresentation( result );
if (log().isLoggable( Level.FINE ))
log().fine( "Returned '" + result + "'" + (result!=null?"("+result.getClass().getName()+")":"") + " from XML-RPC method call." );
return ( (T)result );
}
public MethodCall prepareCall( MethodSignature sig )
{
final MethodSignature tmpSig = new MethodSignature( getHandlerName(), sig );
return( new MethodCall( tmpSig ) );
}
private XmlRpcConnection mConnection;
private String mHandlerName = "";
}