1+ /**
2+ * Copyright (c) 2007, Akeem Philbert (based on the work of (between others): Jesse Warden, Xavi Beumala, Renaun
3+ Erickson, Carlos Rovira)
4+ All rights reserved.
5+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
6+ following conditions are met:
7+
8+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following
9+ disclaimer.
10+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
11+ following disclaimer in the documentation and/or other materials provided with the distribution.
12+ * Neither the name of the Akeem Philbert nor the names of its contributors may be used to endorse or promote
13+ products derived from this software without specific prior written permission.
14+
15+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
16+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
21+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22+ */
23+ package com.ak33m.rpc.amf0
24+ {
25+ import com.ak33m.rpc.core.* ;
26+ import mx.rpc.AsyncToken ;
27+ import mx.managers.CursorManager ;
28+ import mx.messaging.messages.IMessage ;
29+ import mx.messaging.messages.RemotingMessage ;
30+ import mx.rpc.events.* ;
31+ dynamic public class AMF0Object extends AbstractRPCObject
32+ {
33+ protected var _gateway : AMF0Connection;
34+
35+ public function AMF0Object (endpoint :String = null )
36+ {
37+ super ();
38+ this . endpoint = endpoint ;
39+ }
40+
41+ override public function set endpoint (endpoint :String ):void
42+ {
43+ this . _endpoint = endpoint ;
44+ this . makeConnection();
45+ }
46+
47+ override protected function makeCall (method : String ,args : Array ): AsyncToken
48+ {
49+ var tmessage: RemotingMessage = new RemotingMessage ();
50+ tmessage. operation = method ;
51+ tmessage. destination = this . destination ;
52+ var ttoken: AsyncToken = new AsyncToken (tmessage);
53+ var responder: RPCResponder = new RPCResponder (ttoken);
54+ responder. timeout = this . requestTimeout ;
55+ responder. addEventListener (RPCEvent. EVENT_RESULT ,this . onResult);
56+ responder. addEventListener (RPCEvent. EVENT_FAULT ,this . onFault);
57+ responder. addEventListener (RPCEvent. EVENT_CANCEL ,this . onRemoveResponder);
58+ _responders . addItem (responder);
59+ var params : Array = args ;
60+
61+ if (args . length > 0 )
62+ {
63+ params. unshift (this . _destination + "." + method ,responder);
64+ this . _gateway . call . apply (this . _gateway ,params);
65+ }
66+ else
67+ {
68+ this . _gateway . call (this . _destination + "." + method ,responder);
69+ }
70+ dispatchEvent (new InvokeEvent ("invoke" ,false ,true ,ttoken,ttoken. message ));
71+
72+ //Show Busy cursor
73+ this . respondercounter++;
74+ return ttoken;
75+ }
76+
77+ public function makeConnection ():void
78+ {
79+ this . _gateway = new AMF0Connection(this . _endpoint );
80+ }
81+
82+ }
83+ }
0 commit comments