|
WebObjects 5.2.3 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.webobjects.appserver.xml.WOXMLCoder
This class is used to encode objects as XML data. 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 a simple
archiving mechanism, the mapping model is usually not necessary. For more information on the
mapping model, see the "The Format of the Mapping Model" in the package description.
To encode an object, simply invoke the encodeRootObjectForKey
method. To perform
the reverse operation, generating an object from XML data, see the WOXMLDecoder class.
WOXMLDecoder
,
encodeRootObjectForKey(java.lang.Object, java.lang.String)
Field Summary | |
protected String |
xmlDeclaration
|
Constructor Summary | |
protected |
WOXMLCoder()
|
Method Summary | |
static WOXMLCoder |
coder()
Returns a default coder capable of encoding objects into XML data without using a mapping model. |
static WOXMLCoder |
coderWithMapping(String mappingURL)
Returns a coder object initialized with the mapping model specified by mappingURL . |
protected void |
cr()
|
void |
encodeBooleanForKey(boolean b,
String key)
Encodes a boolean value into XML data. |
protected String |
encodedClassName()
|
void |
encodeDoubleForKey(double d,
String key)
Encodes a double value into XML data. |
void |
encodeFloatForKey(float f,
String key)
Encodes a float value into XML data. |
void |
encodeIntForKey(int i,
String key)
Encodes an integer value into XML data. |
void |
encodeObjectForKey(Object object,
String key)
Encodes an object into XML data. |
protected void |
encodeObjectInTag(String s,
String xmlTag,
String type)
|
protected void |
encodeReferenceInTag(int objectID,
String xmlTag,
String type)
|
String |
encodeRootObjectForKey(Object object,
String key)
Encodes an object so that it becomes the root element for the generated XML data. |
protected void |
encodeStringInTag(String s,
String xmlTag,
String type)
|
protected String |
escapeString(String toValidate)
|
void |
setXmlDeclaration()
Sets the XML declaration to the default: <?xml version="1.0" ?> |
void |
setXmlDeclaration(String version,
String encoding,
String standalone)
Sets the XML declaration according to the parameters passed. |
protected boolean |
typeNeedsIndentation(Object o)
|
String |
xmlDeclaration()
Gets the previously specified XML declaration. |
protected String |
xmlTagForClassNamed(String className)
|
protected String |
xmlTagForPropertyKey(String propertyKey,
String className)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected String xmlDeclaration
Constructor Detail |
protected WOXMLCoder()
Method Detail |
public static WOXMLCoder coder()
decoder
factory method in
WOXMLDecoder. When encoding a custom object using the WOXMLCoder without a mapping model,
your custom class needs to implement encodeWithWOXMLCoder
declared in the WOXMLCoding
interface (your implementation of this method is where you encode the custom class's
instance variables). You don't need this if the object you are encoding is:
WOXMLDecoder.decoder()
,
WOXMLCoding
public static WOXMLCoder coderWithMapping(String mappingURL)
mappingURL
. For more information on the mapping model, see the
"The Format of the Mapping Model" in the package description.
This method corresponds directly with the decoderWithMapping
factory method
in WOXMLDecoder.
mappingURL
- an URL to the mapping file that specifies the mapping modelWOXMLDecoder.decoderWithMapping(java.lang.String)
protected void cr()
public void encodeBooleanForKey(boolean b, String key)
encodeRootObjectForKey
or directly as part of encodeWithWOXMLCoder
. Note that nothing is returned
from this method but the internal state of WOXMLCoder gets appended with the generated XML
data as a result of this method call. The XML data will eventually be returned as a result
of encodeRootObjectForKey
.
key
is used as the XML element and the content is the string
representation of b
-either "True" or "False"-and the element has an attribute
type="boolean"
. For example, the following call
encodeBooleanForKey(true, "myTag");causes the following XML data to be appended to the WOXMLCoder's internal state:
<myTag type="boolean">True</myTag>
key
is ignored when a mapping model is used as the model specifies what
XML tag to use.
b
- the boolean value to be encodedkey
- the XML tag to be used for the XML data generatedencodeRootObjectForKey(java.lang.Object, java.lang.String)
,
WOXMLCoding.encodeWithWOXMLCoder(com.webobjects.appserver.xml.WOXMLCoder)
public void encodeDoubleForKey(double d, String key)
encodeRootObjectForKey
or directly as part of encodeWithWOXMLCoder
. Note that nothing is returned
from this method but the internal state of WOXMLCoder gets updated with the generated XML
data as a result of this method call. The XML data will eventually be returned as a result
of encodeRootObjectForKey
.
key
is used as the XML element and the content is the string
representation of d
and the element has an attribute
type="double"
. For example, the following call
encodeDoubleForKey(1.23, "myTag");causes the following XML data to be appended to the WOXMLCoder's internal state:
<myTag type="double">1.23</myTag>
key
is ignored when a mapping model is used as the model specifies what
XML tag to use.
d
- the double value to be encodedkey
- the XML tag to be used for the XML data generatedencodeRootObjectForKey(java.lang.Object, java.lang.String)
,
WOXMLCoding.encodeWithWOXMLCoder(com.webobjects.appserver.xml.WOXMLCoder)
public void encodeFloatForKey(float f, String key)
encodeRootObjectForKey
or directly as part of encodeWithWOXMLCoder
. Note that nothing is returned
from this method but the internal state of WOXMLCoder gets updated with the generated XML
data as a result of this method call. The XML data will eventually be returned as a result
of encodeRootObjectForKey
.
key
is used as the XML element and the content is the string
representation of f
and the element has an attribute
type="float"
. For example, the following call
encodeFloatForKey(1.23, "myTag");causes the following XML data to be appended to the WOXMLCoder's internal state:
<myTag type="float">1.23</myTag>
key
is ignored when a mapping model is used as the model specifies what
XML tag to use.
f
- the float value to be encodedkey
- the XML tag to be used for the XML data generatedencodeRootObjectForKey(java.lang.Object, java.lang.String)
,
WOXMLCoding.encodeWithWOXMLCoder(com.webobjects.appserver.xml.WOXMLCoder)
public void encodeIntForKey(int i, String key)
encodeRootObjectForKey
or directly as part of encodeWithWOXMLCoder
. Note that nothing is returned
from this method but the internal state of WOXMLCoder gets updated with the generated XML
data as a result of this method call. The XML data will eventually be returned as a result
of encodeRootObjectForKey
.
key
is used as the XML element and the content is the string
representation of i
and the element has an attribute
type="int"
. For example, the following call
encodeIntForKey(123, "myTag");causes the following XML data to be appended to the WOXMLCoder's internal state:
<myTag type="int">123</myTag>
key
is ignored when a mapping model is used as the model specifies what
XML tag to use.
i
- the integer value to be encodedkey
- the XML tag to be used for the XML data generatedencodeRootObjectForKey(java.lang.Object, java.lang.String)
,
WOXMLCoding.encodeWithWOXMLCoder(com.webobjects.appserver.xml.WOXMLCoder)
public void encodeObjectForKey(Object object, String key)
encodeRootObjectForKey
or directly as part of encodeWithWOXMLCoder
. Note that nothing is returned
from this method but the internal state of WOXMLCoder gets appended with the generated XML
data as a result of this method call. The XML data will eventually be returned as a result
of encodeRootObjectForKey
.
If a mapping model is not used, object
has to be an instance of a limited set of classes described in coder
or its
class has to implement WOXMLCoding interface.
key
is ignored when a mapping model is used or
when object
is an Enterprise Object. In the former case, the mapping model
specifies what XML tag to use. In the latter, attribute information stored in the EOModel
is used when assigning an XML tag.
object
- the object to be encoded as XML datakey
- the XML tag to be used for the XML data generated from object
encodeRootObjectForKey(java.lang.Object, java.lang.String)
,
WOXMLCoding.encodeWithWOXMLCoder(com.webobjects.appserver.xml.WOXMLCoder)
protected void encodeObjectInTag(String s, String xmlTag, String type)
protected void encodeReferenceInTag(int objectID, String xmlTag, String type)
public String encodeRootObjectForKey(Object object, String key)
object
has to be an instance of a limited set of classes described in coder
or its
class has to implement WOXMLCoding interface.
key
is ignored when a mapping model is used or
when object
is an Enterprise Object. In the former case, the mapping model
specifies what XML tag to use. In the latter, attribute information stored in the EOModel
is used when assigning an XML tag.
object
- the object to be encoded as XML datakey
- the XML tag to be used for the XML data generated from object
setXmlDeclaration
has been called, a complete XML document is
returned. Else an XML segment is returned.coder()
,
setXmlDeclaration()
,
WOXMLCoding
protected void encodeStringInTag(String s, String xmlTag, String type)
protected String encodedClassName()
protected String escapeString(String toValidate)
public void setXmlDeclaration()
public void setXmlDeclaration(String version, String encoding, String standalone)
version
- XML version numberencoding
- the encoding of the XML data, for example, "ISO-8859-1";
if null
, it will not be setstandalone
- indicates if XML document can 'standalone';
if null
, it will not be setprotected boolean typeNeedsIndentation(Object o)
public String xmlDeclaration()
protected String xmlTagForClassNamed(String className)
protected String xmlTagForPropertyKey(String propertyKey, String className)
|
Last updated Thu Oct 21 15:04:16 PDT 2004. | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |