1 package org.simantics.databoard.binding.impl;
\r
3 import org.simantics.databoard.binding.ByteBinding;
\r
4 import org.simantics.databoard.binding.error.BindingException;
\r
5 import org.simantics.databoard.primitives.UnsignedByte;
\r
6 import org.simantics.databoard.type.ByteType;
\r
9 * Binding of {@link UnsignedByte} to byte type.
\r
11 * @author Toni Kalajainen <toni.kalajainen@iki.fi>
\r
13 public abstract class UnsignedByteBinding extends ByteBinding {
\r
15 UnsignedByteBinding(ByteType type) {
\r
19 public static class Immutable extends UnsignedByteBinding {
\r
21 public Immutable(ByteType type) {
\r
26 public Object create(Number value) throws BindingException {
\r
28 return UnsignedByte.valueOf(value.longValue());
\r
29 } catch (java.lang.IllegalArgumentException e) {
\r
30 throw new BindingException( e );
\r
35 public Object create(String value) throws BindingException {
\r
37 return UnsignedByte.valueOf( Long.valueOf(value) );
\r
38 } catch (java.lang.IllegalArgumentException e) {
\r
39 throw new BindingException( e );
\r
44 public void setValue(Object obj, Number value) throws BindingException {
\r
45 throw new BindingException("UnsignedByte is immutable class");
\r
49 public boolean isImmutable() {
\r
54 public boolean isInstance(Object obj) {
\r
55 return obj instanceof UnsignedByte.Immutable;
\r
59 public Object create(byte value) throws BindingException {
\r
61 return UnsignedByte.valueOf(value);
\r
62 } catch (java.lang.IllegalArgumentException e) {
\r
63 throw new BindingException( e );
\r
68 public Object create(Byte value) throws BindingException {
\r
70 return UnsignedByte.valueOf(value);
\r
71 } catch (java.lang.IllegalArgumentException e) {
\r
72 throw new BindingException( e );
\r
77 public void setValue(Object obj, byte value) throws BindingException {
\r
78 throw new BindingException("UnsignedByte is immutable class");
\r
83 public static class Mutable extends UnsignedByteBinding {
\r
85 public Mutable(ByteType type) {
\r
90 public Object create(Number value) throws BindingException {
\r
91 return new UnsignedByte.Mutable(value.longValue());
\r
95 public Object create(String value) throws BindingException {
\r
96 return new UnsignedByte.Mutable(value);
\r
100 public void setValue(Object obj, Number value) throws BindingException {
\r
101 UnsignedByte.Mutable bb = (UnsignedByte.Mutable) obj;
\r
102 bb.setBits(value.intValue());
\r
106 public boolean isImmutable() {
\r
111 public boolean isInstance(Object obj) {
\r
112 return obj instanceof UnsignedByte.Mutable;
\r
116 public Object create(byte value) throws BindingException {
\r
117 return new UnsignedByte.Mutable(value);
\r
121 public Object create(Byte value) throws BindingException {
\r
122 return new UnsignedByte.Mutable(value);
\r
126 public void setValue(Object obj, byte value) throws BindingException {
\r
127 UnsignedByte.Mutable bb = (UnsignedByte.Mutable) obj;
\r
133 public Byte getValue(Object obj) throws BindingException {
\r
134 return (byte) ((UnsignedByte)obj).toBits();
\r
138 public byte getValue_(Object obj) throws BindingException {
\r
139 return (byte) ((UnsignedByte)obj).toBits();
\r
143 public String toString(Object value) throws BindingException {
\r
144 return value.toString();
\r