How Graph Handles Versions in XML

The following scenario illustrates how the graph treats the version in the XML:

Example: Restoring a graph from a previous version of the Graph bean

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()); }

Example: Applying XML to a current default graph

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()); }

Example: Applying all of the properties of a graph

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()); }