[sandbox.akabana]/trunk/yui-frameworks/yui-ds/src/main/flex/jp/akb7/yui/ds/DsPendingCall.as
Parent Directory
|
Revision Log
Revision 1504 -
(show annotations)
Sat Feb 19 16:23:33 2011 JST (2 years, 3 months ago) by e1arkw
Original Path: trunk/yui/yui-ds/src/main/flex/org/seasar/akabana/yui/service/ds/DsPendingCall.as
File size: 6277 byte(s)
Sat Feb 19 16:23:33 2011 JST (2 years, 3 months ago) by e1arkw
Original Path: trunk/yui/yui-ds/src/main/flex/org/seasar/akabana/yui/service/ds/DsPendingCall.as
File size: 6277 byte(s)
Copyrightを変更
| 1 | /* |
| 2 | * Copyright 2004-2011 the Seasar Foundation and the Others. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
| 13 | * either express or implied. See the License for the specific language |
| 14 | * governing permissions and limitations under the License. |
| 15 | */ |
| 16 | package org.seasar.akabana.yui.service.ds { |
| 17 | import mx.core.mx_internal; |
| 18 | import mx.messaging.messages.IMessage; |
| 19 | import mx.rpc.AbstractOperation; |
| 20 | import mx.rpc.AsyncToken; |
| 21 | import mx.rpc.IResponder; |
| 22 | import mx.rpc.Responder; |
| 23 | import mx.rpc.events.FaultEvent; |
| 24 | import mx.rpc.events.ResultEvent; |
| 25 | |
| 26 | import org.seasar.akabana.yui.core.reflection.ClassRef; |
| 27 | import org.seasar.akabana.yui.core.reflection.FunctionRef; |
| 28 | import org.seasar.akabana.yui.core.reflection.ParameterRef; |
| 29 | import org.seasar.akabana.yui.service.ManagedService; |
| 30 | import org.seasar.akabana.yui.service.OperationCallBack; |
| 31 | import org.seasar.akabana.yui.service.PendingCall; |
| 32 | import org.seasar.akabana.yui.service.Service; |
| 33 | import org.seasar.akabana.yui.service.ds.responder.RpcEventResponder; |
| 34 | import org.seasar.akabana.yui.service.ds.responder.RpcNoneResponder; |
| 35 | import org.seasar.akabana.yui.service.ds.responder.RpcObjectResponder; |
| 36 | import org.seasar.akabana.yui.service.ds.responder.RpcResponderFactory; |
| 37 | import org.seasar.akabana.yui.service.resonder.ResponderFactory; |
| 38 | |
| 39 | use namespace mx_internal; |
| 40 | |
| 41 | [ExcludeClass] |
| 42 | public final class DsPendingCall extends AsyncToken implements PendingCall { |
| 43 | |
| 44 | private static const RESULT_HANDLER:String = "ResultHandler"; |
| 45 | |
| 46 | private static const FAULT_HANDLER:String = "FaultHandler"; |
| 47 | |
| 48 | private static const _responderFactory:ResponderFactory = new RpcResponderFactory(); |
| 49 | |
| 50 | private static function createResponder( destination:String,operationName:String, responder:Object ):IResponder{ |
| 51 | const classRef:ClassRef = getClassRef(responder); |
| 52 | const resultFuncDef:FunctionRef = _responderFactory.findResultFunctionRef( classRef, destination, operationName ); |
| 53 | const faultFuncDef:FunctionRef = _responderFactory.findFaultFunctionRef( classRef, destination, operationName ); |
| 54 | |
| 55 | var result:IResponder = null; |
| 56 | var responderClass:Class; |
| 57 | if( resultFuncDef.parameters.length <= 0 ){ |
| 58 | responderClass = RpcNoneResponder; |
| 59 | } else { |
| 60 | var parameter:ParameterRef = resultFuncDef.parameters[0] as ParameterRef; |
| 61 | if( parameter.isEvent ){ |
| 62 | responderClass = RpcEventResponder; |
| 63 | } else { |
| 64 | responderClass = RpcObjectResponder; |
| 65 | } |
| 66 | } |
| 67 | if( faultFuncDef == null){ |
| 68 | result = new responderClass(resultFuncDef.getFunction(responder),null); |
| 69 | } else { |
| 70 | result = new responderClass(resultFuncDef.getFunction(responder),faultFuncDef.getFunction(responder)); |
| 71 | } |
| 72 | return result; |
| 73 | } |
| 74 | |
| 75 | protected var _internalAsyncToken:AsyncToken; |
| 76 | |
| 77 | protected var _responder:IResponder; |
| 78 | |
| 79 | private var _responderOwner:Object; |
| 80 | |
| 81 | private var _operation:AbstractOperation; |
| 82 | |
| 83 | public function DsPendingCall(message:IMessage=null) |
| 84 | { |
| 85 | super(message); |
| 86 | } |
| 87 | |
| 88 | public function clear():void{ |
| 89 | _responder = null; |
| 90 | } |
| 91 | |
| 92 | public function setInternalAsyncToken( asyncToken:AsyncToken, operation:AbstractOperation ):void{ |
| 93 | _internalAsyncToken = asyncToken; |
| 94 | _internalAsyncToken.addResponder( new Responder(onResult,onStatus)); |
| 95 | _operation = operation; |
| 96 | } |
| 97 | |
| 98 | public function setResponder( responder:Object ):void{ |
| 99 | if( responder is IResponder ){ |
| 100 | _responderOwner = null; |
| 101 | _responder = responder as IResponder; |
| 102 | } else { |
| 103 | _responderOwner = responder; |
| 104 | var service:Service = _operation.service as Service; |
| 105 | _responder = createResponder( service.name, _operation.name, responder ); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | public function getResponder():Object{ |
| 110 | if( _responderOwner == null ){ |
| 111 | return _responder; |
| 112 | } else { |
| 113 | return _responderOwner; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | public function get service():Service{ |
| 118 | return _operation.service as Service; |
| 119 | } |
| 120 | |
| 121 | public function onResult( resultEvent:ResultEvent ):void{ |
| 122 | if( service is ManagedService ){ |
| 123 | ( service as ManagedService ).finalizePendingCall(this); |
| 124 | } |
| 125 | |
| 126 | if( OperationCallBack.resultCallBack != null ){ |
| 127 | OperationCallBack.resultCallBack.apply(null,[resultEvent]); |
| 128 | } |
| 129 | |
| 130 | if( _responder != null ){ |
| 131 | _responder.result( resultEvent ); |
| 132 | } |
| 133 | |
| 134 | _responder = null; |
| 135 | _responderOwner = null; |
| 136 | _operation = null; |
| 137 | _internalAsyncToken = null; |
| 138 | } |
| 139 | |
| 140 | public function onStatus( faultEvent:FaultEvent ):void{ |
| 141 | if( service is ManagedService ){ |
| 142 | ( service as ManagedService ).finalizePendingCall(this); |
| 143 | } |
| 144 | |
| 145 | if( OperationCallBack.faultCallBack != null ){ |
| 146 | OperationCallBack.faultCallBack.apply(null,[faultEvent]); |
| 147 | } |
| 148 | |
| 149 | if( _responder != null ){ |
| 150 | _responder.fault( faultEvent ); |
| 151 | } |
| 152 | |
| 153 | _responder = null; |
| 154 | _responderOwner = null; |
| 155 | _operation = null; |
| 156 | _internalAsyncToken = null; |
| 157 | } |
| 158 | |
| 159 | mx_internal override function setResult(newResult:Object):void |
| 160 | { |
| 161 | } |
| 162 | |
| 163 | } |
| 164 | } |
| Repository Top ViewVC Help |
![]() |
| Powered by ViewVC |

