Hi All...I'm writing an application that uses XMLSockets. I get packets from the remote server and process them, each class that handles the packet has a processResponse(packet:XML) function. Currently I have a case statement that goes through and decides which class will handle the packet. Like this:
CODE
public override function dataHandler(event:DataEvent):void {
var packet:XML = new XML(event.data);
var response_type:String = packet.@type;
switch(response_type){
case "LOGIN":
var login:IqResponseLogin = new IqResponseLogin();
login.processResponse(packet);
break;
case "AGENT-STATE":
var state:IqResponseAgentState = new IqResponseAgentState();
state.processResponse(packet);
break;
case "GENERIC":
var generic:IqGeneric = new IqGeneric();
generic.processResponse(packet);
break;
case "OFF-HOOK-TERM":
var offhookterm:IqNotificationOffHookTerm = new IqNotificationOffHookTerm();
offhookterm.processResponse(packet);
break;
case "OFF-HOOK-INIT":
var offhookinit:IqResponseOffHookInit = new IqResponseOffHookInit();
offhookinit.processResponse(packet);
break;
case "NEW-CALL":
var newCall:IqNotificationNewCall = new IqNotificationNewCall();
newCall.processResponse(packet);
break;
case "END-CALL":
var endCall:IqNotificationEndCall = new IqNotificationEndCall();
endCall.processResponse(packet);
break;
case "HOLD":
var hold:IqResponseHold = new IqResponseHold();
hold.processRequest(packet);
break;
case "ADD-SESSION":
var addSession:IqNotificationAddSession = new IqNotificationAddSession();
addSession.processRequest(packet);
break;
case "RE-QUEUE":
var requeue:IqResponseReQueue = new IqResponseReQueue();
requeue.processResponse(packet);
break;
case "WARM-XFER":
var transfer:IqResponseWarmXfer = new IqResponseWarmXfer();
transfer.processResponse(packet);
break;
case "DROP-SESSION":
var drop:IqNotificationDropSession = new IqNotificationDropSession();
drop.processResponse(packet);
break;
default:
UIModel.getInstance().logger.warn(this,"No Handler class found for XMLPacket processing");
break;
}
}
what i would really like to do is to do this dynamically. Basically the name of the class is included in the XML packet.
<iq_response .....type="RE-QUEUE">.... so I would like to dynamically create the class, and then just call the processResponse() function of that class...
Any ideas?
Thanks,
Amanda