]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.databoard/src-isv/doc/accessor.mediawiki
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src-isv / doc / accessor.mediawiki
index 6c0ea61f4d63819d47a0b630513e7fe32609f598..e3942e6aee95a25c0eb6f86d6108e0e0614a91ac 100644 (file)
-=Accessors=\r
-Say, you have several gigabytes of data in a file. The whole object doesn't need to be serialized at once. You can read and write the value partially using [[svn:foundation/databoard/trunk/org.simantics.databoard/src/org/simantics/databoard/accessor/|Accessor]] interface. The actual container can be a file, memory byte[]/ByteBuffer or a Java Object. The content is structured as tree using Databoard's type system. All but referable records are supported (=no recursion in accessors). \r
-\r
-'''[../javadoc/org/simantics/databoard/accessor.html|org.simantics.databoard.accessor] interfaces'''.\r
-{| style="background-color: #e9e9e9; border: 1px solid #aaaaaa; "\r
-| '''Class'''\r
-| '''Description'''\r
-|- style="background-color: #f9f9f9; " |\r
-| [../javadoc/org/simantics/databoard/accessor/Accessor.html|Accessor]\r
-| Base class for all data Accessors\r
-|- style="background-color: #f9f9f9; " |\r
-| [../javadoc/org/simantics/databoard/accessor/RecordAccessor.html|RecordAccessor]\r
-| Record \r
-|- style="background-color: #f9f9f9; " |\r
-| [../javadoc/org/simantics/databoard/accessor/ArrayAccessor.html|ArrayAccessor]\r
-| Array - an ordered sequence of elements of one value.\r
-|- style="background-color: #f9f9f9; " |\r
-| [../javadoc/org/simantics/databoard/accessor/MapAccessor.html|MapAccessor]\r
-| Map - an ''ordered'' map of keys to values. \r
-|- style="background-color: #f9f9f9; " |\r
-| [../javadoc/org/simantics/databoard/accessor/UnionAccessor.html|UnionAccessor]\r
-| Union\r
-|- style="background-color: #f9f9f9; " |\r
-| [../javadoc/org/simantics/databoard/accessor/BooleanAccessor.html|BooleanAccessor],[../javadoc/org/simantics/databoard/accessor/IntAccessor.html|IntAccessor],[../javadoc/org/simantics/databoard/accessor/LongAccessor.html|LongAccessor],[../javadoc/org/simantics/databoard/accessor/FloatAccessor.html|FloatAccessor],[../javadoc/org/simantics/databoard/accessor/DoubleAccessor.html|DoubleAccessor]\r
-| Primitive and numeric Accessors\r
-|- style="background-color: #f9f9f9; " |\r
-| [../javadoc/org/simantics/databoard/accessor/StringAccessor.html|StringAccessor]\r
-| String \r
-|- style="background-color: #f9f9f9; " |\r
-| [../javadoc/org/simantics/databoard/accessor/OptionalAccessor.html|OptionalAccessor]\r
-| Optional value\r
-|- style="background-color: #f9f9f9; " |\r
-| [../javadoc/org/simantics/databoard/accessor/VariantAccessor.html|VariantAccessor]\r
-| Variant value\r
-|}\r
-\r
-[../javadoc/org/simantics/databoard/Accessors.html|Accessors] and [../javadoc/org/simantics/databoard/Files.html|Files] are facade classes that contains utilities for instantiating and handling Accessors.\r
-\r
-<code>[../javadoc/org/simantics/databoard/accessor/binary/index.html|Binary Accessor]</code> is an access to a value in binary format (<tt>byte[]</tt> or <tt>ByteBuffer</tt>).\r
-\r
-'''Example:''' Binary accessor\r
-<pre class="code">\r
-Datatype type = Datatypes.getDatatype( Rectangle2D.Double.class );\r
-Binding binding = Bindings.getBinding( Rectangle2D.Double.class );\r
-Serializer s = Binding.getSerializer( binding );\r
-\r
-// Serialize rectangle\r
-Rectangle2D rect = new Rectangle2D.Double(0,0, 10, 10);\r
-byte[] data = s.serialize(rect);\r
-\r
-// Open accessor to byte data and modify first field in the byte data\r
-RecordAccessor ra = Accessors.getAccessor(data, type);\r
-ra.setFieldValue(0, Bindings.DOUBLE, 5.0);\r
-\r
-// Deserialize values from the byte data back to the rectangle object\r
-s.deserialize(data, rect);\r
-System.out.println(rect.getX());\r
-</pre>\r
-\r
-'''Example:''' File accessor, create\r
-<pre class="code">\r
-RecordType type = Datatypes.getDatatype( Rectangle2D.Double.class );\r
-// Create a new file and initialize it with rectangle type, and open file accessor\r
-FileRecordAccessor fa = Accessors.createFile( file, type );\r
-\r
-// Write the first field (x)\r
-fa.setFieldValue(0, Bindings.DOUBLE, 5.0);\r
-fa.close();\r
-</pre>\r
-\r
-'''Example:''' File accessor, open\r
-<pre class="code">\r
-// Open an accessor to an existing binary file\r
-FileVariantAccessor fa = Accessors.openAccessor(file);\r
-RecordAccessor ra = fa.getContentAccessor();\r
-\r
-// Read the first field (x)\r
-Double x = (Double) ra.getFieldValue(0, Bindings.DOUBLE);\r
-fa.close();\r
-</pre>\r
-\r
-'''Example:''' Java Accessor\r
-<pre class="code">\r
-Binding binding = Bindings.getBinding(Rectangle2D.Double.class);\r
-Rectangle2D rect = new Rectangle2D.Double(0,0, 10, 10);\r
-\r
-// Open accessor to rectangle\r
-RecordAccessor ra = Accessors.getAccessor(binding, rect);\r
-\r
-// Set rectangle's first field (x) to 5.0\r
-ra.setFieldValue(0, Bindings.DOUBLE, 5.0);\r
-System.out.println( rect.getX() );\r
-</pre>\r
-\r
-\r
-==Accessor Reference==\r
-Accessors can be opened to a sub-nodes with AccessorReference or by calling getAccessor. AccessorReference is a string of instances, either accessor type specific of LabelReferences. \r
-<pre class="code">\r
-    ChildReference ref = ChildReference.compile(\r
-      new NameReference("node"),\r
-      new ComponentReference()\r
-    );\r
-    Accessor child = accessor.getComponent( ref );\r
-\r
-    ChildReference ref = ChildReference.compile(\r
-       new LabelReference("node"),\r
-       new LabelReference("v")\r
-    );\r
-    Accessor child = accessor.getComponent( ref );\r
-\r
-    ChildReference ref = ChildReference.create("n-node/v");\r
-    Accessor child = accessor.getComponent( ref );\r
-\r
-    ChildReference ref = ChildReference.create("node/v");\r
-    Accessor child = accessor.getComponent( ref );\r
-\r
-    VariantAccessor va = recordAccessor.getFieldAccessor("node");\r
-    Accessor child = va.getValueAccessor();\r
-</pre>\r
-\r
-==Listening mechanism==\r
-Accessor offers a monitoring mechanism for the data model. \r
-There is an <code>[../javadoc/org/simantics/databoard/accessor/interestset/InterestSet.html|InterestSet]</code> that is a description of a sub-tree that is to be monitored of the data model.\r
-<code>[../javadoc/org/simantics/databoard/accessor/event/Event.html|Events]</code> are objects that spawned on changes to the data model. Each event object is annotated with [../javadoc/org/simantics/databoard/accessor/reference/index.html|reference path] that is in relation to the node where the listener was placed.\r
-\r
-Accessor Listeners use [EventThread Pattern] pattern.\r
+=Accessors=
+Say, you have several gigabytes of data in a file. The whole object doesn't need to be serialized at once. You can read and write the value partially using [[svn:foundation/databoard/trunk/org.simantics.databoard/src/org/simantics/databoard/accessor/|Accessor]] interface. The actual container can be a file, memory byte[]/ByteBuffer or a Java Object. The content is structured as tree using Databoard's type system. All but referable records are supported (=no recursion in accessors). 
+
+'''[../javadoc/org/simantics/databoard/accessor.html|org.simantics.databoard.accessor] interfaces'''.
+{| style="background-color: #e9e9e9; border: 1px solid #aaaaaa; "
+| '''Class'''
+| '''Description'''
+|- style="background-color: #f9f9f9; " |
+| [../javadoc/org/simantics/databoard/accessor/Accessor.html|Accessor]
+| Base class for all data Accessors
+|- style="background-color: #f9f9f9; " |
+| [../javadoc/org/simantics/databoard/accessor/RecordAccessor.html|RecordAccessor]
+| Record 
+|- style="background-color: #f9f9f9; " |
+| [../javadoc/org/simantics/databoard/accessor/ArrayAccessor.html|ArrayAccessor]
+| Array - an ordered sequence of elements of one value.
+|- style="background-color: #f9f9f9; " |
+| [../javadoc/org/simantics/databoard/accessor/MapAccessor.html|MapAccessor]
+| Map - an ''ordered'' map of keys to values. 
+|- style="background-color: #f9f9f9; " |
+| [../javadoc/org/simantics/databoard/accessor/UnionAccessor.html|UnionAccessor]
+| Union
+|- style="background-color: #f9f9f9; " |
+| [../javadoc/org/simantics/databoard/accessor/BooleanAccessor.html|BooleanAccessor],[../javadoc/org/simantics/databoard/accessor/IntAccessor.html|IntAccessor],[../javadoc/org/simantics/databoard/accessor/LongAccessor.html|LongAccessor],[../javadoc/org/simantics/databoard/accessor/FloatAccessor.html|FloatAccessor],[../javadoc/org/simantics/databoard/accessor/DoubleAccessor.html|DoubleAccessor]
+| Primitive and numeric Accessors
+|- style="background-color: #f9f9f9; " |
+| [../javadoc/org/simantics/databoard/accessor/StringAccessor.html|StringAccessor]
+| String 
+|- style="background-color: #f9f9f9; " |
+| [../javadoc/org/simantics/databoard/accessor/OptionalAccessor.html|OptionalAccessor]
+| Optional value
+|- style="background-color: #f9f9f9; " |
+| [../javadoc/org/simantics/databoard/accessor/VariantAccessor.html|VariantAccessor]
+| Variant value
+|}
+
+[../javadoc/org/simantics/databoard/Accessors.html|Accessors] and [../javadoc/org/simantics/databoard/Files.html|Files] are facade classes that contains utilities for instantiating and handling Accessors.
+
+<code>[../javadoc/org/simantics/databoard/accessor/binary/index.html|Binary Accessor]</code> is an access to a value in binary format (<tt>byte[]</tt> or <tt>ByteBuffer</tt>).
+
+'''Example:''' Binary accessor
+<pre class="code">
+Datatype type = Datatypes.getDatatype( Rectangle2D.Double.class );
+Binding binding = Bindings.getBinding( Rectangle2D.Double.class );
+Serializer s = Binding.getSerializer( binding );
+
+// Serialize rectangle
+Rectangle2D rect = new Rectangle2D.Double(0,0, 10, 10);
+byte[] data = s.serialize(rect);
+
+// Open accessor to byte data and modify first field in the byte data
+RecordAccessor ra = Accessors.getAccessor(data, type);
+ra.setFieldValue(0, Bindings.DOUBLE, 5.0);
+
+// Deserialize values from the byte data back to the rectangle object
+s.deserialize(data, rect);
+System.out.println(rect.getX());
+</pre>
+
+'''Example:''' File accessor, create
+<pre class="code">
+RecordType type = Datatypes.getDatatype( Rectangle2D.Double.class );
+// Create a new file and initialize it with rectangle type, and open file accessor
+FileRecordAccessor fa = Accessors.createFile( file, type );
+
+// Write the first field (x)
+fa.setFieldValue(0, Bindings.DOUBLE, 5.0);
+fa.close();
+</pre>
+
+'''Example:''' File accessor, open
+<pre class="code">
+// Open an accessor to an existing binary file
+FileVariantAccessor fa = Accessors.openAccessor(file);
+RecordAccessor ra = fa.getContentAccessor();
+
+// Read the first field (x)
+Double x = (Double) ra.getFieldValue(0, Bindings.DOUBLE);
+fa.close();
+</pre>
+
+'''Example:''' Java Accessor
+<pre class="code">
+Binding binding = Bindings.getBinding(Rectangle2D.Double.class);
+Rectangle2D rect = new Rectangle2D.Double(0,0, 10, 10);
+
+// Open accessor to rectangle
+RecordAccessor ra = Accessors.getAccessor(binding, rect);
+
+// Set rectangle's first field (x) to 5.0
+ra.setFieldValue(0, Bindings.DOUBLE, 5.0);
+System.out.println( rect.getX() );
+</pre>
+
+
+==Accessor Reference==
+Accessors can be opened to a sub-nodes with AccessorReference or by calling getAccessor. AccessorReference is a string of instances, either accessor type specific of LabelReferences. 
+<pre class="code">
+    ChildReference ref = ChildReference.compile(
+      new NameReference("node"),
+      new ComponentReference()
+    );
+    Accessor child = accessor.getComponent( ref );
+
+    ChildReference ref = ChildReference.compile(
+       new LabelReference("node"),
+       new LabelReference("v")
+    );
+    Accessor child = accessor.getComponent( ref );
+
+    ChildReference ref = ChildReference.create("n-node/v");
+    Accessor child = accessor.getComponent( ref );
+
+    ChildReference ref = ChildReference.create("node/v");
+    Accessor child = accessor.getComponent( ref );
+
+    VariantAccessor va = recordAccessor.getFieldAccessor("node");
+    Accessor child = va.getValueAccessor();
+</pre>
+
+==Listening mechanism==
+Accessor offers a monitoring mechanism for the data model. 
+There is an <code>[../javadoc/org/simantics/databoard/accessor/interestset/InterestSet.html|InterestSet]</code> that is a description of a sub-tree that is to be monitored of the data model.
+<code>[../javadoc/org/simantics/databoard/accessor/event/Event.html|Events]</code> are objects that spawned on changes to the data model. Each event object is annotated with [../javadoc/org/simantics/databoard/accessor/reference/index.html|reference path] that is in relation to the node where the listener was placed.
+
+Accessor Listeners use [EventThread Pattern] pattern.