Package com.ribs
Class RXArchiver
- java.lang.Object
-
- com.ribs.RXArchiver
-
- Direct Known Subclasses:
RibsArchiver
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.
Copyright (c) 2004 ReportMill Software, Inc. All Rights Reserved. Contact ReportMill
.
-
-
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()
Creates a new archiver.RXArchiver(java.util.Map classMap)
Creates an archiver with the given class map for unarchival class mapping.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addParent(java.lang.Object aParent, RXElement anElement)
Adds a parent to the parent list.java.lang.String
addResource(byte[] bytes, java.lang.String aName)
Adds a byte array resource to this archiver (only if absent).java.lang.Object
fromXML(RXElement anElement)
Returns an object unarchived from the given element.java.lang.Object
fromXML(RXElement anElement, java.lang.Class aClass)
Returns an object unarchived from the given element by instanciating the given class.java.lang.Object
fromXML(java.lang.Object aSource)
Returns a root object unarchived from the XML source (a File, String path, InputStream, URL, byte[], etc.).protected java.lang.Object
fromXML(java.lang.Object anObj, RXElement anElement)
Calls fromXML on given object.java.lang.Object
get(java.lang.Class aClass, RXElement anElement)
Returns the first object of the given class from the given element.java.lang.Object
get(java.lang.String aName, RXElement anElement)
Returns the named object unarchived from the given element.java.lang.Object
get(java.lang.String aName, RXElement anElement, java.lang.Object defaultValue)
Returns the named object unarchived from the given element (or, if missing, the given default value).java.util.List
getList(java.lang.Class aClass, RXElement anElement)
Returns the list of objects of the given class unarchived from the given element.java.util.List
getList(java.lang.String aName, RXElement anElement)
Returns the list of objects with the given name unarchived from given element.java.util.List
getList(java.lang.String aName, RXElement anElement, java.lang.Class aClass, java.util.List defaultList)
Returns the list of objects with the given name unarchived from given element instanciated from given class.java.util.List
getList(java.lang.String aName, RXElement anElement, java.util.List defaultList)
Returns the list of objects with the given name unarchived from given element (or, if missing, given default).java.lang.Object
getParent()
Returns parent object that initiated unarchival for current object (valid inside that object's fromXML method).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
getResources()
Returns the list of optional resources associated with this archiver.protected java.lang.Object
newInstance(RXElement anElement, java.lang.Class aClass)
Returns a new instance of an object given an element and suggested class (probably null).void
replace(java.lang.Object obj1, java.lang.Object obj2)
Called when a fromXML method swaps another object in to replace the one unarchiving.RXElement
toXML(java.lang.Object anObj)
Writes the given object to XML elements.
-
-
-
Method Detail
-
toXML
public RXElement toXML(java.lang.Object anObj)
Writes the given object to XML elements.
-
fromXML
public java.lang.Object fromXML(java.lang.Object aSource)
Returns a root object unarchived from the XML source (a File, String path, InputStream, URL, byte[], etc.).
-
fromXML
public java.lang.Object fromXML(RXElement anElement)
Returns an object unarchived from the given element.
-
fromXML
public java.lang.Object fromXML(RXElement anElement, java.lang.Class aClass)
Returns an object unarchived from the given element by instanciating the given class.
-
newInstance
protected java.lang.Object newInstance(RXElement anElement, java.lang.Class aClass)
Returns a new instance of an object given an element and suggested class (probably null).
-
fromXML
protected java.lang.Object fromXML(java.lang.Object anObj, RXElement anElement)
Calls fromXML on given object.
-
get
public java.lang.Object get(java.lang.String aName, RXElement anElement)
Returns the named object unarchived from the given element.
-
get
public java.lang.Object get(java.lang.String aName, RXElement anElement, java.lang.Object defaultValue)
Returns the named object unarchived from the given element (or, if missing, the given default value).
-
get
public java.lang.Object get(java.lang.Class aClass, RXElement anElement)
Returns the first object of the given class from the given element.
-
getList
public java.util.List getList(java.lang.String aName, RXElement anElement)
Returns the list of objects with the given name unarchived from given element.
-
getList
public java.util.List getList(java.lang.String aName, RXElement anElement, java.util.List defaultList)
Returns the list of objects with the given name unarchived from given element (or, if missing, given default).
-
getList
public java.util.List getList(java.lang.String aName, RXElement anElement, java.lang.Class aClass, java.util.List defaultList)
Returns the list of objects with the given name unarchived from given element instanciated from given class.
-
getList
public java.util.List getList(java.lang.Class aClass, RXElement anElement)
Returns the list of objects of the given class unarchived from the given element.
-
getParent
public java.lang.Object getParent()
Returns parent object that initiated unarchival for current object (valid inside that object's fromXML method).
-
addParent
public void addParent(java.lang.Object aParent, RXElement anElement)
Adds a parent to the parent list.
-
replace
public void replace(java.lang.Object obj1, java.lang.Object obj2)
Called when a fromXML method swaps another object in to replace the one unarchiving.
-
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).
-
getResources
public java.util.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(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).
-
-