JHotDraw 7.5.1

org.jhotdraw.xml
Class JavaPrimitivesDOMFactory

java.lang.Object
  extended by org.jhotdraw.xml.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.

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.

Version:
$Id: JavaPrimitivesDOMFactory.java 647 2010-01-24 22:52:59Z rawcoder $
Author:
Werner Randelshofer

Constructor Summary
JavaPrimitivesDOMFactory()
           
 
Method Summary
 java.lang.Object create(java.lang.String name)
          Creates an object from the specified element name.
protected  java.lang.Enum createEnum(java.lang.String name, java.lang.String value)
           
protected  java.lang.String getEnumName(java.lang.Enum o)
           
protected  java.lang.String getEnumValue(java.lang.Enum o)
           
 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
clone, equals, finalize, 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

getEnumName

protected java.lang.String getEnumName(java.lang.Enum o)

getEnumValue

protected java.lang.String getEnumValue(java.lang.Enum o)

createEnum

protected java.lang.Enum createEnum(java.lang.String name,
                                    java.lang.String value)

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

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.

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

Copyright 1996-2010 (c) by the authors and contributors of the JHotDraw project.
Some rights reserved.