Documentation of 'org.jhotdraw.xml.JavaPrimitivesDOMFactory' Java class
JavaPrimitivesDOMFactory
org.jhotdraw.xml

Class JavaPrimitivesDOMFactory

  • All Implemented Interfaces:
    DOMFactory
    Direct Known Subclasses:
    DefaultDOMFactory


    public class JavaPrimitivesDOMFactory
    extends java.lang.Object
    implements DOMFactory
    JavaPrimitivesDOMFactory can be used to serialize Java primitive objects and DOMStorable objects.

    The following Java primitive types are supported. Object wrappers are automatically unwrapped into their primitive types.

    • null
    • boolean
    • byte
    • short
    • char
    • int
    • long
    • float
    • double
    • string
    • enum
    • color (will be removed in a future revision of this class!)
    • font (will be removed in a future revision of this class!)
    Arrays of primitive types are supported, by appending the word "Array" to a primitive type name.

    You can add support for additional primitive types by overriding the methods read and write.

    In addition to the primitive types, this factory can store and read DOMStorable objects. No mapping for DOMStorable class names is performed. For example, if a DOMStorable object has the class name com.example.MyClass, then the DOM element has the same name, that is: <com.example.MyClass>.

    Since no mapping between DOM element names and DOMStorable class names is performed, DOM's generated with JavaPrimitivesDOMFactory are not suited for long-term storage of objects. This is because a DOM element can not be read back into an object, if the class name of the object has changed.

    You can implement a mapping by overriding the methods getName, create, getEnumName and getEnumValue.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      java.lang.Object create(java.lang.String name)
      Creates an object from the specified element name.
      java.lang.String getName(java.lang.Object o)
      Returns the element name for the specified object.
      java.lang.Object read(DOMInput in)
      Reads the specified object from DOMInput.
      void write(DOMOutput out, java.lang.Object o)
      Writes the specified object to DOMOutput.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JavaPrimitivesDOMFactory

        public JavaPrimitivesDOMFactory()
    • Method Detail

      • getName

        public java.lang.String getName(java.lang.Object o)
        Description copied from interface: DOMFactory
        Returns the element name for the specified object.
        Specified by:
        getName in interface DOMFactory
      • create

        public java.lang.Object create(java.lang.String name)
        Description copied from interface: DOMFactory
        Creates an object from the specified element name.
        Specified by:
        create in interface DOMFactory
      • write

        public void write(DOMOutput out,
                          java.lang.Object o)
                   throws java.io.IOException
        Description copied from interface: DOMFactory
        Writes the specified object to DOMOutput.

        This method is only ever called from DOMOutput. You should never call this method directly.

        Specified by:
        write in interface DOMFactory
        o - The object to be written.
        Throws:
        java.io.IOException
      • read

        @Nullable
        public java.lang.Object read(DOMInput in)
                                        throws java.io.IOException
        Description copied from interface: DOMFactory
        Reads the specified object from DOMInput.

        This method is only ever called from DOMInput. You should never call this method directly.

        If the object returned by this method is an instanceof DOMStorable then DOMInput invokes its read method.

        Specified by:
        read in interface DOMFactory
        Parameters:
        in - The DOMInput object which creates the object from an element in a DOM.
        Throws:
        java.io.IOException

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.