package org.eclipse.swt.net;

import com.google.gwt.core.client.JavaScriptObject;

public class GWTUtil {
	
	  interface RESTHandler
	   {
	      public void handleREST(JavaScriptObject obj);
	   }

	   public static native void makeRESTRequest(String url, RESTHandler handler, String callback) /*-{
	  	
	       $wnd[callback]  = function(restObj)
	       {
	       		@org.eclipse.swt.net.GWTUtil::dispatchREST(Lcom/google/gwt/core/client/JavaScriptObject;Lorg/eclipse/swt/net/GWTUtil$RESTHandler;)(restObj, handler);
	       }
	      
	       // create SCRIPT tag, and set SRC attribute equal to JSON feed URL + callback function name
	       var script = $wnd.document.createElement("script");
	       script.setAttribute("src", url+"jsoncallback="+callback);
	       script.setAttribute("type", "text/javascript");
	       
	       $wnd.document.getElementsByTagName("head")[0].appendChild(script);
	   
	   }-*/;

	   public static void dispatchREST(JavaScriptObject restObj, RESTHandler handler)
	   {
	      handler.handleREST(restObj);
	   }
}
