]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/binding/mutable/MutableByteBinding.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / binding / mutable / MutableByteBinding.java
1 /*******************************************************************************\r
2  *  Copyright (c) 2010 Association for Decentralized Information Management in\r
3  *  Industry THTH ry.\r
4  *  All rights reserved. This program and the accompanying materials\r
5  *  are made available under the terms of the Eclipse Public License v1.0\r
6  *  which accompanies this distribution, and is available at\r
7  *  http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  *  Contributors:\r
10  *      VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.databoard.binding.mutable;
13
14 import org.simantics.databoard.binding.ByteBinding;\r
15 import org.simantics.databoard.binding.error.BindingException;\r
16 import org.simantics.databoard.primitives.MutableByte;\r
17 import org.simantics.databoard.type.ByteType;\r
18
19 /**
20  * Binds java.lang.Byte to {@link MutableByte}
21  *
22  * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
23  */
24 public class MutableByteBinding extends ByteBinding {
25         
26         public MutableByteBinding(ByteType type) {
27                 super( type );
28         }
29
30         @Override
31         public Object create(byte value) {
32                 MutableByte result = new MutableByte();
33                 result.value = value;
34                 return result;
35         }
36
37         @Override
38         public Object create(Byte value) {
39                 MutableByte result = new MutableByte();
40                 result.value = value;
41                 return result;
42         }
43
44         @Override
45         public Object create(Number value) {
46                 MutableByte result = new MutableByte();
47                 result.value = value.byteValue();
48                 return result;
49         }
50
51         @Override
52         public Object create(String value) throws BindingException {\r
53                 try {\r
54                         byte x = Byte.valueOf( value );
55                         MutableByte result = new MutableByte();
56                         result.value = x;
57                         return result;
58                 } catch (java.lang.NumberFormatException e) {\r
59                         throw new BindingException( e );\r
60                 }\r
61         }
62
63         @Override
64         public byte getValue_(Object obj) throws BindingException {
65                 MutableByte result = (MutableByte) obj;
66                 return result.value;
67         }
68
69         @Override
70         public Byte getValue(Object obj) throws BindingException {
71                 MutableByte result = (MutableByte) obj;
72                 return result.value;
73         }
74
75         @Override
76         public boolean isInstance(Object obj) {
77                 return obj instanceof MutableByte;
78         }
79
80         @Override
81         public void setValue(Object obj, byte value) throws BindingException {
82                 MutableByte result = (MutableByte) obj;
83                 result.value = value;
84         }
85
86         @Override
87         public void setValue(Object obj, Number value) throws BindingException {
88                 MutableByte result = (MutableByte) obj;
89                 result.value = value.byteValue();
90         }
91         
92 }
93