What's the maximum depth the recursion will ever reach?

Well thats the problem you see.... With circular references there is no bottom, it'll keep going until CFMX runs out of memory to play with.

Got any source code to look at?


Ermm Aye... Bit of a monster mind.... Any suggestions gratefully received... Also, in hindsight, I might have put my counter check in the wrong place.... Another pair of eyes would be appreciated.



<cfscript> Counter = 0; CounterMax = 500;

function Object2Struct(thisObject) {
/* Function to copy webservice object to CF struct for easier output and manipulation
Function arguments are :
thisObject
- object to be converted to struct
- REQUIRED
ignoreObjects
- list of objects in thisObject to be ignored and not added to the struct
- OPTIONAL
- default empty list
debug
- true/false to turn on/off the WriteOutputs for debugging
- OPTIONAL
- Default false


Calling the Function :
Object2Struct must be passed the above arguments in the order:
thisObject, ignoreObjects,debug
The global variables Counter and CounterMax must be defined outside the function. These
variables are to try and prevent circular references in a malformed object from locking up
the CFMX server.

Author : Stephen Moretti ([EMAIL PROTECTED])
Last Update : 29th January 2004
*/
// Local Variable Definition
var outStruct = StructNew();
var KeyList = '';
var ObjectItem = '';
var excpt = '';
var i=0;
var j=0;


switch (ArrayLen(arguments)){
case 1:{
ignoreObjects = '';
debug = false;
break;
}
case 2:{
if (IsBoolean(arguments[2])) {
debug = arguments[2];
ignoreObjects = '';
} else {
ignoreObjects = arguments[2];
debug = false;
}
break;
}
case 3: {
ignoreObjects = arguments[2];
debug = arguments[3];
break;
}
}

if (IsDefined("thisObject") AND (IsObject(thisObject) OR IsStruct(thisObject))) {
KeyList = StructKeyList(thisObject);
if (debug) Writeoutput(KeyList&"<BR>");
for (i=1;i LTE ListLen(KeyList);i=i+1) {
ObjectItem = ListGetAt(KeyList,i);
if (debug) WriteOutput("<b>"&ObjectItem&"</b> - ");
try {
if (IsSimpleValue(thisObject[ObjectItem])) {
if (debug) WriteOutput("(S) "&thisobject[ObjectItem]&"<br>");
outStruct[ObjectItem] = thisObject[ObjectItem];
}
else if (IsStruct(thisObject[ObjectItem])) {
if (debug) WriteOutput("(St) - "&StructKeyList(thisObject[ObjectItem])&"<BR>");
outStruct[ObjectItem] = structnew();
outStruct[ObjectItem] = duplicate(Object2Struct(thisObject[ObjectItem],ignoreObjects,debug));
}
else if (IsArray(thisObject[ObjectItem])) {
if (debug) WriteOutput("(A) "&ArrayLen(thisObject[ObjectItem])&"<BR>");
if (ListFindNoCase(IgnoreObjects,ObjectItem) EQ 0) {
outStruct[ObjectItem] = arraynew(1);
if(ArrayLen(thisObject[ObjectItem]) GT 0) {
if (debug) WriteOutput("* "&ObjectItem&" Array Start *<br>");
for (j=1;j LTE ArrayLen(thisObject[ObjectItem]); j=j+1) {
if (debug) WriteOutput("* "&ObjectItem&" Array Element "&j&" START *<br>");
ArrayAppend(outStruct[ObjectItem],Object2Struct(thisObject[ObjectItem][j],ignoreObjects,debug));
if (debug) WriteOutput("* "&ObjectItem&" Array Element "&j&" END *<br>");
}
if (debug) WriteOutput("* "&ObjectItem&" Array End *<br>");
}
} else {
outStruct[ObjectItem] = 'ignored';
if (debug) Writeoutput('ignored <br>');
}
}
else if (IsObject(thisObject[ObjectItem])) {
if (debug) WriteOutput("(O) <BR>");
if (ListFindNoCase(IgnoreObjects,ObjectItem) EQ 0) {
if (debug) WriteOutput("* "&ObjectItem&" Object Start *<br>");
outStruct[ObjectItem] = structnew();
outStruct[ObjectItem] = duplicate(Object2Struct(thisObject[ObjectItem],ignoreObjects,debug));
if (debug) WriteOutput("* "&ObjectItem&" Object End *<br>");
} else {
outStruct[ObjectItem] = 'ignored';
if (debug) Writeoutput('ignored<br>');
}
}
}
catch (Any errorcontent) {
if (debug) WriteOutput("<b>"&ObjectItem&"</b> (e) <br>ERROR START<br>"&errorcontent.message&"<br>END ERROR<br>");
if (FindNoCase("undefined",errorcontent.message) GT 0)
outStruct[objectitem] = 'empty';
else outStruct[objectitem] = errorcontent.message;
}
Counter = Counter +1;
if (Counter GTE CounterMax) break;
}
return outStruct;
}
return 'Error occured : argument 1 in function call was not an object';
}
</cfscript>


Regards

Stephen

--
** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/

To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
For human help, e-mail: [EMAIL PROTECTED]



Reply via email to