Class JavaPrimitivesDOMFactory
- java.lang.Object
-
- org.jhotdraw.xml.JavaPrimitivesDOMFactory
-
- All Implemented Interfaces:
- DOMFactory
- Direct Known Subclasses:
- DefaultDOMFactory
public class JavaPrimitivesDOMFactory extends java.lang.Object implements DOMFactory
JavaPrimitivesDOMFactorycan be used to serialize Java primitive objects andDOMStorableobjects.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!)
You can add support for additional primitive types by overriding the methods
readandwrite.In addition to the primitive types, this factory can store and read
DOMStorableobjects. No mapping forDOMStorableclass names is performed. For example, if aDOMStorableobject has the class namecom.example.MyClass, then the DOM element has the same name, that is:<com.example.MyClass>.Since no mapping between DOM element names and
DOMStorableclass 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,getEnumNameandgetEnumValue.
-
-
Constructor Summary
Constructors Constructor and Description JavaPrimitivesDOMFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description java.lang.Objectcreate(java.lang.String name)Creates an object from the specified element name.java.lang.StringgetName(java.lang.Object o)Returns the element name for the specified object.java.lang.Objectread(DOMInput in)Reads the specified object fromDOMInput.voidwrite(DOMOutput out, java.lang.Object o)Writes the specified object to DOMOutput.
-
-
-
Method Detail
-
getName
public java.lang.String getName(java.lang.Object o)
Description copied from interface:DOMFactoryReturns the element name for the specified object.- Specified by:
getNamein interfaceDOMFactory
-
create
public java.lang.Object create(java.lang.String name)
Description copied from interface:DOMFactoryCreates an object from the specified element name.- Specified by:
createin interfaceDOMFactory
-
write
public void write(DOMOutput out, java.lang.Object o) throws java.io.IOException
Description copied from interface:DOMFactoryWrites the specified object to DOMOutput.This method is only ever called from DOMOutput. You should never call this method directly.
- Specified by:
writein interfaceDOMFactoryo- 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:DOMFactoryReads the specified object fromDOMInput.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
DOMStorablethenDOMInputinvokes its read method.- Specified by:
readin interfaceDOMFactory- Parameters:
in- TheDOMInputobject which creates the object from an element in a DOM.- Throws:
java.io.IOException
-
-
DataMelt 3.0 © DataMelt by jWork.ORG