Cool Here You Go (this the serialize and deserialize functions....they only
work if you adhere to a naming conventions like that illustrated in the
attached code files...but feel free to seek inspiration from them and
improve upon them).  They are pretty loose and I just threw in some comments
for you to know what the heck is going on.  You can just pop in the files
into   a single directory in your wwwroot, and call the test.cfm page. Also,
you could cut and paste the serialize/deserialize functions and put them
into your CFusionMX/wwwroot/web-inf/cftags/component.cfc file so that all
the cfcs have access to them?  Not a recommended, but will work for a quick
test.

Hope this helps....sorry it is so sloppy, just haven't had time to clean it
up.

Justin


<!----ALL WDDX representions of a business objects instance data uses a
three element struct. The elements are called
instance - all instance data that is not composed of other cfcs
mulObj - this is instance data is composed of multiple cfcs
obj - this is instance data that is composed of a single cfc (could be
worked into above in the future?)
----->

        <cffunction name="serialize" returntype="any" output="yes"
access="public">
                <cfset var i = "" />
                <cfset var x = "" />
                <cfset var resultWDDX = StructNew() />
                <cfset var resut = StructNew() />
                <cfset result.mulObj = StructNew()/>
                <cfset result.obj = StructNew() />
                <cfset result.var = StructNew() />
                
                <!---All Business Objects store instance data in a struct
called variables.instance--->
                <cfif isDefined("variables.instance")>
                        <cfloop item="i" collection="#variables.instance#">
                                <!----If the instance variable is holding
multiple cfcs (based on some accepted naming convention, then build
                                a struct element called mulObj to hold the
wddx of the serialized objs---->
                                <cfif isStruct(variables.instance[i]) AND
NOT isObject(variables.instance[i]) AND RemoveChars(i,1,len(i)-6) EQ
"struct">
                                        <cfset result.mulObj[i] =
StructNew() />
                                        <cfloop
collection="#variables.instance[i]#" item="x">
                                                <cfset result.mulObj[i][x] =
variables.instance[i][x].serialize()/>
                                        </cfloop>
                                </cfif>
                                <!----If the instance variable is holding a
single cfc then set the struct element called obj to the wddx of the 
                                serialized object----->
                                <cfif isObject(variables.instance[i])>
                                        <cfset result.obj[i] =
variables.instance[i].serialize()/>
                                <cfelse>
                                        <!---This was taken out, becuase I
need to account for objects containing multiple objects
                                        so I need to come up with a naming
convention that I can use to denote that.  Something like
                                        getAddressComp() for an object
containing multiple addresses--->
                                        <!--- <cfif
RemoveChars(i,1,len(i)-6) NEQ "struct">
                                                <cfoutput>#i# =
#len(i)-6#</cfoutput> --->
                                        <!---This is the instance data that
is native to the cfc being serilaized---->
                                        <cfset result.var[i] =
variables.instance[i]>
                                        <!--- </cfif> --->
                                </cfif>
                        </cfloop>
                <cfelse>
                        <cfthrow message="Serialization Implementation
Error: You have tried to serialize an object, or a child object that does
not have any instance variables defined.  According the API, all
serializeable objects must have instance variables declared."/>
                </cfif>
                <cfwddx action="cfml2wddx" input="#result#"
output="resultWDDX" />
                <cfreturn resultWDDX />
        </cffunction>
        
        <cffunction name="deserialize" returntype="any" output="Yes"
access="public">
                <cfargument name="objData" required="Yes" type="any">
                <!----Set up local vars --->
                <cfset var temp = "" />
        <cfset var i = "" />
                <cfset var x = "" />
                <cfset var n = "" />
                <cfset var z = "" />
                <cfset var tempObj = ""/>
                <cfset var objectPath = "" />
                <cfset var wddxFile = "" />
                
                <!-------This simply converts the wddx to a structure of the
function to operate with--->
        <cfwddx action="wddx2cfml" input="#arguments.objData#" output="temp"
/>
                        <!--- <cfdump var="#temp#"/> --->
                        <!----If these elements are not defined in the
struct then there was a serialization
                        error and nothing can be done about it ----->
                        <cfif not IsDefined("temp.var") OR not
IsDefined("temp.obj") OR not IsDefined("temp.mulObj")>
                                <cfthrow message="Serialization Error: The
Object being Deserialized was not Serialized correctly. The struct returned
from the WDDX packet did not contain one the following required elements.
(var, obj, mulObj)."/>
                        </cfif>
                        
                        <cfif NOT StructIsEmpty(temp.mulObj)>
                                <cfloop collection="#temp.mulObj#" item="n">
                                                <cfloop
collection="#temp.mulObj[n]#" item="z">
                                                        <cfwddx
action="wddx2cfml" input="#temp.mulObj[n][z]#" output="wddxFile"/>
                                                        <!---Setting the
object Path that needs to be built---->
                                                        <cfset objectPath =
wddxFile.var.objectName />

                                                        <cfset tempObj =
CreateObject('component',objectPath)/>
                                                        <cfset
variables.instance[n][z] = tempObj.deserialize(temp.mulObj[n][z])/>
                                                        <cfset wddxFile =
""/>
                                                </cfloop>
                                </cfloop>
                        </cfif>
                        
                        
                        <!-----If the temp.cfc struct key is not empty, then
the instance var is an object, and it will
                        also need to be deserialized.--->
                        <cfif NOT StructIsEmpty(temp.obj)>
                                <cfloop collection="#temp.obj#" item="i">
                                        <!--- Object:<cfdump
var="#temp.obj[i]#"/> --->
                                        <!----Need to structify the WDDX to
grab the objectName var so that it can be rebuilt--->
                                        <cfwddx action="wddx2cfml"
input="#temp.obj[i]#" output="wddxFile"/>
                                        <!--- Object Wddx:<cfdump
var="#wddxFile#"/> --->
                                        <!---Setting the object Path that
needs to be built---->
                                        <cfset objectPath =
wddxFile.var.objectName />
                                        
                                        <cfset tempObj =
CreateObject('component',objectPath)/>
                                        <cfset variables.instance[i] =
tempObj.deserialize(temp.obj[i])/>
                                        <!----Reset the wddxFile output
var--->
                                        <cfset wddxFile = ""/>
                                </cfloop>
                        </cfif>
                        
                        <!---Set noObject instance variables ---->
                        <cfloop collection="#temp.var#" item="x">
                                <cfset variables.instance[x] = temp.var[x]
/>
                        </cfloop> 
                        <cfreturn this />
        </cffunction>

-----Original Message-----
From: Jeff Battershall [mailto:[EMAIL PROTECTED]
Sent: Monday, November 10, 2003 2:23 PM
To: [EMAIL PROTECTED]
Subject: RE: [CFCDev] Serialization/De-Serialization of CFCs


Justin,

Right now, I'm simply serializing/deserializing some nested structs and
arrays and using cfcs to manipulate them.  This is for an app that is

1) Going to be deployed across a cluster using Cisco Local Director and
non-sticky sessions.
2) Has to be cookie-less.

