]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src-isv/tasks/class_binding.mediawiki
Merge "Improved line gaps" into release/1.43.1
[simantics/platform.git] / bundles / org.simantics.databoard / src-isv / tasks / class_binding.mediawiki
1 =Binding=
2 Information between databoard's datatype and Java classes are transferred using a ''[javadoc/org/simantics/databoard/binding/Binding.html Binding]''.
3 The type and hierarchy structure of binding is same as its repsective type and [javadoc/org/simantics/databoard/type/Datatype.html Datatype]. 
4 As datatype has tree-structure, so does a binding. 
5
6 {| border="1" cellpadding="3" cellspacing="0" align="center"
7 | '''#'''||'''Type'''||'''Description'''
8 |-
9 | -||[javadoc/org/simantics/databoard/binding/Binding.java|Binding]||Base class for all Bindings
10 |- 
11 | 0-5||[javadoc/org/simantics/databoard/binding/BooleanBinding.java|BooleanBinding],[javadoc/org/simantics/databoard/binding/ByteBinding.java|ByteBinding],[javadoc/org/simantics/databoard/binding/IntBinding.java|IntBinding],[javadoc/org/simantics/databoard/binding/LongBinding.java|LongBinding],[javadoc/org/simantics/databoard/binding/FloatBinding.java|FloatBinding],[javadoc/org/simantics/databoard/binding/DoubleBinding.java|DoubleBinding]||Primitive and numeric Bindings
12 |- 
13 | 6||[javadoc/org/simantics/databoard/binding/StringBinding.java|StringBinding]|| String
14 |- 
15 | 7||[javadoc/org/simantics/databoard/binding/RecordBinding.java|RecordBinding]|| Record 
16 |- 
17 | 8||[javadoc/org/simantics/databoard/binding/ArrayBinding.java|ArrayBinding]|| Array - an ordered sequence of elements of one value.
18 |- 
19 | 9||[javadoc/org/simantics/databoard/binding/MapBinding.java|MapBinding]|| Map - an ''ordered'' map of keys to values. 
20 |- 
21 | 11||[javadoc/org/simantics/databoard/binding/UnionBinding.java|UnionBinding]|| Union
22 |- 
23 | 10||[javadoc/org/simantics/databoard/binding/OptionalBinding.java|OptionalBinding]|| Optional value
24 |- 
25 | 12||[javadoc/org/simantics/databoard/binding/VariantBinding.java|VariantBinding]|| Variant value
26 |}
27
28 ==Built-in Bindings=
29
30 ==Class Binding==
31 To acquire a binding, the developer can use a utility that creates one using Java reflection functions. 
32     Binding binding = Bindings.getBinding( Double.class );
33
34 The Binding implementation is based on reflection or constructed from byte-code at runtime. Reflection is used if ASM library is not available. 
35
36 An automatic mechanism can create binding out of Java class, provided that certain rules are followed.
37
38 ''Record-like class:''
39     class Foo {
40         public String name;
41         public Object value;
42     }
43
44 ''Immutable class:''
45     class Foo {
46         private String name;
47         private Object value;
48         
49         public Foo(String name, Object value) {
50             this.name = name;
51             this.value = value;
52         }
53         
54         public String getName() {
55             return name;
56         }
57         
58         public Object getValue() {
59             return value;
60         }
61         
62     }
63
64 ''Bean-like classes:''
65     class Foo {
66         private String name;
67         private Object value;
68         
69         public void setName(String name) {
70             this.name = name;
71         }
72         
73         public void setValue(Object value) {
74             this.value = value;
75         }
76         
77         public String getName() {
78             return name;
79         }
80         
81         public Object getValue() {
82             return value;
83         }
84         
85     }
86
87 ===Annotations===
88 You can aid the Binding creation with annotations.
89
90  such as @Recursive, @Optional, @Arguments.
91
92 {| style="background-color: #e9e9e9; border: 1px solid #aaaaaa; "
93 | '''Class''' 
94 |-
95 |}
96
97
98 ==Hand-Written Binding==