|
First_explanation
IntroductionHi, First of all, for the guy's ignoring what's SWXFORMAT is? Now everybody know's what's SWXFormat, let's see what's pixSWX. It's simply an API to acces SWX with PIXLIB framework. SWXCALLIt's the principal class, that's going to send and receive the informations. // -- Basic usage
var swx : SWXCall = new SWXCall("http://www.geturl.net/services/swx_php_1/php/swx.php", "Simple.addNumbers");
swx.addListener(this); // implements ISWXListener
swx.load(18, 32);ISWXListenerIt's the interface that declares all the methods that a listener must implement public function onFault(e : SWXFaultEvent) : Void; public function onResult(e : SWXResultEvent) : Void; // extends ILibListener public function onLoadInit(e:LibEvent) : Void; public function onLoadProgress(e:LibEvent) : Void; public function onTimeOut(e:LibEvent) : Void; SWXResponderThis class defines the scope where we want to receive the server response, it's based on the same logic than a delegate. var swx : SWXCall = new SWXCall("http://www.geturl.net/services/swx_php_1/php/swx.php", "Simple.addNumbers");
var swxResponder : SWXResponder = new SWXResponder(this, onResult, onFault, onProgress);
swx.addListener(swxResponder);
swx.load(18, 32);In the above example, it's the onResult, onFault, onProgress method's that will be used. SWXProxyThis class group all the methods of a service. class pixswx_first.net.SWXSimpleService
extends SWXProxy
{
public static var echoDataMETHOD : SWXMethod = new SWXMethod("echoData");
public static var addNumbersMETHOD : SWXMethod = new SWXMethod("addNumbers");
public function SWXSimpleService( sURL : String, serviceName : String )
{
super(sURL, serviceName);
}
public function echoData( swxlistener : ISWXListener, o ) : Void
{
super.callMethod(echoDataMETHOD, swxlistener, o);
}
public function addNumbers( swxlistener : ISWXListener, nFirst : Number, nSecond : Number ) : Void
{
super.callMethod(addNumbersMETHOD, swxlistener, nFirst, nSecond);
}
}// -- SWXProxy Usage var sGateway : String = "http://www.geturl.net/services/swx_php_1/php/swx.php"; var swxService : SWXSimpleService = new SWXSimpleService(sGateway, "Simple"); swxService.addNumbers(swxResponder, 100, 31); SWXProxyLocatorThis is actually a map that will globaly catch the different services of an application, base on the Frontcontroller mecanism. class pixswx_first.net.SWXLocator
extends SWXProxyLocator
{
private static var _oI : SWXLocator;
public static var simpleSERVICE : String = "Simple";
public static function getInstance() : SWXLocator
{
if (!_oI) _oI = new SWXLocator();
return _oI;
}
private function SWXLocator()
{
super();
}
public function init( remotingURL : String ) : Void
{
gatewayURL = remotingURL;
Debug.INFO(toString() + " initialization with '" + gatewayURL + "' gateway url.");
push(simpleSERVICE, new SWXSimpleService(gatewayURL, simpleSERVICE));
// push all services
}
}At the site initialisation : SWXLocator.getInstance().init("http://www.geturl.net/services/swx_php_1/php/swx.php");Afterwards : var swxService : SWXSimpleService = SWXSimpleService(SWXLocator.getInstance().getService(SWXLocator.simpleSERVICE)); swxService.echoData(new SWXResponder(this, onSWXResult, onSWXFault), "Hello World!"); That's it for the overview. I've inspired myself on Francis remoting API , so what i've said above is usable(nearly) for remoting services (AMFPHP for example). links |
Sign in to add a comment