This handler is used to convert an object (Parent script instance) into a property list. Any properties of the object which contain objects are recursively serialized.
Great tool for sending information via MUS Xtra since objects aren't allowed.
-- This handler is used to create a property list out of an object
-- The object reference is traversed to create a property list with each property of the original object
on SerializeObject objectReference
-- Ensure that the paramater is an object of some kind
if not ( objectP( objectReference ) ) then
-- Just return what was passed in if not an object
return objectReference
end if
-- Create an empty property list
newPropList = [:]
-- See if the object is a list or not
if ( listP( objectReference ) ) then
-- It's a list, so check each element
listCount = objectReference.count
case ilk( objectReference ) of
#list:
-- Linear list, so just iterate through each element and see if they're all not objects
-- Create flag to tell if an object has been found
objectFoundFlag = FALSE
repeat with currentElement in objectReference
if objectP( currentElement ) then
-- An object was found, so the list has to be parsed each element separately
objectFoundFlag = TRUE
exit repeat
end if
end repeat
if not ( objectFoundFlag = TRUE ) then
-- No object was found in the list, so return the whole thing to the caller
return objectReference
else
-- Go thru each element since the entire list can't be returned
repeat with currentIndex = 1 to listCount
propValue = getAt( objectReference, currentIndex )
if objectP( propValue ) then
propValue = SerializeObject( propValue )
end if
propName = value( "#linearListElement_" & currentIndex )
setaProp( newPropList, propName, propValue )
end repeat
end if
#propList:
-- Property list, so need to get each name-value pair
repeat with currentIndex = 1 to listCount
propValue = getAt( objectReference, currentIndex )
if objectP( propValue ) then
propValue = SerializeObject( propValue )
end if
propName = getPropAt( objectReference, currentIndex )
setaProp( newPropList, propName, propValue )
end repeat
end case
else
-- Make sure it's an instance or object that can be serialized
if ( objectReference.ilk = #instance ) then
-- It's an object and not a list so serialize it directly
-- Determine how many properties there are
totalProps = count( objectReference )
-- Assign identical property values:
repeat with i = 1 to totalProps
-- Get the name of the current property
propName = getPropAt( objectReference, i )
-- Get the value for the property
propValue = getaProp( objectReference, propName )
if objectP( propValue ) then
-- Serialize the value for the property
propValue = SerializeObject( propValue )
end if
setaProp( newPropList, propName, propValue )
end repeat
else
-- This object can't be serialized, but it should be added with a note that it can't be
setaProp( newPropList, #unSerializableObject, string( objectReference ) )
-- Check for object instance
end if
-- Check for list
end if
return newPropList
end
Contact
MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA