PATH |
Inherits from: Object
Package: com.webobjects.appserver.xml
Use this class to encode objects as XML. Encoding can take place either with or without a mapping model. The mapping model provides greater control over the encoding process and is typically used when you are encoding and decoding XML that is destined for, or originates from, an external source. When the WOXMLCoder and WOXMLCoder are used as an archiving mechanism, the mapping model is usually not necessary. For more information on the mapping model, see the "The Format of the Mapping Model" (page 4) in the framework introduction.
When encoding without a mapping model, WOXMLCoder is able to encode any object as long as the object and all of the objects it encapsulates either implement the WOXMLCoder interface or are an instance of String, Number (or a subclass, providing that the subclass doesn't add any new instance variables), NSArray, NSDictionary, NSDate, NSData, or EOEnterpriseObject (or a subclass, providing that all instance variables are either attributes or relationships). During the encoding of an enterprise object, WOXMLCoder uses attribute information stored in the EOModel when assigning an XML type tag to an object. For objects that don't inherit from EOEnterpriseObject, the tag supplied by WOXMLCoder's encodeObjectForKey method is used.
To encode an object, simply invoke the encodeRootObjectForKey method. To perform the reverse operation, generating an object from XML data, see the WOXMLCoder class.
Creating a WOXMLCoder coder coderWithMapping Encoding an object graph encodeRootObjectForKey Implementing the WOXMLCoding interface encodeBooleanForKey encodeDoubleForKey encodeFloatForKey encodeIntForKey encodeObjectForKey
protected WOXMLCoder
public static WOXMLCoder coder()
Creates and returns a new WOXMLCoder object.
public static WOXMLCoder coderWithMapping(String mappingURL)
Creates and returns a new WOXMLCoder object initialized with the mapping model specified by mappingURL. See "The Format of the Mapping Model" (page 4) for a complete description of the mapping model.
Note: Windows NT uses backslashes where other systems use forward slashes. When prepending the "file:" URL prefix to a path such as is returned by WOResourceManager's pathForResourceNamed method, on Windows NT the prefix must be "file:\\" while on all other platforms the prefix must be "file://". See the RelatedLinks example for one way to select the proper prefix based upon the underlying system. |
protected void cr()
public void encodeBooleanForKey( boolean flag, String key)
Invoke from within in your implementation of WOXMLCoder's encodeWithWOXMLCoder method to append an element with XML tag key to the WOXMLCoder object's internal string buffer. The element's XML content is the string representation of flag-either True or False-and the element has an attribute named type with a value of boolean. For example, the following call to encodeBooleanForKey:
encodeBooleanForKey(true, "myTag");
causes the following text to be appended to the WOXMLCoder's internal string buffer:
<myTag type="boolean">True</myTag>
protected String encodedClassName()
public void encodeDoubleForKey( double aDouble, String key)
Invoke from within in your implementation of WOXMLCoder's encodeWithWOXMLCoder method to append an element of type key to the WOXMLCoder object's internal string buffer. The element's content is the string value of aDouble and the element has an attribute named type with a value of double. For example, the following call to encodeDoubleForKey:
encodeDoubleForKey(1.23, "myTag");
causes the following text to be appended to the WOXMLCoder's internal string buffer:
<myTag type="double">1.23</myTag>
public void encodeFloatForKey( float aFloat, String key)
Invoke from within in your implementation of WOXMLCoder's encodeWithWOXMLCoder method to append an element of type key to the WOXMLCoder object's internal string buffer. The element's content is the string value of aFloat and the element has an attribute named type with a value of float. For example, the following call to encodeFloatForKey:
encodeFloatForKey(1.23, "myTag");
causes the following text to be appended to the WOXMLCoder's internal string buffer:
<myTag type="float">1.23</myTag>
public void encodeIntForKey( int anInt, String key)
Invoke from within in your implementation of WOXMLCoder's encodeWithWOXMLCoder method to append an element of type key to the WOXMLCoder object's internal string buffer. The element's content is the string value of anInt and the element has an attribute named type with a value of int. For example, the following call to encodeIntForKey:
encodeIntForKey(123, "myTag");
causes the following text to be appended to the WOXMLCoder's internal string buffer:
<myTag type="int">123</myTag>
public void encodeObjectForKey( Object anObject, String key)
Invoke from within in your implementation of WOXMLCoder's encodeWithWOXMLCoder method to append an element of type key to the WOXMLCoder object's internal string buffer. The element's content depends on anObject's class. anObject must meet the same criteria outlined in encodeRootObjectForKey.
encodeRootObjectForKey relies upon this method to perform the actual encoding of objects.
protected void encodeObjectInTag( String, String, String)
protected void encodeReferenceInTag( int, String, String
public synchronized String encodeRootObjectForKeyForKey( Object anObject, String key)
Encodes anObject as XML and returns the resulting XML string. The encoded root object is tagged using key, and has a type attribute that indicates anObject's class. anObject must be one of the following:
If anObject is not one of the above, encodeRootObjectForKey throws an exception.
protected void encodeStringInTag( String, String, String)
protected String escapeString(String escapeString)
protected boolean typeNeedsIndentation(Object)
protected String xmlTagForClassNamed(String className)
protected String xmlTagForPropertyKey( String, String)
© 2001 Apple Computer, Inc. (Last Published April 15, 2001)