1//////////////////////////////////////////////////////////////////////////////// 2// 3// ADOBE SYSTEMS INCORPORATED 4// Copyright 2005-2007 Adobe Systems Incorporated 5// All Rights Reserved. 6// 7// NOTICE: Adobe permits you to use, modify, and distribute this file 8// in accordance with the terms of the license agreement accompanying it. 9// 10//////////////////////////////////////////////////////////////////////////////// 11 12package mx.rpc.remoting 13{ 14 15import mx.core.mx_internal; 16import mx.messaging.Channel; 17import mx.messaging.ChannelSet; 18import mx.messaging.channels.AMFChannel; 19import mx.messaging.channels.SecureAMFChannel; 20import mx.rpc.AbstractOperation; 21import mx.rpc.AbstractService; 22import mx.rpc.mxml.Concurrency; 23 24use namespace mx_internal; 25 26/** 27 * The RemoteObject class gives you access to classes on a remote application server. 28 * 29 * @langversion 3.0 30 * @playerversion Flash 9 31 * @playerversion AIR 1.1 32 * @productversion Flex 3 33 */ 34public dynamic class RemoteObject extends AbstractService 35{ 36 //------------------------------------------------------------------------- 37 // 38 // Constructor 39 // 40 //------------------------------------------------------------------------- 41 42 /** 43 * Creates a new RemoteObject. 44 * @param destination [optional] Destination of the RemoteObject; should match a destination name in the services-config.xml file. 45 * 46 * @langversion 3.0 47 * @playerversion Flash 9 48 * @playerversion AIR 1.1 49 * @productversion Flex 3 50 */ 51 public function RemoteObject(destination:String = null) 52 { 53 super(destination); 54 55 concurrency = Concurrency.MULTIPLE; 56 makeObjectsBindable = true; 57 showBusyCursor = false; 58 } 59 60 //-------------------------------------------------------------------------- 61 // 62 // Variables 63 // 64 //-------------------------------------------------------------------------- 65 66 private var _concurrency:String; 67 68 private var _endpoint:String; 69 70 private var _source:String; 71 72 private var _makeObjectsBindable:Boolean; 73 74 private var _showBusyCursor:Boolean; 75 76 //-------------------------------------------------------------------------- 77 // 78 // Properties 79 // 80 //-------------------------------------------------------------------------- 81 82 [Inspectable(enumeration="multiple,single,last", defaultValue="multiple", category="General")] 83 /** 84 * Value that indicates how to handle multiple calls to the same service. The default 85 * value is multiple. The following values are permitted: 86 * <ul> 87 * <li>multiple - Existing requests are not cancelled, and the developer is 88 * responsible for ensuring the consistency of returned data by carefully 89 * managing the event stream. This is the default.</li> 90 * <li>single - Making only one request at a time is allowed on the method; additional requests made 91 * while a request is outstanding are immediately faulted on the client and are not sent to the server.</li> 92 * <li>last - Making a request causes the client to ignore a result or fault for any current outstanding request. 93 * Only the result or fault for the most recent request will be dispatched on the client. 94 * This may simplify event handling in the client application, but care should be taken to only use 95 * this mode when results or faults for requests may be safely ignored.</li> 96 * </ul> 97 * 98 * @langversion 3.0 99 * @playerversion Flash 9 100 * @playerversion AIR 1.1 101 * @productversion Flex 3 102 */ 103 public function get concurrency():String 104 { 105 return _concurrency; 106 } 107 108 /** 109 * @private 110 */ 111 public function set concurrency(c:String):void 112 { 113 _concurrency = c; 114 } 115 116 117 //---------------------------------- 118 // endpoint 119 //---------------------------------- 120 121 [Inspectable(category="General")] 122 /** 123 * This property allows the developer to quickly specify an endpoint for a RemoteObject 124 * destination without referring to a services configuration file at compile time or programmatically creating 125 * a ChannelSet. It also overrides an existing ChannelSet if one has been set for the RemoteObject service. 126 * 127 * <p>If the endpoint url starts with "https" a SecureAMFChannel will be used, otherwise an AMFChannel will 128 * be used. Two special tokens, {server.name} and {server.port}, can be used in the endpoint url to specify 129 * that the channel should use the server name and port that was used to load the SWF. </p> 130 * 131 * <p><b>Note:</b> This property is required when creating AIR applications.</p> 132 * 133 * @langversion 3.0 134 * @playerversion Flash 9 135 * @playerversion AIR 1.1 136 * @productversion Flex 3 137 */ 138 public function get endpoint():String 139 { 140 return _endpoint; 141 } 142 143 public function set endpoint(url:String):void 144 { 145 // If endpoint has changed, null out channelSet to force it 146 // to be re-initialized on the next Operation send 147 if (_endpoint != url || url == null) 148 { 149 _endpoint = url; 150 channelSet = null; 151 } 152 } 153 154 //---------------------------------- 155 // makeObjectsBindable 156 //---------------------------------- 157 158 [Inspectable(category="General", defaultValue="true")] 159 160 /** 161 * When this value is true, anonymous objects returned are forced to bindable objects. 162 * 163 * @langversion 3.0 164 * @playerversion Flash 9 165 * @playerversion AIR 1.1 166 * @productversion Flex 3 167 */ 168 public function get makeObjectsBindable():Boolean 169 { 170 return _makeObjectsBindable; 171 } 172 173 public function set makeObjectsBindable(b:Boolean):void 174 { 175 _makeObjectsBindable = b; 176 } 177 178 //---------------------------------- 179 // showBusyCursor 180 //---------------------------------- 181 182 [Inspectable(defaultValue="false", category="General")] 183 /** 184 * If <code>true</code>, a busy cursor is displayed while a service is executing. The default 185 * value is <code>false</code>. 186 * 187 * @langversion 3.0 188 * @playerversion Flash 9 189 * @playerversion AIR 1.1 190 * @productversion Flex 3 191 */ 192 public function get showBusyCursor():Boolean 193 { 194 return _showBusyCursor; 195 } 196 197 public function set showBusyCursor(sbc:Boolean):void 198 { 199 _showBusyCursor = sbc; 200 } 201 202 //---------------------------------- 203 // source 204 //---------------------------------- 205 206 [Inspectable(category="General")] 207 /** 208 * Lets you specify a source value on the client; not supported for destinations that use the JavaAdapter. This allows you to provide more than one source 209 * that can be accessed from a single destination on the server. 210 * 211 * 212 * @langversion 3.0 213 * @playerversion Flash 9 214 * @playerversion AIR 1.1 215 * @productversion Flex 3 216 */ 217 public function get source():String 218 { 219 return _source; 220 } 221 222 public function set source(s:String):void 223 { 224 _source = s; 225 } 226 227 /** 228 * An optional function, primarily intended for framework developers who need to install 229 * a function to get called with the parameters passed to each remote object invocation. 230 * The function takes an array of parameters and returns the potentially altered array. 231 * 232 * The function definition should look like: 233 * <code> 234 * function myParametersFunction(parameters:Array):Array 235 * </code> 236 * 237 * @langversion 3.0 238 * @playerversion Flash 9 239 * @playerversion AIR 1.1 240 * @productversion Flex 3 241 */ 242 public var convertParametersHandler:Function; 243 244 /** 245 * An optional function, primarily intended for framework developers who need to install 246 * a hook to process the results of an operation before notifying the result handlers. 247 * 248 * The function definition should look like: 249 * <code> 250 * function myConvertResultsFunction(result:*, operation:AbstractOperation):* 251 * </code> 252 * 253 * It is passed the result just after the makeObjectsBindable conversion has been done 254 * but before the result event is created. 255 * 256 * @langversion 3.0 257 * @playerversion Flash 9 258 * @playerversion AIR 1.1 259 * @productversion Flex 3 260 */ 261 public var convertResultHandler:Function; 262 263 //------------------------------------------------------------------------- 264 265 // 266 // Internal Methods 267 // 268 //------------------------------------------------------------------------- 269 270 /** 271 *@private 272 */ 273 mx_internal function initEndpoint():void 274 { 275 if (endpoint != null) 276 { 277 var chan:Channel; 278 if (endpoint.indexOf("https") == 0) 279 { 280 chan = new SecureAMFChannel(null, endpoint); 281 } 282 else 283 { 284 chan = new AMFChannel(null, endpoint); 285 } 286 287 // Propagate requestTimeout. 288 chan.requestTimeout = requestTimeout; 289 290 channelSet = new ChannelSet(); 291 channelSet.addChannel(chan); 292 } 293 } 294 295 //-------------------------------------------------------------------------- 296 // 297 // Methods 298 // 299 //-------------------------------------------------------------------------- 300 301 /** 302 * Returns an Operation of the given name. If the Operation wasn't 303 * created beforehand, a new <code>mx.rpc.remoting.Operation</code> is 304 * created during this call. Operations are usually accessible by simply 305 * naming them after the service variable 306 * (<code>myService.someOperation</code>), but if your Operation name 307 * happens to match a defined method on the service 308 * (like <code>setCredentials</code>), you can use this method to get the 309 * Operation instead. 310 * @param name Name of the Operation. 311 * @return Operation that executes for this name. 312 * 313 * @langversion 3.0 314 * @playerversion Flash 9 315 * @playerversion AIR 1.1 316 * @productversion Flex 3 317 */ 318 override public function getOperation(name:String):AbstractOperation 319 { 320 var op:AbstractOperation = super.getOperation(name); 321 if (op == null) 322 { 323 op = new Operation(this, name); 324 _operations[name] = op; 325 op.asyncRequest = asyncRequest; 326 } 327 return op; 328 } 329 330 /** 331 * If a remote object is managed by an external service, such a ColdFusion Component (CFC), 332 * a username and password can be set for the authentication mechanism of that remote service. 333 * 334 * @param remoteUsername the username to pass to the remote endpoint 335 * @param remotePassword the password to pass to the remote endpoint 336 * @param charset The character set encoding to use while encoding the 337 * remote credentials. The default is null, which implies the legacy charset 338 * of ISO-Latin-1. The only other supported charset is "UTF-8". 339 * 340 * @langversion 3.0 341 * @playerversion Flash 9 342 * @playerversion AIR 1.1 343 * @productversion Flex 3 344 */ 345 override public function setRemoteCredentials(remoteUsername:String, remotePassword:String, charset:String=null):void 346 { 347 super.setRemoteCredentials(remoteUsername, remotePassword, charset); 348 } 349 350 /** 351 * Represents an instance of RemoteObject as a String, describing 352 * important properties such as the destination id and the set of 353 * channels assigned. 354 * 355 * @return Returns a String representing an instance of a RemoteObject. 356 * 357 * @langversion 3.0 358 * @playerversion Flash 9 359 * @playerversion AIR 1.1 360 * @productversion Flex 3 361 */ 362 public function toString():String 363 { 364 var s:String = "[RemoteObject "; 365 s += " destination=\"" + destination + "\""; 366 if (source) 367 s += " source=\"" + source + "\""; 368 s += " channelSet=\"" + channelSet + "\"]"; 369 return s; 370 } 371} 372 373} 374