Class SimpleDocument

All Implemented Interfaces:
ExternalizableLite, PortableObject, XmlDocument, XmlElement, XmlSerializable, XmlValue, Externalizable, Serializable, Cloneable

public class SimpleDocument extends SimpleElement implements XmlDocument, Externalizable
A simple implementation of the XmlElement interface. Protected methods are provided to support inheriting classes.
Author:
cp 2000.10.20
See Also:
  • Constructor Details

    • SimpleDocument

      public SimpleDocument()
      Construct an empty SimpleDocument. Note: this constructor is needed only to comply with the requirements for the Externalizable and ExternalizableLite interfaces.
    • SimpleDocument

      public SimpleDocument(String sName)
      Construct a SimpleDocument.
      Parameters:
      sName - the name of the root element
    • SimpleDocument

      public SimpleDocument(String sName, String sDtdUri, String sDtdName)
      Construct a SimpleDocument.
      Parameters:
      sName - the name of the root element
      sDtdUri - the URI of the DTD (system identifier)
      sDtdName - the name of the DTD (public identifier); may be null
  • Method Details

    • getDtdUri

      public String getDtdUri()
      Get the URI of the DTD (DOCTYPE) for the document. This is referred to as the System Identifier by the XML specification. For example: http://java.sun.com/j2ee/dtds/web-app_2_2.dtd
      Specified by:
      getDtdUri in interface XmlDocument
      Returns:
      the document type URI
    • setDtdUri

      public void setDtdUri(String sUri)
      Set the URI of the DTD (DOCTYPE) for the document. This is referred to as the System Identifier by the XML specification.
      Specified by:
      setDtdUri in interface XmlDocument
      Parameters:
      sUri - the document type URI
    • getDtdName

      public String getDtdName()
      Get the public identifier of the DTD (DOCTYPE) for the document. For example: -//Sun Microsystems, Inc.//DTD Web Application 1.2//EN
      Specified by:
      getDtdName in interface XmlDocument
      Returns:
      the DTD public identifier
    • setDtdName

      public void setDtdName(String sName)
      Set the public identifier of the DTD (DOCTYPE) for the document.
      Specified by:
      setDtdName in interface XmlDocument
      Parameters:
      sName - the DTD public identifier
    • getEncoding

      public String getEncoding()
      Get the encoding string for the XML document. Documents that are parsed may or may not have the encoding string from the persistent form of the document.
      Specified by:
      getEncoding in interface XmlDocument
      Returns:
      the encoding set for the document
    • setEncoding

      public void setEncoding(String sEncoding)
      Set the encoding string for the XML document.
      Specified by:
      setEncoding in interface XmlDocument
      Parameters:
      sEncoding - the encoding that the document will use
    • getDocumentComment

      public String getDocumentComment()
      Get the XML comment that appears outside of the root element. This differs from the Comment property of this object, which refers to the comment within the root element.
      Specified by:
      getDocumentComment in interface XmlDocument
      Returns:
      the document comment
    • setDocumentComment

      public void setDocumentComment(String sComment)
      Set the XML comment that appears outside of the root element. This differs from the Comment property of this object, which refers to the comment within the root element.
      Specified by:
      setDocumentComment in interface XmlDocument
      Parameters:
      sComment - the document comment
    • writeXml

      public void writeXml(PrintWriter out, boolean fPretty)
      Write the XML document, including an XML header and DOCTYPE if one exists. This overrides the contract of the XmlElement super interface.
      Specified by:
      writeXml in interface XmlDocument
      Specified by:
      writeXml in interface XmlElement
      Overrides:
      writeXml in class SimpleElement
      Parameters:
      out - a PrintWriter object to use to write to
      fPretty - true to specify that the output is intended to be as human readable as possible
    • hashCode

      public int hashCode()
      Provide a hash value for this XML document and all of its contained information. Note that this overrides the contract of the hashCode method in the super interface XmlElement. The hash value is defined as a xor of the following:
      1. the hashCode from the root element
      2. the hashCode from the document type (uri and optional name)
      Specified by:
      hashCode in interface XmlDocument
      Specified by:
      hashCode in interface XmlElement
      Specified by:
      hashCode in interface XmlValue
      Overrides:
      hashCode in class SimpleElement
      Returns:
      the hash value for this XML document
    • equals

      public boolean equals(Object o)
      Compare this XML document and all of its contained information with another XML document for equality. Note that this overrides the contract of the equals method in the super interface XmlElement.
      Specified by:
      equals in interface XmlDocument
      Specified by:
      equals in interface XmlElement
      Specified by:
      equals in interface XmlValue
      Overrides:
      equals in class SimpleElement
      Returns:
      true if the documents are equal, false otherwise
    • clone

      public Object clone()
      Creates and returns a copy of this XmlDocument.
      Specified by:
      clone in interface XmlDocument
      Specified by:
      clone in interface XmlElement
      Specified by:
      clone in interface XmlValue
      Overrides:
      clone in class SimpleElement
      Returns:
      a clone of this instance.
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.
      Specified by:
      writeExternal in interface Externalizable
      Parameters:
      out - the stream to write the object to
      Throws:
      IOException - Includes any I/O exceptions that may occur
    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays. The readExternal method must read the values in the same sequence and with the same types as were written by writeExternal.
      Specified by:
      readExternal in interface Externalizable
      Parameters:
      in - the stream to read data from in order to restore the object
      Throws:
      IOException - if I/O errors occur
      ClassNotFoundException - If the class for an object being restored cannot be found.
    • readExternal

      public void readExternal(DataInput in) throws IOException
      Restore the contents of this object by loading the object's state from the passed DataInput object.
      Specified by:
      readExternal in interface ExternalizableLite
      Overrides:
      readExternal in class SimpleElement
      Parameters:
      in - the DataInput stream to read data from in order to restore the state of this object
      Throws:
      IOException - if an I/O exception occurs
    • writeExternal

      public void writeExternal(DataOutput out) throws IOException
      Save the contents of this object by storing the object's state into the passed DataOutput object.
      Specified by:
      writeExternal in interface ExternalizableLite
      Overrides:
      writeExternal in class SimpleElement
      Parameters:
      out - the DataOutput stream to write the state of this object to
      Throws:
      IOException - if an I/O exception occurs
    • readExternal

      public void readExternal(PofReader in) throws IOException
      Restore the contents of a user type instance by reading its state using the specified PofReader object.
      Specified by:
      readExternal in interface PortableObject
      Overrides:
      readExternal in class SimpleElement
      Parameters:
      in - the PofReader from which to read the object's state
      Throws:
      IOException - if an I/O error occurs
    • writeExternal

      public void writeExternal(PofWriter out) throws IOException
      Save the contents of a POF user type instance by writing its state using the specified PofWriter object.
      Specified by:
      writeExternal in interface PortableObject
      Overrides:
      writeExternal in class SimpleElement
      Parameters:
      out - the PofWriter to which to write the object's state
      Throws:
      IOException - if an I/O error occurs
    • toXml

      public XmlElement toXml()
      Serialize the object into an XmlElement.
      Specified by:
      toXml in interface XmlSerializable
      Overrides:
      toXml in class SimpleElement
      Returns:
      an XmlElement that contains the serialized form of the object
    • fromXml

      public void fromXml(XmlElement xml)
      Deserialize the object from an XmlElement. This method can throw one of several RuntimeExceptions.
      Specified by:
      fromXml in interface XmlSerializable
      Overrides:
      fromXml in class SimpleElement
      Parameters:
      xml - an XmlElement that contains the serialized form of the object
      Throws:
      UnsupportedOperationException - if this element is immutable
    • checkMutable

      protected void checkMutable()
      Validates that the document is mutable, otherwise throws an UnsupportedOperationException.
      Overrides:
      checkMutable in class SimpleElement
      Throws:
      UnsupportedOperationException - if the document is immutable