Right now, I'm storing everything in a db and using a uuid as the session
token. 

I'd rather just serialize/deserialize the CFCs that are being used because
it would be cleaner, but no dice.  Just interested in what others may have
done along this line.

By all means, send me what you've got - I'd definitely be interested in
looking at it.

Jeff

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Justin Balog
Sent: Monday, November 10, 2003 4:11 PM
To: '[EMAIL PROTECTED]'
Subject: RE: [CFCDev] Serialization/De-Serialization of CFCs


I wrote a serialize, deserialize function based on a recommendation by
Barney, mine depends on method naming conventions which sux, but you can
look at it you like and get an idea for how mine works?  Let me know.

Justin

[EMAIL PROTECTED]

-----Original Message-----
From: Jeff Battershall [mailto:[EMAIL PROTECTED]
Sent: Monday, November 10, 2003 2:07 PM
To: [EMAIL PROTECTED]
Subject: [CFCDev] Serialization/De-Serialization of CFCs


In some brief experimentation, I found I could serialize a CFC using WDDX,
but de-serialization did not work.

Has anyone played around with this?  Are there other techniques for
achieving persistence of CFCs across a cluster? 

Jeff Battershall
(610) 544-4795 p
[EMAIL PROTECTED]



----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev' 
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

An archive of the CFCDev list is available at
www.mail-archive.com/[EMAIL PROTECTED]
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev' 
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

An archive of the CFCDev list is available at
www.mail-archive.com/[EMAIL PROTECTED]


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev' 
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

An archive of the CFCDev list is available at
www.mail-archive.com/[EMAIL PROTECTED]

Attachment: test.cfm
Description: Binary data

Attachment: multipleObj.cfc
Description: Binary data

Attachment: mainObj.cfc
Description: Binary data

Attachment: childObj.cfc
Description: Binary data

Reply via email to