FileDocCategorySizeDatePackage
XmlRpcAsynchClientPlugin.javaAPI DocExample2091Sun Jan 12 23:37:36 GMT 2003com.wiverson.macosbook.webservices

XmlRpcAsynchClientPlugin.java

package com.wiverson.macosbook.webservices;

public class XmlRpcAsynchClientPlugin implements com.wiverson.macosbook.SimpleEditPlugin
{
    public XmlRpcAsynchClientPlugin()
    {
    }
    
    public static void main(String[] args)
    {
        System.out.print("Calling asynch...");
        new XmlRpcAsynchClientPlugin().callRemote(null);
        System.out.println("ok...");
    }
    
    public void callRemote(com.wiverson.macosbook.SimpleEdit frame)
    {
        try
        {
            org.apache.xmlrpc.XmlRpcClient xmlrpc = new org.apache.xmlrpc.XmlRpcClient("http://localhost:9000/MiniServer");
            java.util.Vector params = new java.util.Vector();
            AsynchTimeHandler myAsynchTimeHandler = new AsynchTimeHandler(frame);
            xmlrpc.executeAsync("MiniServer.now", params, myAsynchTimeHandler);
        } catch (java.net.MalformedURLException e1)
        {
            e1.printStackTrace();
        } catch (java.io.IOException e2)
        {
            e2.printStackTrace();
        }
    }
    
    public void doAction(com.wiverson.macosbook.SimpleEdit frame, java.awt.event.ActionEvent evt)
    {
        this.callRemote(frame);
    }
    
    public String getAction()
    {
        return "Test Async XML-RPC";
    }
    
    public void init(com.wiverson.macosbook.SimpleEdit frame)
    {
    }
    
    public class AsynchTimeHandler implements org.apache.xmlrpc.AsyncCallback
    {
        public AsynchTimeHandler(com.wiverson.macosbook.SimpleEdit frame)
        {
            myFrame = frame;
        }
        private com.wiverson.macosbook.SimpleEdit myFrame = null;
        public void handleError(Exception e, java.net.URL uRL, String str)
        {
            e.printStackTrace();
        }
        
        public void handleResult(Object obj, java.net.URL uRL, String str)
        {
            if(myFrame != null)
                myFrame.appendDocumentText((String) obj);
            else
                System.out.println((String) obj);
        }
    }    
}