Class RXArchiver
- java.lang.Object
-
- com.inductiveautomation.rm.archiver.RXArchiver
-
- Direct Known Subclasses:
RMArchiver
public class RXArchiver extends java.lang.Object
This class manages archival and unarchival to/from RXElements. For archival, objects simply implement the toXML() method to configure and return RXElements. RXArchiver's toXML() method manages the process, allowing for object references. For unarchival, classes register for particular element names. Then during RXArchiver.fromXML(), RXArchiver will call fromXML() on the classes for encountered tags to reconstruct the object graph.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RXArchiver.Resource
This inner class represents a named resource associated with an archiver.
-
Constructor Summary
Constructors Constructor Description RXArchiver()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
addResource(byte[] bytes, java.lang.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.protected java.util.Map
createClassMap()
Creates the class map.<T> T
fromXML(RXElement anElement, java.lang.Class<T> aClass, java.lang.Object anOwner)
Returns an object unarchived from the given element by instantiating the given class.java.lang.Object
fromXML(RXElement anElement, java.lang.Object anOwner)
Returns an object unarchived from the given element.java.lang.Object
fromXML(RXElement anElement, java.lang.Object anObj, java.lang.Object anOwner)
Calls fromXML on given object.java.util.List
fromXMLList(RXElement anElement, java.lang.String aName, java.lang.Class aClass, java.lang.Object anOwner)
Returns the list of objects of the given name and/or class (either can be null) unarchived from the given element.protected java.lang.Class
getClass(RXElement anElement)
Returns the class for a given element.java.lang.Class
getClass(java.lang.String aName)
Returns the class for a given element name.java.lang.ClassLoader
getClassLoader()
Returns the archiver class loader.java.util.Map
getClassMap()
Returns the class map.java.lang.Object
getParent()
Returns the top parent from the parent stack.<T> T
getParent(java.lang.Class<T> aClass)
Returns the first parent from the parent stack of given class.int
getReference(java.lang.Object anObj)
Returns a reference id for the given object (used in archival).int
getReference(java.lang.Object anObj, boolean add)
Returns a reference id for given object if in references list with option to add if absent (used in archival).java.lang.Object
getReference(java.lang.String aName, RXElement anElement)
Returns an object for a given reference (used in unarchival).RXArchiver.Resource
getResource(int anIndex)
Returns an individual resource associated with this archiver, by index.byte[]
getResource(java.lang.String aName)
Returns an individual resource associated with this archiver, by name.java.util.List<RXArchiver.Resource>
getResources()
Returns the list of optional resources associated with this archiver.void
getResources(RXElement anElement)
Reads resources from <resource> elements in given xml (top-level) element, converts from ASCII encoding and adds to archiver.java.lang.Object
getRootObject()
Returns the object that the archiver should read "into".RXElement
getRootXML()
Returns the root xml.WebURL
getSourceURL()
Returns the WebURL of the currently loading archive.int
indexOf(RXElement anElement, java.lang.Class aClass)
Returns the index of the first child element with the given name.int
indexOf(RXElement anElement, java.lang.Class aClass, int startIndex)
Returns the index of the first child element with the given name at or beyond the given index.protected java.lang.Object
newInstance(RXElement anElement)
Returns a new instance of an object given an element.protected java.lang.Object
newInstance(java.lang.Class aClass)
Returns a new instance of an object given a class.protected java.lang.Object
popParent()
Pops a parent from the parent stack.protected void
pushParent(java.lang.Object anObj)
Pushes a parent on the parent stack.java.lang.Object
readObject(byte[] theBytes)
Returns a root object unarchived from an RMByteSource.java.lang.Object
readObject(RXElement theXML)
Returns a root object unarchived from the XML source (a File, String path, InputStream, URL, byte[], etc.).java.lang.Object
readObject(java.lang.Object aSource)
Returns a root object unarchived from a generic input source (a File, String path, InputStream, URL, byte[], etc.).void
setClassLoader(java.lang.ClassLoader aClassLoader)
Sets the archiver class loader.void
setRootObject(java.lang.Object anObj)
Sets the object that the archiver should read "into".RXElement
toXML(java.lang.Object anObj)
Writes the given object to XML elements.RXElement
toXML(java.lang.Object anObj, java.lang.Object anOwner)
Writes the given object to XML elements.RXElement
writeObject(java.lang.Object anObj)
Returns an xml element for a given object.
-
-
-
Method Detail
-
getSourceURL
public WebURL getSourceURL()
Returns the WebURL of the currently loading archive.
-
getRootObject
public java.lang.Object getRootObject()
Returns the object that the archiver should read "into".
-
setRootObject
public void setRootObject(java.lang.Object anObj)
Sets the object that the archiver should read "into".
-
getClassLoader
public java.lang.ClassLoader getClassLoader()
Returns the archiver class loader.
-
setClassLoader
public void setClassLoader(java.lang.ClassLoader aClassLoader)
Sets the archiver class loader.
-
getRootXML
public RXElement getRootXML()
Returns the root xml.
-
getClassMap
public java.util.Map getClassMap()
Returns the class map.
-
createClassMap
protected java.util.Map createClassMap()
Creates the class map.
-
readObject
public java.lang.Object readObject(java.lang.Object aSource)
Returns a root object unarchived from a generic input source (a File, String path, InputStream, URL, byte[], etc.).
-
readObject
public java.lang.Object readObject(byte[] theBytes)
Returns a root object unarchived from an RMByteSource.
-
readObject
public java.lang.Object readObject(RXElement theXML)
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".
-
writeObject
public RXElement writeObject(java.lang.Object anObj)
Returns an xml element for a given object. This top level method encodes resources, in addition to doing the basic toXML stuff.
-
fromXML
public java.lang.Object fromXML(RXElement anElement, java.lang.Object anOwner)
Returns an object unarchived from the given element.
-
fromXML
public <T> T fromXML(RXElement anElement, java.lang.Class<T> aClass, java.lang.Object anOwner)
Returns an object unarchived from the given element by instantiating the given class.
-
fromXML
public java.lang.Object fromXML(RXElement anElement, java.lang.Object anObj, java.lang.Object anOwner)
Calls fromXML on given object.
-
toXML
public RXElement toXML(java.lang.Object anObj)
Writes the given object to XML elements.
-
toXML
public RXElement toXML(@Nonnull java.lang.Object anObj, @Nullable java.lang.Object anOwner)
Writes the given object to XML elements.
-
getClass
public java.lang.Class getClass(java.lang.String aName)
Returns the class for a given element name.
-
getClass
protected java.lang.Class getClass(RXElement anElement)
Returns the class for a given element.
-
newInstance
protected java.lang.Object newInstance(java.lang.Class aClass)
Returns a new instance of an object given a class.
-
newInstance
protected java.lang.Object newInstance(RXElement anElement)
Returns a new instance of an object given an element.
-
getReference
public int getReference(java.lang.Object anObj)
Returns a reference id for the given object (used in archival).
-
getReference
public int getReference(java.lang.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
public java.lang.Object getReference(java.lang.String aName, RXElement anElement)
Returns an object for a given reference (used in unarchival).
-
indexOf
public int indexOf(RXElement anElement, java.lang.Class aClass)
Returns the index of the first child element with the given name.
-
indexOf
public int indexOf(RXElement anElement, java.lang.Class aClass, int startIndex)
Returns the index of the first child element with the given name at or beyond the given index.
-
fromXMLList
public java.util.List fromXMLList(RXElement anElement, java.lang.String aName, java.lang.Class aClass, java.lang.Object anOwner)
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
public java.lang.Object getParent()
Returns the top parent from the parent stack.
-
getParent
public <T> T getParent(java.lang.Class<T> aClass)
Returns the first parent from the parent stack of given class.
-
pushParent
protected void pushParent(java.lang.Object anObj)
Pushes a parent on the parent stack.
-
popParent
protected java.lang.Object popParent()
Pops a parent from the parent stack.
-
getResources
public java.util.List<RXArchiver.Resource> getResources()
Returns the list of optional resources associated with this archiver.
-
getResource
public RXArchiver.Resource getResource(int anIndex)
Returns an individual resource associated with this archiver, by index.
-
getResource
public byte[] getResource(java.lang.String aName)
Returns an individual resource associated with this archiver, by name.
-
addResource
public java.lang.String addResource(byte[] bytes, java.lang.String aName)
Adds a byte array resource to this archiver (only if absent).
-
getResources
public void getResources(RXElement anElement)
Reads resources from <resource> elements in given xml (top-level) element, converts from ASCII encoding and adds to archiver.
-
-