com.wm.util.coder
Class IDataXMLCoder

java.lang.Object
  extended by com.wm.util.coder.IDataCoder
      extended by com.wm.util.coder.IDataXMLCoder

public class IDataXMLCoder
extends IDataCoder

This class extends IDataCoder and contains methods you use to encode IData objects as XML documents and decode XML documents as IData objects. These methods are often used to transform an IData object into an XML document (typically so you can easily store it to a file) and regenerate the IData object from the XML document at a later time.

Important: If you use IDataXMLCoder to encode IData objects, then you MUST use IDataXMLCoder. to decode it. Although webMethods may change the XML format produced by this class in the future, it will always remain backwardly compatible. If you modify the XML outside of IDataXMLCoder methods, you might not be able to decode that XML in a future release.

XMLCoder can encode IData objects that contain any of the following Object < types.

Valid Primary Object Types

IData IDataCodable Codable
Vector Number String
Mboolean boolean true or false

Valid Object Array Types

String[] IData[] IDataCodable[]
Vector[] Object[] Object[][]

Objects other than those listed above are not supported, and IDataXMLCoder will not encode or decode them. If an unsupported object is contained in an IData object that you are encoding, IDataXMLCoder will post a warning message to the debug log.

See Also:
IDataCodable, IDataXMLCoder, IData

Constructor Summary
IDataXMLCoder()
          Constructs a new IDataXMLCoder object.
 
Method Summary
 IData decode(java.io.InputStream is)
          Decodes the XML in the specified InputStream to an IData object.
 void encode(java.io.OutputStream os, IData data)
          Encodes the specified IData object as an XML document and writes that document to an OutputStream.
 java.lang.String getContentType()
          Returns a String object indicating the current content type.
 void setContentType(java.lang.String ctype)
          Sets the content type.
 void setIgnoreInvalid(boolean ignore)
          Sets a boolean flag that specifies whether this IDataXMLCoder ignores unsupported object types in the data that it encodes or decodes.
 void setUseOIDs(boolean use)
          Specifies whether Object Identifiers (OIDs) are assigned to object values.
 void setUseXMLHeader(boolean use)
          Sets a boolean flag that specifies whether or not an XML header (for example, <?xml version="1.0" encoding "UTF-8" >) is included in the XML document.
 
Methods inherited from class com.wm.util.coder.IDataCoder
decodeFromBytes, encodeToBytes, readFromFile, writeToFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IDataXMLCoder

public IDataXMLCoder()
Constructs a new IDataXMLCoder object.

Method Detail

decode

public IData decode(java.io.InputStream is)
             throws java.io.IOException,
                    InvalidDatatypeException
Decodes the XML in the specified InputStream to an IData object.

Specified by:
decode in class IDataCoder
Parameters:
is - An InputStream that contains the XML document that you want to decode.
Returns:
The IData object decoded from is.
Throws:
java.io.IOException - If an error occurs while reading InputStream.
InvalidDatatypeException - If the XML in InputStream cannot be decoded or it contains an unsupported object type and setIgnoreInvalid is false.
See Also:
setIgnoreInvalid(boolean), encode(java.io.OutputStream, com.wm.data.IData)

encode

public void encode(java.io.OutputStream os,
                   IData data)
            throws java.io.IOException,
                   InvalidDatatypeException
Encodes the specified IData object as an XML document and writes that document to an OutputStream.

Specified by:
encode in class IDataCoder
Parameters:
os - The OutputStream into which you want the XML-encoded IData object written.
data - The IData object that you want to encode.
Throws:
java.io.IOException - If error occurs while writing to the OutputStream.
InvalidDataTypeException - If the IData object contains an unsupported object type and setIgnoreInvalid is false.
InvalidDatatypeException - If the data in the IData object cannot be encoded (i.e., the IData object contains an object type that is not supported by the specific implementation of encode that you are using).
See Also:
setIgnoreInvalid(boolean), decode(java.io.InputStream)

getContentType

public java.lang.String getContentType()
Returns a String object indicating the current content type. The default content type for IDataXMLCoder objects is: text/xml

Specified by:
getContentType in class IDataCoder
Returns:
A String containing the content type for this IDataXMLCoder.
See Also:
setContentType(java.lang.String)

setContentType

public void setContentType(java.lang.String ctype)
Sets the content type. The default content type for XMLCoder is "text/xml". The coder classes, IDataXMLCoder and XMLCoder, both support the default content type. This method enables support for custom content types.

Note: If you want to use the standard webMethods ContentHandler, then do not use this method to override the default content type with a custom one.

Parameters:
ctype - A String specifying the content type for this XMLCoder.
See Also:
getContentType()

setIgnoreInvalid

public void setIgnoreInvalid(boolean ignore)
Sets a boolean flag that specifies whether this IDataXMLCoder ignores unsupported object types in the data that it encodes or decodes. The default is to ignore unsupported object types.

Parameters:
ignore - A boolean specifying whether unsupported objects are ignored.
Set ignore to…
To…
true Ignore unsupported objects types when encountered (default).
false Throw an InvalidDataTypeException when an unsupported object type is encountered.

setUseOIDs

public void setUseOIDs(boolean use)
Specifies whether Object Identifiers (OIDs) are assigned to object values. Assigning an OID to each object value better utilizes disk space, but demands more CPU usage and run-time memory (especially for large value sets). The default is to omit OIDs.

Parameters:
use - A boolean specifying whether to assign Object Identifiers (OID) to each object value.
Set use to…
To…
true Assign OIDs to object values.
false Omit OIDs from object values.

setUseXMLHeader

public void setUseXMLHeader(boolean use)
Sets a boolean flag that specifies whether or not an XML header (for example, <?xml version="1.0" encoding "UTF-8" >) is included in the XML document. The default behavior is to include the XML header.

Parameters:
use - A boolean specifying whether this IDataXMLCoder will include an XML header when it encodes an IData object as XML.
Set use to…
To…
true Include the XML header. (default)
false Omit the XML header.