org.instantreality.InstantIO
Class StateKeeperXML

java.lang.Object
  extended by org.instantreality.InstantIO.StateKeeperXML

public final class StateKeeperXML
extends java.lang.Object

Writes the current state of namespaces as XML to an output stream or reads the state of namespaces as XML from an input stream.

You cannot instanciate the StateKeeperXML class, it just contains static methods that allow to save subtrees of the data flow graph in XML encoding to output streams, or to reconstruct subtrees by reading that XML code later on from input streams. This allows you to make your data flow graphs persistent, i.e. you can save the state of the graph to a file when you quit your application, and you can rebuild the graph from that file when you start your application again.

The following example demonstrates how to save the state of a Namespace object, i.e. all its subnamespaces, nodes, and routes, to a file called "macro.xml":

 Namespace namespace = ...;
 java.io.FileOutputStream fos = new java.io.FileOutputStream("macro.xml");
 StateKeeperXML.save(namespace, fos);
 fos.close();
 

Loading the state from "macro.xml" works like this:

 Namespace namespace = ...;
 java.io.FileInputStream fis = new java.io.FileInputStream("macro.xml");
 StateKeeperXML.load(namespace, fis);
 fis.close();
 
It is also possible to save and load the state of namespaces by using the web interface provided by the WebNode. The WebNode internally uses the StateKeeperXML class, i.e. states saved by the web interface can be loaded in your application via the StateKeeperXML class, and vice versa. Another alternative is the InlineNode. The InlineNode takes the URL of a file created by StateKeeperXML and loads the state into its own namespace when it is enabled. By doing so, you can partition large data flow graphs into smaller "macros" and integrate these macros into one single graph later on.

Author:
Patrick Dähne
See Also:
Namespace, WebNode, InlineNode

Method Summary
static void load(Namespace ns, java.io.InputStream is)
          Loads the state from an input stream.
static void load(Namespace ns, java.net.URL url)
          Loads the state from an URL.
static void save(Namespace namespace, java.io.OutputStream os)
          Saves the state to an output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

save

public static void save(Namespace namespace,
                        java.io.OutputStream os)
                 throws java.io.IOException
Saves the state to an output stream.

Writes the current state of a Namespace (i.e. all subnamespaces, nodes and routes) as XML to an output stream.

The following example demonstrates how to save the state of a Namespace object to a file called "macro.xml":

 Namespace namespace = ...;
 java.io.FileOutputStream fos = new java.io.FileOutputStream("macro.xml");
 StateKeeperXML.save(namespace, fos);
 fos.close();
 

Parameters:
namespace - The namespace whose current state should be written to the output stream.
os - The output stream you want to write the current state of the namespace to.
Throws:
java.io.IOException - when writing the state failed.
See Also:
load(Namespace, java.io.InputStream)

load

public static void load(Namespace ns,
                        java.io.InputStream is)
                 throws java.io.IOException
Loads the state from an input stream.

Clears a given namespace and reads its new state (i.e. all subnamespaces, nodes and routes) as XML from an input stream.

The following example demonstrates how to restore a saved state from a file "macro.xml":

 Namespace namespace = ...;
 java.io.FileInputStream fis = new java.io.FileInputStream("macro.xml");
 StateKeeperXML.load(namespace, fis);
 fis.close();
 

Parameters:
ns - The namespace that should be filled with the restored state
is - The input stream you want to read the namespace from.
Throws:
java.io.IOException - when reading the state failed.

load

public static void load(Namespace ns,
                        java.net.URL url)
                 throws java.io.IOException
Loads the state from an URL.

Clears a given namespace and reads its new state (i.e. all subnamespaces, nodes and routes) as XML from an URL.

The following example demonstrates how to restore a saved state from a file "macro.xml":

 Namespace namespace = ...;
 java.net.URL url = new java.net.URL("macro.xml");
 StateKeeperXML.load(namespace, url);
 fis.close();
 

Parameters:
ns - The namespace that should be filled with the restored state
url - The URL you want to read the namespace from.
Throws:
java.io.IOException - when reading the state failed.