Thes FilePersistence plug-in implements a file and a clipboard application tree stores based on XML.
With the help of the SimpleTextFileStore class a tree can be stored as files on disk, where each persistence unit is saved to a different file. The precise data format is described below.
The SystemClipboard class provides access to the system clipboard. It offers functionality to copy a node or a list of nodes to the clipboard. Nodes are copied as an XML text which is described below. Nodes from the clipboard can be pasted into a node of a list type or can be used to replace other nodes in the tree.
Data persistence format
When application trees are stored on disk using the SimpleTextFileStore persistent store they are stored in a series of text files. To describe the format of these files we will use the simple application tree shown in the figure below.
A binary node hierarchy with a persistent unit
The image shows an application tree called units that contains 8 nodes. During the store operation each node is assigned a universally unique id (uuid) of the form {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} where each 'x' is a hex digit. In the documentation below we will use just integers as ids to simplify the presentation. The ids are indicated in the corresponding circle. Nodes 0,2,4 and 6 are of type BinaryNode. A binary node always has a name an optionally has a left and right nodes. The name is just a string. Node 2 in the figure is a persistence unit. Persistence units are saved in separate files by the SimpleTextFileStore class.
There is a master file which belongs to the main persistence unit (the application tree) and a file for each other persistence unit if any. Here is an example of a master file:
units BinaryNode {0xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
name Text {1xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}. S_root
left persistencenewunit {2xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
right BinaryNode {4xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
name Text {5xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}. S_second
Each line contains exactly one node from the tree. Child nodes are indented by tabs. The line defining a node has the following elements:
- name - the name by which the parrent refers to this child. For list parents, this is just the index in the list. For composite parents, this is the child attribute name. E.g. the then branch of an if statement has the name 'thenBranch'. The name of the root node is the application name. Some programming constructs have names independent of their parents. For example a method appears at a specific index in the list of methods of its parent, but has a separate name (e.g. foo). This name is encoded as a child attribute of the method, the attribute is of type NameText.
- type - this is the type of the node.
- id - the uuid of the node.
- (optional) value - leaf nodes have a value and no children. Leaf nodes have a '.' immediately after the uuid which is followed by a single space and a value type specifier. Specifiers are 'S_', 'I_' or 'D_' for String, Integer and Double respectively. The value follows immediately after the specifier. Integers and Doubles are encoded in decimal notation, Doubles use a decimal dot. Strings are encoded in unicode. Back slash '\', carriage return '\r' and new line feed '\n' are escaped with a single back slash character. Strings last until the end of the line.
persistencenewunit is a special node which indicates that its content is defined in a different file. The type of this node is also defined in that file. The file name is the uuid of the file, inlcuding the braces. In the example above this filename is {2xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}. Here is the content of that file:
left BinaryNodePersistenceUnit {2xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
name Text {3xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}. S_first
left BinaryNode {6xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
name Text {7xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}. S_last
Its structure is identical to the one of the master file. top-level element which is absent. It is possible to have nested persistence unit nodes, in which case each new unit will be saved in its own file.
Format of the clipboard store
When using the ClipboardStore class provided by FilePersistence any copied nodes are stored as XML in the system clipboard. The format is equivalent to the one for persisting the tree on disk - we plan to unify the two in the future, they only diverge for historical reasons. Here is an example of two nodes being copied to clipboard:
<!DOCTYPE EnvisionFilePersistence>
<clipboard>
<BinaryNode name="0" partial="0">
<Text name="name" partial="0">S_first</Text>
</BinaryNode>
<BinaryNode name="1" partial="0">
<Text name="name" partial="0">S_second</Text>
</BinaryNode>
</clipboard>
The main element is clipboard and it contains one sub-element for each node that was copied. The structure of these sub-node elements is similar to the one discussed above, with the following differences:
- There is no node id attribute.
- The partial hint is always set to 0. Nodes loaded from the clipboard cannot be partially loaded.
- For direct children of clipboard the name attribute is simply an index that ranges from 0 to one less than the number of nodes copied to the clipboard.