Class RXArchiver
- java.lang.Object
-
- com.inductiveautomation.rm.archiver.RXArchiver
-
- Direct Known Subclasses:
RMArchiver
public class RXArchiver extends java.lang.ObjectThis 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 classRXArchiver.ResourceThis 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.StringaddResource(byte[] bytes, java.lang.String aName)Adds a byte array resource to this archiver (only if absent).<T> Tcopy(T anObj)Returns a copy of the given object using archival.protected java.util.MapcreateClassMap()Creates the class map.<T> TfromXML(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.ObjectfromXML(RXElement anElement, java.lang.Object anOwner)Returns an object unarchived from the given element.java.lang.ObjectfromXML(RXElement anElement, java.lang.Object anObj, java.lang.Object anOwner)Calls fromXML on given object.java.util.ListfromXMLList(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.ClassgetClass(RXElement anElement)Returns the class for a given element.java.lang.ClassgetClass(java.lang.String aName)Returns the class for a given element name.java.lang.ClassLoadergetClassLoader()Returns the archiver class loader.java.util.MapgetClassMap()Returns the class map.java.lang.ObjectgetParent()Returns the top parent from the parent stack.<T> TgetParent(java.lang.Class<T> aClass)Returns the first parent from the parent stack of given class.intgetReference(java.lang.Object anObj)Returns a reference id for the given object (used in archival).intgetReference(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.ObjectgetReference(java.lang.String aName, RXElement anElement)Returns an object for a given reference (used in unarchival).RXArchiver.ResourcegetResource(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.voidgetResources(RXElement anElement)Reads resources from <resource> elements in given xml (top-level) element, converts from ASCII encoding and adds to archiver.java.lang.ObjectgetRootObject()Returns the object that the archiver should read "into".RXElementgetRootXML()Returns the root xml.WebURLgetSourceURL()Returns the WebURL of the currently loading archive.intindexOf(RXElement anElement, java.lang.Class aClass)Returns the index of the first child element with the given name.intindexOf(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.ObjectnewInstance(RXElement anElement)Returns a new instance of an object given an element.protected java.lang.ObjectnewInstance(java.lang.Class aClass)Returns a new instance of an object given a class.protected java.lang.ObjectpopParent()Pops a parent from the parent stack.protected voidpushParent(java.lang.Object anObj)Pushes a parent on the parent stack.java.lang.ObjectreadObject(byte[] theBytes)Returns a root object unarchived from an RMByteSource.java.lang.ObjectreadObject(RXElement theXML)Returns a root object unarchived from the XML source (a File, String path, InputStream, URL, byte[], etc.).java.lang.ObjectreadObject(java.lang.Object aSource)Returns a root object unarchived from a generic input source (a File, String path, InputStream, URL, byte[], etc.).voidsetClassLoader(java.lang.ClassLoader aClassLoader)Sets the archiver class loader.voidsetRootObject(java.lang.Object anObj)Sets the object that the archiver should read "into".RXElementtoXML(java.lang.Object anObj)Writes the given object to XML elements.RXElementtoXML(java.lang.Object anObj, java.lang.Object anOwner)Writes the given object to XML elements.RXElementwriteObject(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.
-
-