Class RXArchiver

java.lang.Object
com.inductiveautomation.rm.archiver.RXArchiver
Direct Known Subclasses:
RMArchiver

public class RXArchiver extends 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.

  • Constructor Details

    • RXArchiver

      public RXArchiver()
  • Method Details

    • getSourceURL

      public WebURL getSourceURL()
      Returns the WebURL of the currently loading archive.
    • getRootObject

      public Object getRootObject()
      Returns the object that the archiver should read "into".
    • setRootObject

      public void setRootObject(Object anObj)
      Sets the object that the archiver should read "into".
    • getClassLoader

      public ClassLoader getClassLoader()
      Returns the archiver class loader.
    • setClassLoader

      public void setClassLoader(ClassLoader aClassLoader)
      Sets the archiver class loader.
    • getRootXML

      public RXElement getRootXML()
      Returns the root xml.
    • getClassMap

      public Map getClassMap()
      Returns the class map.
    • createClassMap

      protected Map createClassMap()
      Creates the class map.
    • readObject

      public Object readObject(Object aSource)
      Returns a root object unarchived from a generic input source (a File, String path, InputStream, URL, byte[], etc.).
    • readObject

      public Object readObject(byte[] theBytes)
      Returns a root object unarchived from an RMByteSource.
    • readObject

      public 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(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 Object fromXML(RXElement anElement, Object anOwner)
      Returns an object unarchived from the given element.
    • fromXML

      public <T> T fromXML(RXElement anElement, Class<T> aClass, Object anOwner)
      Returns an object unarchived from the given element by instantiating the given class.
    • fromXML

      public Object fromXML(RXElement anElement, Object anObj, Object anOwner)
      Calls fromXML on given object.
    • toXML

      public RXElement toXML(Object anObj)
      Writes the given object to XML elements.
    • toXML

      public RXElement toXML(@Nonnull Object anObj, @Nullable Object anOwner)
      Writes the given object to XML elements.
    • getClass

      public Class getClass(String aName)
      Returns the class for a given element name.
    • getClass

      protected Class getClass(RXElement anElement)
      Returns the class for a given element.
    • newInstance

      protected Object newInstance(Class aClass)
      Returns a new instance of an object given a class.
    • newInstance

      protected Object newInstance(RXElement anElement)
      Returns a new instance of an object given an element.
    • getReference

      public int getReference(Object anObj)
      Returns a reference id for the given object (used in archival).
    • getReference

      public 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

      public Object getReference(String aName, RXElement anElement)
      Returns an object for a given reference (used in unarchival).
    • indexOf

      public int indexOf(RXElement anElement, Class aClass)
      Returns the index of the first child element with the given name.
    • indexOf

      public int indexOf(RXElement anElement, Class aClass, int startIndex)
      Returns the index of the first child element with the given name at or beyond the given index.
    • fromXMLList

      public List fromXMLList(RXElement 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.
    • copy

      public <T> T copy(T anObj)
      Returns a copy of the given object using archival.
    • getParent

      public Object getParent()
      Returns the top parent from the parent stack.
    • getParent

      public <T> T getParent(Class<T> aClass)
      Returns the first parent from the parent stack of given class.
    • pushParent

      protected void pushParent(Object anObj)
      Pushes a parent on the parent stack.
    • popParent

      protected Object popParent()
      Pops a parent from the parent stack.
    • getResources

      public 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(String aName)
      Returns an individual resource associated with this archiver, by name.
    • addResource

      public String addResource(byte[] bytes, 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.