The following scenario illustrates how the graph treats the version in the XML:
You save a graph in XML in version 1.5.0.1 of the Graph bean. The XML file is called
myGraph1501.xml
. You save only the properties that are different from the default
values.
For version 2.1.0.1 of the Graph bean, some default property values change. Note that this is not the plan. The versioning mechanism is just prepared for such changes.
You read myGraph1501.xml
into a graph in version 2.1.0.1, passing
true
in the reset
parameter.
The graph sets the properties to the default values for version 1.5.0.1 and
then applies the property settings from myGraph1501.xml
to the graph. The graph is
then identical to the graph from which the XML was saved.
The following example shows how to restore an XML graph that was saved in an earlier version of the Graph bean. The XML was saved in an output stream, and only the properties that differed from the default values were saved. This code reads the input stream from the current folder, sets the properties of the graph and its components to the defaults for the version that produced the input stream, and then applies the XML to the graph.
Graph myGraph = new Graph(); FileInputStream graphXMLStream = new FileInputStream("myGraph.xml"); try { //apply XML, but first reset to default values for saving version myGraph.setXML(graphXMLStream, true); } catch (BIIOException e) { system.out.println("Problem reading XML file. Is it really there?"); system.out.println(e.toString()); } catch (BIParseException e) { system.out.println("The XML has a syntax error or is not valid."); system.out.println(e.toString()); } catch (BISAXException e) { system.out.println("The parser needs fixing."); system.out.println(e.toString()); }
In the following example, XML from a graph that was saved in the previous version of the Graph bean is applied to the current default graph. The XML was saved in an output stream, and only the properties that differed from the default values were saved. This code reads the input stream from the current folder and applies it to a default graph.
Graph myGraph = new Graph(); FileInputStream graphXMLStream = new FileInputStream("myGraph.xml"); //property change -- represents any number of changes to graph myGraph.setGraphType(SCATTER); //before applying XML, reset to the default property values for this version myGraph.resetToDefault(); //now apply the XML try { //apply XML to current settings (this version's defaults) myGraph.setXML(graphXMLStream, false); } catch (BIIOException e) { system.out.println("Problem reading XML file. Is it really there?"); system.out.println(e.toString()); } catch (BIParseException e) { system.out.println("The XML has a syntax error or is not valid."); system.out.println(e.toString()); } catch (BISAXException e) { system.out.println("The parser needs fixing."); system.out.println(e.toString()); }
In the following example, all the property values were saved in the XML. This code reads the input stream from the current folder. It does not matter which version of the Graph bean produced the XML or which version reads the XML.
Graph myGraph = new Graph(); FileInputStream graphXMLStream = new FileInputStream("myGraph.xml"); try { //apply XML; do not reset to defaults, since all property values are //being taken from the XML myGraph.setXML(graphXMLStream, false); } catch (BIIOException e) { system.out.println("Problem reading XML file. Is it really there?"); system.out.println(e.toString()); } catch (BIParseException e) { system.out.println("The XML has a syntax error or is not valid."); system.out.println(e.toString()); } catch (BISAXException e) { system.out.println("The parser needs fixing."); system.out.println(e.toString()); }