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.
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.
| Constructor and Description |
|---|
JavaPrimitivesDOMFactory() |
| Modifier and Type | Method and Description |
|---|---|
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.
|
public java.lang.String getName(java.lang.Object o)
DOMFactorygetName in interface DOMFactorypublic java.lang.Object create(java.lang.String name)
DOMFactorycreate in interface DOMFactoryprotected java.lang.String getEnumName(java.lang.Enum o)
protected java.lang.String getEnumValue(java.lang.Enum o)
protected java.lang.Enum createEnum(java.lang.String name,
java.lang.String value)
public void write(DOMOutput out, java.lang.Object o) throws java.io.IOException
DOMFactoryThis method is only ever called from DOMOutput. You should never call this method directly.
write in interface DOMFactoryo - The object to be written.java.io.IOExceptionpublic java.lang.Object read(DOMInput in) throws java.io.IOException
DOMFactoryDOMInput.
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.
read in interface DOMFactoryin - The DOMInput object which creates the object from an element
in a DOM.java.io.IOException