Package com.ribs

Class RXArchiver

java.lang.Object
com.ribs.RXArchiver
Direct Known Subclasses:
RibsArchiver

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.

Copyright (c) 2004 ReportMill Software, Inc. All Rights Reserved. Contact ReportMill <info@reportmill.com>.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    This inner class represents a named resource associated with an archiver.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new archiver.
    RXArchiver(Map classMap)
    Creates an archiver with the given class map for unarchival class mapping.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addParent(Object aParent, RXElement anElement)
    Adds a parent to the parent list.
    addResource(byte[] bytes, String aName)
    Adds a byte array resource to this archiver (only if absent).
    fromXML(RXElement anElement)
    Returns an object unarchived from the given element.
    fromXML(RXElement anElement, Class aClass)
    Returns an object unarchived from the given element by instanciating the given class.
    fromXML(Object aSource)
    Returns a root object unarchived from the XML source (a File, String path, InputStream, URL, byte[], etc.).
    protected Object
    fromXML(Object anObj, RXElement anElement)
    Calls fromXML on given object.
    get(Class aClass, RXElement anElement)
    Returns the first object of the given class from the given element.
    get(String aName, RXElement anElement)
    Returns the named object unarchived from the given element.
    get(String aName, RXElement anElement, Object defaultValue)
    Returns the named object unarchived from the given element (or, if missing, the given default value).
    getList(Class aClass, RXElement anElement)
    Returns the list of objects of the given class unarchived from the given element.
    getList(String aName, RXElement anElement)
    Returns the list of objects with the given name unarchived from given element.
    getList(String aName, RXElement anElement, Class aClass, List defaultList)
    Returns the list of objects with the given name unarchived from given element instanciated from given class.
    getList(String aName, RXElement anElement, List defaultList)
    Returns the list of objects with the given name unarchived from given element (or, if missing, given default).
    Returns parent object that initiated unarchival for current object (valid inside that object's fromXML method).
    int
    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, RXElement 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[]
    Returns an individual resource associated with this archiver, by name.
    Returns the list of optional resources associated with this archiver.
    protected Object
    newInstance(RXElement anElement, Class aClass)
    Returns a new instance of an object given an element and suggested class (probably null).
    void
    replace(Object obj1, Object obj2)
    Called when a fromXML method swaps another object in to replace the one unarchiving.
    toXML(Object anObj)
    Writes the given object to XML elements.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • RXArchiver

      public RXArchiver()
      Creates a new archiver.
    • RXArchiver

      public RXArchiver(Map classMap)
      Creates an archiver with the given class map for unarchival class mapping.
  • Method Details

    • toXML

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

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

      public Object fromXML(RXElement anElement)
      Returns an object unarchived from the given element.
    • fromXML

      public Object fromXML(RXElement anElement, Class aClass)
      Returns an object unarchived from the given element by instanciating the given class.
    • newInstance

      protected Object newInstance(RXElement anElement, Class aClass)
      Returns a new instance of an object given an element and suggested class (probably null).
    • fromXML

      protected Object fromXML(Object anObj, RXElement anElement)
      Calls fromXML on given object.
    • get

      public Object get(String aName, RXElement anElement)
      Returns the named object unarchived from the given element.
    • get

      public Object get(String aName, RXElement anElement, Object defaultValue)
      Returns the named object unarchived from the given element (or, if missing, the given default value).
    • get

      public Object get(Class aClass, RXElement anElement)
      Returns the first object of the given class from the given element.
    • getList

      public List getList(String aName, RXElement anElement)
      Returns the list of objects with the given name unarchived from given element.
    • getList

      public List getList(String aName, RXElement anElement, List defaultList)
      Returns the list of objects with the given name unarchived from given element (or, if missing, given default).
    • getList

      public List getList(String aName, RXElement anElement, Class aClass, List defaultList)
      Returns the list of objects with the given name unarchived from given element instanciated from given class.
    • getList

      public List getList(Class aClass, RXElement anElement)
      Returns the list of objects of the given class unarchived from the given element.
    • getParent

      public Object getParent()
      Returns parent object that initiated unarchival for current object (valid inside that object's fromXML method).
    • addParent

      public void addParent(Object aParent, RXElement anElement)
      Adds a parent to the parent list.
    • replace

      public void replace(Object obj1, Object obj2)
      Called when a fromXML method swaps another object in to replace the one unarchiving.
    • 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).
    • getResources

      public List 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).