PATH |
WOXMLCoding
Implemented by: Custom objects that need to be encoded as XML
Package: com.webobjects.appserver.xml
Interface Description
When operating without a mapping model, the WOXMLCoding class is capable of encoding a predefined set of Java classes, any object that is an instance of EOEnterpriseObject, and any object that implements the WOXMLCoding interface. This interface consists of a single method, encodeWithWOXMLCoder, in which you encode your object's instance variables using WOXMLCoder's various encode...ForKey methods.
If you'll be reconstituting objects from XML using WOXMLCoding, your classes must have a constructor that takes a WOXMLDecoder object as its sole argument. This constructor should consist of a series of decode...ForKey method invocations that restore each of your object's instance variables.
The following simple "Person" class implements both the WOXMLCoding interface and the single-argument constructor needed to later decode objects of this class.
import com.webobjects.appserver.xml.*; import com.webobjects.foundation.*; import java.lang.*; import java.net.*; import java.math.*; public class Person extends Object implements WOXMLCoding { String name; boolean married; int children; public Person() { name = "John Smith"; married = true; children = 2; } public void encodeWithWOXMLCoder(WOXMLCoder coder) { coder.encodeObjectForKey(name, "Name"); coder.encodeBooleanForKey(married, "MaritalStatus"); coder.encodeIntForKey(children, "NumberOfChildren"); } // constructor required for decoding public Person(WOXMLDecoder decoder) { name = (String)decoder.decodeObjectForKey("Name"); married = decoder.decodeBooleanForKey("MaritalStatus"); children = decoder.decodeIntForKey("NumberOfChildren"); } }
See the XMLArchiving example (accessible through the WebObjects Info Center under Examples > WebObjects > Java > XMLArchiving) for a more complete example illustrating the use of the WOXMLCoding interface.
Instance Methods
classForCoder
public abstract Class classForCoder()
Description forthcoming.
encodeWithWOXMLCoder
public abstract void encodeWithWOXMLCoder(WOXMLCoder aCoder)
Implement this method using WOXMLCoder's various encode...ForKey methods (invoked on aCoder) to encode your object's instance variables.
See Also: WOXMLCoding class
© 2001 Apple Computer, Inc. (Last Published April 15, 2001)