[Zmx-cvs-commit] zmx XMLMessage.as, 1.1.2.3, 1.1.2.4 XMLRPCLib.as, 1.1.2.2, 1.1.2.3 XMLRPC_Response
Brought to you by:
sspickle
|
From: Steve S. <ssp...@us...> - 2011-07-13 11:17:19
|
Update of /cvsroot/zmx/zmx
In directory vz-cvs-4.sog:/tmp/cvs-serv2017
Modified Files:
Tag: ActionScript_2-0_conversion
XMLMessage.as XMLRPCLib.as XMLRPC_ResponseHandler.as
XML_Loader.as ZMX_XML_new.as
Log Message:
convert to unix line endingds..
Index: XMLRPC_ResponseHandler.as
===================================================================
RCS file: /cvsroot/zmx/zmx/Attic/XMLRPC_ResponseHandler.as,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -d -r1.1.2.2 -r1.1.2.3
*** XMLRPC_ResponseHandler.as 2 Mar 2004 21:37:05 -0000 1.1.2.2
--- XMLRPC_ResponseHandler.as 13 Jul 2011 11:17:16 -0000 1.1.2.3
***************
*** 1 ****
! //
// XMLRPC_ResponseHandler knows how to notify an XMLRPC client that their request has succeeded, or failed.
//
import zmx.XML_Loader;
class zmx.XMLRPC_ResponseHandler {
var onSuccessFunc;
var onFailureFunc;
var proxy;
function XMLRPC_ResponseHandler( onSuccess, onFailure, proxy) {
this.onSuccessFunc = onSuccess;
this.onFailureFunc = onFailure;
this.proxy = proxy;
}
function onSuccess( theXML ) {
var loader = new zmx.XML_Loader();
var argObj = loader.loads( theXML )
if (argObj.params.isFault == null) {
//_global.gTrace("Applying " + this.onSuccessFunc + " to " + this.proxy + " using " + _global.serializeObject(argObj.params));
this.proxy[this.onSuccessFunc].apply( this.proxy, argObj.params);
}
else {
//_global.gTrace("Fault occured: " + _global.serializeObject(argObj.params));
this.proxy[this.onFailureFunc].apply( this.proxy, [argObj.params]);
}
}
function onFailure( argObj ) {
this.proxy[this.onFailureFunc]( argObj );
}
function mapSuccess( newName ) {
this[newName] = this.onSuccess;
}
function mapFailure( newName ) {
this[newName] = this.onFailure;
}
}
\ No newline at end of file
--- 1,45 ----
! //
! // XMLRPC_ResponseHandler knows how to notify an XMLRPC client that their request has succeeded, or failed.
! //
!
! import zmx.XML_Loader;
!
! class zmx.XMLRPC_ResponseHandler {
!
! var onSuccessFunc;
! var onFailureFunc;
! var proxy;
!
! function XMLRPC_ResponseHandler( onSuccess, onFailure, proxy) {
! this.onSuccessFunc = onSuccess;
! this.onFailureFunc = onFailure;
! this.proxy = proxy;
! }
!
! function onSuccess( theXML ) {
!
! var loader = new zmx.XML_Loader();
! var argObj = loader.loads( theXML )
!
! if (argObj.params.isFault == null) {
! //_global.gTrace("Applying " + this.onSuccessFunc + " to " + this.proxy + " using " + _global.serializeObject(argObj.params));
! this.proxy[this.onSuccessFunc].apply( this.proxy, argObj.params);
! }
! else {
! //_global.gTrace("Fault occured: " + _global.serializeObject(argObj.params));
! this.proxy[this.onFailureFunc].apply( this.proxy, [argObj.params]);
! }
! }
!
! function onFailure( argObj ) {
! this.proxy[this.onFailureFunc]( argObj );
! }
!
! function mapSuccess( newName ) {
! this[newName] = this.onSuccess;
! }
!
! function mapFailure( newName ) {
! this[newName] = this.onFailure;
! }
! }
Index: XMLMessage.as
===================================================================
RCS file: /cvsroot/zmx/zmx/Attic/XMLMessage.as,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -C2 -d -r1.1.2.3 -r1.1.2.4
*** XMLMessage.as 3 Mar 2004 13:49:20 -0000 1.1.2.3
--- XMLMessage.as 13 Jul 2011 11:17:16 -0000 1.1.2.4
***************
*** 1 ****
! dynamic class zmx.XMLMessage {
function XMLMessage()
{
this.methodCall = new XML();
this.methodCall.ignoreWhite = true;
this.Parameters = new Array();
}
function AddParameter( theParameter ) {
this.Parameters.push( theParameter );
}
function Send( Server, Method, proxy) {
//
// conventional XMLRPC client sender..
//
this.methodResponse = new XML();
this.methodResponse.ignoreWhite = true;
this.methodResponse.ref = this;
this.methodResponse.onLoad = this.Loaded;
this.responseProxy = proxy;
this.Result = null;
// An example server might be:
// http://www.example.com:8080/RPC2
this.Server = Server;
this.BuildXML( Method );
// Make the call. Flash uses POST method for
// the sendAndLoad() XML methods.
// Added methodCall.contentType- Isaac Levy
// Content-Type http header value 'text/xml' now carried in Call headers
this.methodCall.sendAndLoad(this.Server,this.methodResponse);
return true;
}
function BuildXML ( Method )
{
var dumper = new zmx.XML_Dumper();
var xmlText = dumper.wrapMethod( this.Parameters, Method );
//_global.gTrace("BUILDXML: " + xmlText);
this.methodCall = new XML(xmlText);
this.methodCall.ignoreWhite = true;
this.methodCall.xmlDecl = "<?xml version=\"1.0\"?>";
this.Result = null;
this.methodCall.contentType = "text/xml";
return this.methodCall;
}
function onFailure( reason ) {
this.responseProxy.onFailure( reason );
}
function onSuccess( theXML ) {
this.responseProxy.onSuccess( theXML );
};
function Loaded( success ) {
if (success) {
this.ref.onSuccess( this );
}
else
{
this.ref.onFailure( this );
}
}
}
\ No newline at end of file
--- 1,82 ----
! dynamic class zmx.XMLMessage {
!
! function XMLMessage()
! {
! this.methodCall = new XML();
! this.methodCall.ignoreWhite = true;
! this.Parameters = new Array();
! }
!
! function AddParameter( theParameter ) {
! this.Parameters.push( theParameter );
! }
!
! function Send( Server, Method, proxy) {
!
! //
! // conventional XMLRPC client sender..
! //
!
! this.methodResponse = new XML();
! this.methodResponse.ignoreWhite = true;
! this.methodResponse.ref = this;
! this.methodResponse.onLoad = this.Loaded;
! this.responseProxy = proxy;
!
! this.Result = null;
!
! // An example server might be:
! // http://www.example.com:8080/RPC2
!
! this.Server = Server;
!
! this.BuildXML( Method );
!
! // Make the call. Flash uses POST method for
! // the sendAndLoad() XML methods.
!
!
! // Added methodCall.contentType- Isaac Levy
! // Content-Type http header value 'text/xml' now carried in Call headers
!
! this.methodCall.sendAndLoad(this.Server,this.methodResponse);
! return true;
! }
!
!
! function BuildXML ( Method )
! {
!
! var dumper = new zmx.XML_Dumper();
! var xmlText = dumper.wrapMethod( this.Parameters, Method );
!
! //_global.gTrace("BUILDXML: " + xmlText);
! this.methodCall = new XML(xmlText);
! this.methodCall.ignoreWhite = true;
! this.methodCall.xmlDecl = "<?xml version=\"1.0\"?>";
! this.Result = null;
!
! this.methodCall.contentType = "text/xml";
!
! return this.methodCall;
! }
!
! function onFailure( reason ) {
! this.responseProxy.onFailure( reason );
! }
!
! function onSuccess( theXML ) {
! this.responseProxy.onSuccess( theXML );
! };
!
! function Loaded( success ) {
!
! if (success) {
! this.ref.onSuccess( this );
! }
! else
! {
! this.ref.onFailure( this );
! }
! }
! }
Index: ZMX_XML_new.as
===================================================================
RCS file: /cvsroot/zmx/zmx/Attic/ZMX_XML_new.as,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** ZMX_XML_new.as 19 Feb 2004 21:19:27 -0000 1.1.2.1
--- ZMX_XML_new.as 13 Jul 2011 11:17:16 -0000 1.1.2.2
***************
*** 1 ****
! 
import zmx.*
_global.Args_To_XML = function ( args, method ) {
var xmlFunc = new _global.XMLFunction( method );
return xmlFunc.BuildArgumentMessage.apply(xmlFunc, args);
}
_global.Arg_To_XML = function ( arg, method ) {
return _global.Args_To_XML([arg], method);
}
_global.XML_To_Args = function ( theXML ) {
var argObj = XML_To_ArgObject( theXML );
return argObj.params;
}
_global.XML_To_ArgObject = function ( theXML ) {
return dumps( theXML );
}
_global.XML_CallWithArg = function ( theURL, methodName, theArg, successFunc, failFunc, client) {
//
// Deprecated! Use XML_CallWithArgs instead..
//
// theURL: URL to get 'object' reference
// methodName : method of object to call
// theArgs : arguments to pass
// successFunc: method of client to call for success notification
// failFunc : method of client to call for failure notification
// client: object to be notified..
return _global.XML_CallWithArgs( theURL, methodName, [theArg], successFunc, failFunc, client);
}
_global.XML_CallWithArgs = function ( theURL, methodName, theArgs, successFunc, failFunc, client) {
//
// theURL: URL to get 'object' reference
// methodName : method of object to call
// theArgs : arguments to pass
// successFunc: method of client to call for success notification
// failFunc : method of client to call for failure notification
// client: object to be notified..
// useLCServer: set to 'true' if the connection should be made via a LocalConnection object
//
var proxy = new XMLRPC_ResponseHandler( successFunc, failFunc, client);
var rpcFunction = new XMLFunction( methodName );
rpcFunction.BuildArguments.apply(rpcFunction, theArgs);
rpcFunction.Send(theURL, proxy);
return rpcFunction;
}
c = _global.AsyncSocket = function( parentObj ) {
//
// Async Socket that knows how to handle XML...
//
this.parentObj = parentObj;
}
p = c.prototype = new XMLSocket();
p.invokeMethod = function ( resultObj, theObj ) {
//
// invoke the method on the object using the args passed..
//
var theMethod = theObj[ resultObj.methodName ];
if ( theMethod != null) {
return theMethod.apply( theObj, resultObj.params );
}
return "ERROR! invoking method!";
}
p.onXML = function (theXML) {
var argObj = loads( theXML ) // get the arguments...
if (argObj.methodCall) {
var funcResult = this.invokeMethod( argObj, this.parentObj.proxy );
var theReply = Arg_To_XML({sender_id:this.parentObj.config.sender_id, result:funcResult});
if (theReply != null) {
this.send( theReply );
}
}
else
{
if (argObj != null) {
if (argObj.params.isFault == null) {
this.parentObj.proxy.onAsync( argObj.params );
}
else {
this.parentObj.proxy.onFailure( argObj.params );
}
}
}
}
delete p;
delete c;
#include "XML_js.as"
c = _global.XMLMessage = function()
{
this.methodCall = new XML();
this.methodCall.ignoreWhite = true;
this.Parameters = new Array();
}
p = c.prototype = new Object();
p.AddParameter = function( theParameter ) {
this.Parameters.push( theParameter );
}
p.Send = function( Server, Method, proxy) {
//
// conventional XMLRPC client sender..
//
this.methodResponse = new XML();
this.methodResponse.ignoreWhite = true;
this.methodResponse.ref = this;
this.methodResponse.onLoad = this.Loaded;
this.responseProxy = proxy;
this.Result = null;
// An example server might be:
// http://www.example.com:8080/RPC2
this.Server = Server;
this.BuildXML( Method );
// Make the call. Flash uses POST method for
// the sendAndLoad() XML methods.
// Added methodCall.contentType- Isaac Levy
// Content-Type http header value 'text/xml' now carried in Call headers
this.methodCall.sendAndLoad(this.Server,this.methodResponse);
return true;
}
p.BuildXML = function ( Method )
{
var xmlText = dumps( this.Parameters, Method );
//_global.gTrace("BUILDXML: " + xmlText);
this.methodCall = new XML(xmlText);
this.methodCall.ignoreWhite = true;
this.methodCall.xmlDecl = "<?xml version=\"1.0\"?>";
this.Result = null;
this.methodCall.contentType = "text/xml";
return this.methodCall;
}
p.onFailure = function ( reason ) {
this.responseProxy.onFailure( reason );
}
p.onSuccess = function ( theXML ) {
this.responseProxy.onSuccess( theXML );
};
p.Loaded = function ( success ) {
if (success) {
this.ref.onSuccess( this );
}
else
{
this.ref.onFailure( this );
}
}
delete p;
delete c;
c = _global.XMLFunction = function ( methodName ) {
this.methodName = methodName;
this.theArgs = null;
};
p = c.prototype = new Object();
p.BuildArgumentMessage = function() {
this.theArgs = arguments;
this.BuildArguments();
return this.BuildXML();
}
p.BuildArguments = function() {
if (this.theArgs == null) {
this.theArgs = arguments;
}
this.lastMessage = new _global.XMLMessage()
for (var i=0; i<this.theArgs.length; i++) {
this.lastMessage.AddParameter( this.theArgs[i] );
}
return this.lastMessage;
}
p.BuildXML = function ( theMsg ) {
if (theMsg == null) {
theMsg = this.lastMessage;
}
this.lastXML = theMsg.BuildXML( this.methodName );
return this.lastXML;
}
p.Send = function(Server, proxy) {
this.lastMessage.Send(Server, this.methodName, proxy);
}
delete p;
delete c;
c = _global.XMLRPC_ResponseHandler = function( onSuccess, onFailure, proxy) {
this.onSuccessFunc = onSuccess;
this.onFailureFunc = onFailure;
this.proxy = proxy;
}
p = c.prototype = new Object();
p.onSuccess = function( theXML ) {
var argObj = loads( theXML )
if (argObj.params.isFault == null) {
//_global.gTrace("Applying " + this.onSuccessFunc + " to " + this.proxy + " using " + _global.serializeObject(argObj.params));
this.proxy[this.onSuccessFunc].apply( this.proxy, argObj.params);
}
else {
//_global.gTrace("Fault occured: " + _global.serializeObject(argObj.params));
this.proxy[this.onFailureFunc].apply( this.proxy, [argObj.params]);
}
}
p.onFailure = function( argObj ) {
this.proxy[this.onFailureFunc]( argObj );
}
p.mapSuccess = function( newName ) {
this[newName] = this.onSuccess;
}
p.mapFailure = function( newName ) {
this[newName] = this.onFailure;
}
delete p;
delete c;
\ No newline at end of file
--- 1,274 ----
! 
! import zmx.*
!
! _global.Args_To_XML = function ( args, method ) {
! var xmlFunc = new _global.XMLFunction( method );
! return xmlFunc.BuildArgumentMessage.apply(xmlFunc, args);
! }
!
! _global.Arg_To_XML = function ( arg, method ) {
! return _global.Args_To_XML([arg], method);
! }
! _global.XML_To_Args = function ( theXML ) {
! var argObj = XML_To_ArgObject( theXML );
! return argObj.params;
! }
!
! _global.XML_To_ArgObject = function ( theXML ) {
! return dumps( theXML );
! }
!
! _global.XML_CallWithArg = function ( theURL, methodName, theArg, successFunc, failFunc, client) {
! //
! // Deprecated! Use XML_CallWithArgs instead..
! //
! // theURL: URL to get 'object' reference
! // methodName : method of object to call
! // theArgs : arguments to pass
! // successFunc: method of client to call for success notification
! // failFunc : method of client to call for failure notification
! // client: object to be notified..
!
! return _global.XML_CallWithArgs( theURL, methodName, [theArg], successFunc, failFunc, client);
! }
!
! _global.XML_CallWithArgs = function ( theURL, methodName, theArgs, successFunc, failFunc, client) {
! //
! // theURL: URL to get 'object' reference
! // methodName : method of object to call
! // theArgs : arguments to pass
! // successFunc: method of client to call for success notification
! // failFunc : method of client to call for failure notification
! // client: object to be notified..
! // useLCServer: set to 'true' if the connection should be made via a LocalConnection object
! //
!
! var proxy = new XMLRPC_ResponseHandler( successFunc, failFunc, client);
! var rpcFunction = new XMLFunction( methodName );
! rpcFunction.BuildArguments.apply(rpcFunction, theArgs);
! rpcFunction.Send(theURL, proxy);
! return rpcFunction;
! }
!
! c = _global.AsyncSocket = function( parentObj ) {
!
! //
! // Async Socket that knows how to handle XML...
! //
!
! this.parentObj = parentObj;
! }
!
! p = c.prototype = new XMLSocket();
!
! p.invokeMethod = function ( resultObj, theObj ) {
!
! //
! // invoke the method on the object using the args passed..
! //
!
! var theMethod = theObj[ resultObj.methodName ];
!
! if ( theMethod != null) {
! return theMethod.apply( theObj, resultObj.params );
! }
!
! return "ERROR! invoking method!";
! }
!
! p.onXML = function (theXML) {
!
! var argObj = loads( theXML ) // get the arguments...
! if (argObj.methodCall) {
! var funcResult = this.invokeMethod( argObj, this.parentObj.proxy );
! var theReply = Arg_To_XML({sender_id:this.parentObj.config.sender_id, result:funcResult});
!
! if (theReply != null) {
! this.send( theReply );
! }
! }
! else
! {
! if (argObj != null) {
! if (argObj.params.isFault == null) {
! this.parentObj.proxy.onAsync( argObj.params );
! }
! else {
! this.parentObj.proxy.onFailure( argObj.params );
! }
! }
! }
! }
!
! delete p;
! delete c;
!
! #include "XML_js.as"
!
! c = _global.XMLMessage = function()
! {
! this.methodCall = new XML();
! this.methodCall.ignoreWhite = true;
! this.Parameters = new Array();
! }
!
! p = c.prototype = new Object();
!
! p.AddParameter = function( theParameter ) {
! this.Parameters.push( theParameter );
! }
!
! p.Send = function( Server, Method, proxy) {
!
! //
! // conventional XMLRPC client sender..
! //
!
! this.methodResponse = new XML();
! this.methodResponse.ignoreWhite = true;
! this.methodResponse.ref = this;
! this.methodResponse.onLoad = this.Loaded;
! this.responseProxy = proxy;
!
! this.Result = null;
!
! // An example server might be:
! // http://www.example.com:8080/RPC2
!
! this.Server = Server;
!
! this.BuildXML( Method );
!
! // Make the call. Flash uses POST method for
! // the sendAndLoad() XML methods.
!
!
! // Added methodCall.contentType- Isaac Levy
! // Content-Type http header value 'text/xml' now carried in Call headers
!
! this.methodCall.sendAndLoad(this.Server,this.methodResponse);
! return true;
! }
!
!
! p.BuildXML = function ( Method )
! {
!
! var xmlText = dumps( this.Parameters, Method );
!
! //_global.gTrace("BUILDXML: " + xmlText);
! this.methodCall = new XML(xmlText);
! this.methodCall.ignoreWhite = true;
! this.methodCall.xmlDecl = "<?xml version=\"1.0\"?>";
! this.Result = null;
!
! this.methodCall.contentType = "text/xml";
!
! return this.methodCall;
! }
!
! p.onFailure = function ( reason ) {
! this.responseProxy.onFailure( reason );
! }
!
! p.onSuccess = function ( theXML ) {
! this.responseProxy.onSuccess( theXML );
! };
!
! p.Loaded = function ( success ) {
!
! if (success) {
! this.ref.onSuccess( this );
! }
! else
! {
! this.ref.onFailure( this );
! }
! }
!
! delete p;
! delete c;
!
! c = _global.XMLFunction = function ( methodName ) {
!
! this.methodName = methodName;
! this.theArgs = null;
! };
!
! p = c.prototype = new Object();
!
! p.BuildArgumentMessage = function() {
!
! this.theArgs = arguments;
! this.BuildArguments();
! return this.BuildXML();
! }
!
! p.BuildArguments = function() {
!
! if (this.theArgs == null) {
! this.theArgs = arguments;
! }
!
! this.lastMessage = new _global.XMLMessage()
!
!
! for (var i=0; i<this.theArgs.length; i++) {
! this.lastMessage.AddParameter( this.theArgs[i] );
! }
!
! return this.lastMessage;
! }
!
! p.BuildXML = function ( theMsg ) {
!
! if (theMsg == null) {
! theMsg = this.lastMessage;
! }
!
! this.lastXML = theMsg.BuildXML( this.methodName );
! return this.lastXML;
! }
!
! p.Send = function(Server, proxy) {
! this.lastMessage.Send(Server, this.methodName, proxy);
! }
!
! delete p;
! delete c;
!
!
! c = _global.XMLRPC_ResponseHandler = function( onSuccess, onFailure, proxy) {
! this.onSuccessFunc = onSuccess;
! this.onFailureFunc = onFailure;
! this.proxy = proxy;
! }
!
! p = c.prototype = new Object();
!
! p.onSuccess = function( theXML ) {
! var argObj = loads( theXML )
! if (argObj.params.isFault == null) {
! //_global.gTrace("Applying " + this.onSuccessFunc + " to " + this.proxy + " using " + _global.serializeObject(argObj.params));
! this.proxy[this.onSuccessFunc].apply( this.proxy, argObj.params);
! }
! else {
! //_global.gTrace("Fault occured: " + _global.serializeObject(argObj.params));
! this.proxy[this.onFailureFunc].apply( this.proxy, [argObj.params]);
! }
! }
!
! p.onFailure = function( argObj ) {
! this.proxy[this.onFailureFunc]( argObj );
! }
!
! p.mapSuccess = function( newName ) {
! this[newName] = this.onSuccess;
! }
!
! p.mapFailure = function( newName ) {
! this[newName] = this.onFailure;
! }
!
! delete p;
! delete c;
Index: XML_Loader.as
===================================================================
RCS file: /cvsroot/zmx/zmx/Attic/XML_Loader.as,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -d -r1.1.2.2 -r1.1.2.3
*** XML_Loader.as 2 Mar 2004 21:37:05 -0000 1.1.2.2
--- XML_Loader.as 13 Jul 2011 11:17:16 -0000 1.1.2.3
***************
*** 1 ****
! //
//
// abstract Loader.. XML objects need to have attributes:
//
// nodeType, nodeName, and childNodes.
//
//
dynamic class zmx.XML_Loader {
var dispatch;
function XML_Loader() {
this.dispatch = {
boolean:this.doParseBoolean,
dateTimeType:this. doParseDate,
name:this.doParseString,
string:this.doParseString,
double:this.doParseFloat,
int:this.doParseInt,
fault:this.parseFault,
param:this.parseParam,
value:this.parseParam,
array:this.parseParam,
params:this.parseList,
data:this.parseList,
struct:this.doParseStruct,
member:this.doParseMember
}
}
function loads( xmlObj ) {
//
// start out being listish...
//
var value = null;
var currChild;
var name = null;
var aNode = xmlObj.firstChild;
while (aNode.nodeType == 3) { // skip text nodes...
aNode = aNode.nextSibling;
}
var result = this.result = new zmx.ZMX_DynamicObj({
methodCall : false,
methodResponse : false,
methodName : ''
});
if (aNode.nodeName == 'params') {
result.params = this.doParse( aNode );
}
else if (aNode.nodeName == 'methodCall') {
for (var i=0; i<aNode.childNodes.length; i++) {
currChild = aNode.childNodes[i];
if (currChild.nodeName == 'methodName') {
name = this.doParseString( currChild );
result.methodName = name;
result.methodCall = true;
}
else if (currChild.nodeName == 'params') {
result.params = this.doParse( currChild );
}
}
}
else if (aNode.nodeName == 'methodResponse') {
result.methodResponse = true;
var respChild = aNode.firstChild;
while( respChild != null) {
value = this.doParse( respChild )
if (value != null) {
break;
}
respChild = respChild.nextSibling;
}
result.params = value;
}
return result
}
function doParse( aNode ) {
if (aNode.nodeName != null) {
var nodeName = aNode.nodeName;
if (nodeName == 'dateTime.iso8601') {
nodeName = 'dateTimeType';
}
var dFunc = this.dispatch[nodeName];
if (dFunc != null) {
// we've got a parser for this node type..
return dFunc.apply(this, [aNode]);
}
else {
trace('No parse method for node ' + aNode.nodeName);
}
}
}
function parseList( aNode ) {
// parent should be root result object..
//
var currChild;
var val;
var listObj = [];
for (var i=0; i<aNode.childNodes.length; i++) {
currChild = aNode.childNodes[i];
if (currChild.nodeType == 1) { // doParse only wants nodeType == 1!
val = this.doParse( currChild );
if (val != null) {
listObj.push(val);
}
}
}
return listObj;
}
function doParseStruct( aNode ) {
var structObj = new zmx.ZMX_DynamicObj({});
var val;
var currChild;
for (var i=0; i<aNode.childNodes.length; i++) {
currChild = aNode.childNodes[i];
if (currChild.nodeType == 1) { // doParse only wants nodeType == 1!
val = this.doParse( currChild );
if (val != null) {
structObj[ val.name ] = val.value;
}
}
}
return structObj;
}
function doParseMember( aNode ) {
var structObj = {};
var value = null;
var name = null;
var currChild;
for (var i=0; i<aNode.childNodes.length; i++) {
currChild = aNode.childNodes[i];
if (currChild.nodeName == 'name') {
name = this.doParseString( currChild );
}
else if (currChild.nodeName == 'value') {
value = this.parseParam( currChild );
}
}
if ((name != null) && (value != null)) {
structObj.name = name;
structObj.value = value;
}
return structObj;
}
function parseParam( aNode ) {
var currChild;
var value;
for (var i=0; i<aNode.childNodes.length; i++) {
currChild = aNode.childNodes[i];
if (currChild.nodeType == 1) {
value = this.doParse( currChild );
break;
}
}
return value;
}
function parseFault( aNode ) {
var currChild;
var value;
for (var i=0; i<aNode.childNodes.length; i++) {
currChild = aNode.childNodes[i];
if (currChild.nodeType == 1) {
value = this.doParse( currChild );
break;
}
}
if (value == null) {
value = {isFault:true};
}
else
{
value.isFault = true;
}
return value;
}
function doParseInt( aNode ) {
var value = parseInt(aNode.firstChild.nodeValue);
return value;
}
function doParseFloat( aNode ) {
var value = parseFloat(aNode.firstChild.nodeValue);
return value;
}
function doParseString( aNode ) {
var value = aNode.firstChild.nodeValue;
return value == null ? '' : value;
}
function fromISO( aString) {
var dt = aString.split('T');
var datePart = dt[0];
var timePart = dt[1];
datePart = datePart.split('-').join('');
datePart = [datePart.slice(0,4),parseInt(datePart.slice(4,6))-1,datePart.slice(6,8)]
timePart = timePart.split(':').join('');
timePart = [timePart.slice(0,2),timePart.slice(2,4),timePart.slice(4)]
return new Date(datePart[0], datePart[1], datePart[2], timePart[0], timePart[1], timePart[2]);
}
function doParseDate( aNode ) {
var value = this.fromISO( aNode.firstChild.nodeValue );
return value;
}
function doParseBoolean( aNode ) {
var intValue = parseInt(aNode.firstChild.nodeValue);
return intValue == 0 ? false : true;
}
}
\ No newline at end of file
--- 1,248 ----
! //
! //
! // abstract Loader.. XML objects need to have attributes:
! //
! // nodeType, nodeName, and childNodes.
! //
! //
!
! dynamic class zmx.XML_Loader {
!
! var dispatch;
!
! function XML_Loader() {
! this.dispatch = {
! boolean:this.doParseBoolean,
! dateTimeType:this. doParseDate,
! name:this.doParseString,
! string:this.doParseString,
! double:this.doParseFloat,
! int:this.doParseInt,
! fault:this.parseFault,
! param:this.parseParam,
! value:this.parseParam,
! array:this.parseParam,
! params:this.parseList,
! data:this.parseList,
! struct:this.doParseStruct,
! member:this.doParseMember
! }
! }
!
! function loads( xmlObj ) {
!
! //
! // start out being listish...
! //
!
! var value = null;
! var currChild;
! var name = null;
! var aNode = xmlObj.firstChild;
!
! while (aNode.nodeType == 3) { // skip text nodes...
! aNode = aNode.nextSibling;
! }
!
! var result = this.result = new zmx.ZMX_DynamicObj({
! methodCall : false,
! methodResponse : false,
! methodName : ''
! });
!
! if (aNode.nodeName == 'params') {
! result.params = this.doParse( aNode );
! }
! else if (aNode.nodeName == 'methodCall') {
! for (var i=0; i<aNode.childNodes.length; i++) {
! currChild = aNode.childNodes[i];
! if (currChild.nodeName == 'methodName') {
! name = this.doParseString( currChild );
! result.methodName = name;
! result.methodCall = true;
! }
! else if (currChild.nodeName == 'params') {
! result.params = this.doParse( currChild );
! }
! }
! }
! else if (aNode.nodeName == 'methodResponse') {
! result.methodResponse = true;
! var respChild = aNode.firstChild;
! while( respChild != null) {
! value = this.doParse( respChild )
! if (value != null) {
! break;
! }
! respChild = respChild.nextSibling;
! }
! result.params = value;
! }
! return result
! }
!
! function doParse( aNode ) {
!
! if (aNode.nodeName != null) {
! var nodeName = aNode.nodeName;
! if (nodeName == 'dateTime.iso8601') {
! nodeName = 'dateTimeType';
! }
!
! var dFunc = this.dispatch[nodeName];
! if (dFunc != null) {
! // we've got a parser for this node type..
! return dFunc.apply(this, [aNode]);
! }
! else {
! trace('No parse method for node ' + aNode.nodeName);
! }
! }
! }
!
!
! function parseList( aNode ) {
! // parent should be root result object..
! //
!
! var currChild;
! var val;
! var listObj = [];
!
! for (var i=0; i<aNode.childNodes.length; i++) {
! currChild = aNode.childNodes[i];
! if (currChild.nodeType == 1) { // doParse only wants nodeType == 1!
! val = this.doParse( currChild );
! if (val != null) {
! listObj.push(val);
! }
! }
! }
!
! return listObj;
! }
!
! function doParseStruct( aNode ) {
! var structObj = new zmx.ZMX_DynamicObj({});
! var val;
! var currChild;
!
! for (var i=0; i<aNode.childNodes.length; i++) {
! currChild = aNode.childNodes[i];
! if (currChild.nodeType == 1) { // doParse only wants nodeType == 1!
! val = this.doParse( currChild );
! if (val != null) {
! structObj[ val.name ] = val.value;
! }
! }
! }
!
! return structObj;
! }
!
! function doParseMember( aNode ) {
!
! var structObj = {};
! var value = null;
! var name = null;
! var currChild;
!
! for (var i=0; i<aNode.childNodes.length; i++) {
! currChild = aNode.childNodes[i];
! if (currChild.nodeName == 'name') {
! name = this.doParseString( currChild );
! }
! else if (currChild.nodeName == 'value') {
! value = this.parseParam( currChild );
! }
! }
!
! if ((name != null) && (value != null)) {
! structObj.name = name;
! structObj.value = value;
! }
!
! return structObj;
! }
!
!
! function parseParam( aNode ) {
!
! var currChild;
! var value;
!
! for (var i=0; i<aNode.childNodes.length; i++) {
! currChild = aNode.childNodes[i];
! if (currChild.nodeType == 1) {
! value = this.doParse( currChild );
! break;
! }
! }
! return value;
! }
!
! function parseFault( aNode ) {
!
! var currChild;
! var value;
!
! for (var i=0; i<aNode.childNodes.length; i++) {
! currChild = aNode.childNodes[i];
! if (currChild.nodeType == 1) {
! value = this.doParse( currChild );
! break;
! }
! }
!
! if (value == null) {
! value = {isFault:true};
! }
! else
! {
! value.isFault = true;
! }
! return value;
! }
!
! function doParseInt( aNode ) {
! var value = parseInt(aNode.firstChild.nodeValue);
! return value;
! }
!
! function doParseFloat( aNode ) {
! var value = parseFloat(aNode.firstChild.nodeValue);
! return value;
! }
!
! function doParseString( aNode ) {
! var value = aNode.firstChild.nodeValue;
! return value == null ? '' : value;
! }
!
! function fromISO( aString) {
!
! var dt = aString.split('T');
!
! var datePart = dt[0];
! var timePart = dt[1];
!
! datePart = datePart.split('-').join('');
! datePart = [datePart.slice(0,4),parseInt(datePart.slice(4,6))-1,datePart.slice(6,8)]
!
! timePart = timePart.split(':').join('');
! timePart = [timePart.slice(0,2),timePart.slice(2,4),timePart.slice(4)]
!
! return new Date(datePart[0], datePart[1], datePart[2], timePart[0], timePart[1], timePart[2]);
! }
!
! function doParseDate( aNode ) {
! var value = this.fromISO( aNode.firstChild.nodeValue );
! return value;
! }
!
! function doParseBoolean( aNode ) {
! var intValue = parseInt(aNode.firstChild.nodeValue);
! return intValue == 0 ? false : true;
! }
!
! }
Index: XMLRPCLib.as
===================================================================
RCS file: /cvsroot/zmx/zmx/Attic/XMLRPCLib.as,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -d -r1.1.2.2 -r1.1.2.3
*** XMLRPCLib.as 2 Mar 2004 21:37:05 -0000 1.1.2.2
--- XMLRPCLib.as 13 Jul 2011 11:17:16 -0000 1.1.2.3
***************
*** 1 ****
! /*
**
** Start simple....
**
** this is a 'pure' javascript core for ZMX_XML.as
**
** it's so much easier to debug/develop with rhino...
**
*/
import zmx.XML_Dumper
import zmx.XML_Loader
import zmx.XMLFunction
import zmx.XMLRPC_ResponseHandler
class zmx.XMLRPCLib {
var dumps = function(params, methodname, methodresponse) {
var m = new zmx.XML_Dumper();
var data = m.dumps(params)
if (methodname != null) {
data = "<methodCall><methodName>" + methodname + "</methodName>" + data + "</methodCall>";
}
else if (methodresponse != null) {
data = "<methodResponse>" + data + "</methodResponse>";
}
return data;
}
var loads = function( xmlObj) {
var m = new zmx.XML_Loader();
var result = m.loads(xmlObj)
return result;
}
var Args_To_XML = function ( args, method ) {
var xmlFunc = new zmx.XMLFunction( method );
return xmlFunc.BuildArgumentMessage.apply(xmlFunc, args);
}
var Arg_To_XML = function ( arg, method ) {
return this.Args_To_XML([arg], method);
}
var XML_To_Args = function ( theXML ) {
var argObj = this.XML_To_ArgObject( theXML );
return argObj.params;
}
var XML_To_ArgObject = function ( theXML ) {
return this.dumps( theXML );
}
var XML_CallWithArg = function ( theURL, methodName, theArg, successFunc, failFunc, client) {
//
// Deprecated! Use XML_CallWithArgs instead..
//
// theURL: URL to get 'object' reference
// methodName : method of object to call
// theArgs : arguments to pass
// successFunc: method of client to call for success notification
// failFunc : method of client to call for failure notification
// client: object to be notified..
return this.XML_CallWithArgs( theURL, methodName, [theArg], successFunc, failFunc, client);
}
var XML_CallWithArgs = function ( theURL, methodName, theArgs, successFunc, failFunc, client) {
//
// theURL: URL to get 'object' reference
// methodName : method of object to call
// theArgs : arguments to pass
// successFunc: method of client to call for success notification
// failFunc : method of client to call for failure notification
// client: object to be notified..
// useLCServer: set to 'true' if the connection should be made via a LocalConnection object
//
var proxy = new zmx.XMLRPC_ResponseHandler( successFunc, failFunc, client);
var rpcFunction = new zmx.XMLFunction( methodName );
rpcFunction.BuildArguments.apply(rpcFunction, theArgs);
rpcFunction.Send(theURL, proxy);
return rpcFunction;
}
}
\ No newline at end of file
--- 1,92 ----
! /*
! **
! ** Start simple....
! **
! ** this is a 'pure' javascript core for ZMX_XML.as
! **
! ** it's so much easier to debug/develop with rhino...
! **
! */
!
! import zmx.XML_Dumper
! import zmx.XML_Loader
! import zmx.XMLFunction
! import zmx.XMLRPC_ResponseHandler
!
! class zmx.XMLRPCLib {
!
! var dumps = function(params, methodname, methodresponse) {
!
! var m = new zmx.XML_Dumper();
! var data = m.dumps(params)
!
! if (methodname != null) {
! data = "<methodCall><methodName>" + methodname + "</methodName>" + data + "</methodCall>";
! }
! else if (methodresponse != null) {
! data = "<methodResponse>" + data + "</methodResponse>";
! }
!
! return data;
! }
!
! var loads = function( xmlObj) {
!
! var m = new zmx.XML_Loader();
! var result = m.loads(xmlObj)
!
! return result;
! }
!
! var Args_To_XML = function ( args, method ) {
! var xmlFunc = new zmx.XMLFunction( method );
! return xmlFunc.BuildArgumentMessage.apply(xmlFunc, args);
! }
!
! var Arg_To_XML = function ( arg, method ) {
! return this.Args_To_XML([arg], method);
! }
!
! var XML_To_Args = function ( theXML ) {
! var argObj = this.XML_To_ArgObject( theXML );
! return argObj.params;
! }
!
! var XML_To_ArgObject = function ( theXML ) {
! return this.dumps( theXML );
! }
!
! var XML_CallWithArg = function ( theURL, methodName, theArg, successFunc, failFunc, client) {
! //
! // Deprecated! Use XML_CallWithArgs instead..
! //
! // theURL: URL to get 'object' reference
! // methodName : method of object to call
! // theArgs : arguments to pass
! // successFunc: method of client to call for success notification
! // failFunc : method of client to call for failure notification
! // client: object to be notified..
!
! return this.XML_CallWithArgs( theURL, methodName, [theArg], successFunc, failFunc, client);
! }
!
! var XML_CallWithArgs = function ( theURL, methodName, theArgs, successFunc, failFunc, client) {
! //
! // theURL: URL to get 'object' reference
! // methodName : method of object to call
! // theArgs : arguments to pass
! // successFunc: method of client to call for success notification
! // failFunc : method of client to call for failure notification
! // client: object to be notified..
! // useLCServer: set to 'true' if the connection should be made via a LocalConnection object
! //
!
! var proxy = new zmx.XMLRPC_ResponseHandler( successFunc, failFunc, client);
! var rpcFunction = new zmx.XMLFunction( methodName );
! rpcFunction.BuildArguments.apply(rpcFunction, theArgs);
! rpcFunction.Send(theURL, proxy);
! return rpcFunction;
! }
!
! }
!
|