Package snap.util
Class XMLArchiver
java.lang.Object
snap.util.XMLArchiver
- Direct Known Subclasses:
ViewArchiver
This class manages archival and unarchival to/from XMLElements.
For archival, objects simply implement the toXML() method to configure and return XMLElements. Archiver's toXML() method manages the process, allowing for object references.
For unarchival, classes register for particular element names. Then during Archiver.fromXML(), Archiver will call fromXML() on the classes for encountered tags to reconstruct the object graph.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
An interface for objects that are archivable.static class
This inner class represents a named resource associated with an archiver. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddResource
(byte[] bytes, String aName) Adds a byte array resource to this archiver (only if absent).<T> T
copy
(T anObj) Returns a copy of the given object using archival.Creates the class map.<T> T
fromXML
(XMLElement anElement, Class<T> aClass, Object anOwner) Returns an object unarchived from the given element by instantiating the given class.fromXML
(XMLElement anElement, Object anOwner) Returns an object unarchived from the given element.fromXML
(XMLElement anElement, Object anObj, Object anOwner) Calls fromXML on given object.fromXMLList
(XMLElement anElement, String aName, Class aClass, Object anOwner) Returns the list of objects of the given name and/or class (either can be null) unarchived from the given element.Returns the class for a given element name.protected Class<?>
getClassForXML
(XMLElement anElement) Returns the class for a given element.Returns the class map.getOwner()
Returns the owner.Returns the owner class.Returns the top parent from the parent stack.<T> T
Returns the first parent from the parent stack of given class.int
getReference
(Object anObj) Returns a reference id for the given object (used in archival).int
getReference
(Object anObj, boolean add) Returns a reference id for given object if in references list with option to add if absent (used in archival).getReference
(String aName, XMLElement anElement) Returns an object for a given reference (used in unarchival).getResource
(int anIndex) Returns an individual resource associated with this archiver, by index.byte[]
getResource
(String aName) Returns an individual resource associated with this archiver, by name.Returns the list of optional resources associated with this archiver.protected void
getResources
(XMLElement anElement) Reads resources fromelements in given xml (top-level) element, converts from ASCII encoding and adds to archiver. Returns the object that the archiver should read "into".Returns the root xml.Returns the WebURL of the currently loading archive.double
Returns the version of the document.int
indexOf
(XMLElement anElement, Class aClass) Returns the index of the first child element with the given name.int
indexOf
(XMLElement anElement, Class aClass, int startIndex) Returns the index of the first child element with the given name at or beyond the given index.boolean
Returns whether element should ignore case when asking for attributes/elements by name.protected Object
newInstance
(Class aClass) Returns a new instance of an object given a class.protected Object
Pops a parent from the parent stack.protected void
pushParent
(Object anObj) Pushes a parent on the parent stack.readFromXML
(XMLElement theXML) Returns a root object unarchived from the XML source (a File, String path, InputStream, URL, byte[], etc.).readFromXMLBytes
(byte[] theBytes) Returns a root object unarchived from an RMByteSource.readFromXMLSource
(Object aSource) Returns a root object unarchived from a generic input source (a File, String path, InputStream, URL, byte[], etc.).readFromXMLString
(String xmlString) Returns a root object unarchived from a generic XML source (File, String path, InputStream, URL, byte[], etc.).void
setIgnoreCase
(boolean aVal) Sets whether element should ignore case when asking for attributes/elements by name.void
Sets the owner.void
setRootObject
(Object anObj) Sets the object that the archiver should read "into".void
setSourceURL
(WebURL aURL) Sets the WebURL of the currently loading archive.void
setVersion
(double aVersion) Sets the version of the document.Writes the given object to XML elements.Writes the given object to XML elements.writeToXML
(Object anObj) Returns an xml element for a given object.byte[]
writeToXMLBytes
(Object anObj) Writes given object to XML and returns the XML bytes.
-
Constructor Details
-
XMLArchiver
public XMLArchiver()
-
-
Method Details
-
getSourceURL
Returns the WebURL of the currently loading archive. -
setSourceURL
Sets the WebURL of the currently loading archive. -
getOwner
Returns the owner. -
setOwner
Sets the owner. -
getOwnerClass
Returns the owner class. -
getRootObject
Returns the object that the archiver should read "into". -
setRootObject
Sets the object that the archiver should read "into". -
getVersion
public double getVersion()Returns the version of the document. -
setVersion
public void setVersion(double aVersion) Sets the version of the document. -
isIgnoreCase
public boolean isIgnoreCase()Returns whether element should ignore case when asking for attributes/elements by name. -
setIgnoreCase
public void setIgnoreCase(boolean aVal) Sets whether element should ignore case when asking for attributes/elements by name. -
getRootXML
Returns the root xml. -
getClassMap
Returns the class map. -
createClassMap
Creates the class map. -
readFromXMLSource
Returns a root object unarchived from a generic input source (a File, String path, InputStream, URL, byte[], etc.). -
readFromXMLString
Returns a root object unarchived from a generic XML source (File, String path, InputStream, URL, byte[], etc.). -
readFromXMLBytes
Returns a root object unarchived from an RMByteSource. -
readFromXML
Returns a root object unarchived from the XML source (a File, String path, InputStream, URL, byte[], etc.). You can also provide a root object to be read "into", and an owner that the object is being read "for". -
writeToXML
Returns an xml element for a given object. This top level method encodes resources, in addition to doing the basic toXML stuff. -
writeToXMLBytes
Writes given object to XML and returns the XML bytes. -
fromXML
Returns an object unarchived from the given element. -
fromXML
Returns an object unarchived from the given element by instantiating the given class. -
fromXML
Calls fromXML on given object. -
toXML
Writes the given object to XML elements. -
toXML
Writes the given object to XML elements. -
getClass
Returns the class for a given element name. -
getClassForXML
Returns the class for a given element. -
newInstance
Returns a new instance of an object given a class. -
getReference
Returns a reference id for the given object (used in archival). -
getReference
Returns a reference id for given object if in references list with option to add if absent (used in archival). -
getReference
Returns an object for a given reference (used in unarchival). -
indexOf
Returns the index of the first child element with the given name. -
indexOf
Returns the index of the first child element with the given name at or beyond the given index. -
fromXMLList
Returns the list of objects of the given name and/or class (either can be null) unarchived from the given element. -
copy
public <T> T copy(T anObj) Returns a copy of the given object using archival. -
getParent
Returns the top parent from the parent stack. -
getParent
Returns the first parent from the parent stack of given class. -
pushParent
Pushes a parent on the parent stack. -
popParent
Pops a parent from the parent stack. -
getResources
Returns the list of optional resources associated with this archiver. -
getResource
Returns an individual resource associated with this archiver, by index. -
getResource
Returns an individual resource associated with this archiver, by name. -
addResource
Adds a byte array resource to this archiver (only if absent). -
getResources
Reads resources fromelements in given xml (top-level) element, converts from ASCII encoding and adds to archiver.
-