--- /dev/null
+package org.simantics.databoard.binding.impl;\r
+\r
+import org.simantics.databoard.binding.ByteBinding;\r
+import org.simantics.databoard.binding.error.BindingException;\r
+import org.simantics.databoard.primitives.UnsignedByte;\r
+import org.simantics.databoard.type.ByteType;\r
+\r
+/**\r
+ * Binding of {@link UnsignedByte} to byte type.\r
+ * \r
+ * @author Toni Kalajainen <toni.kalajainen@iki.fi>\r
+ */\r
+public abstract class UnsignedByteBinding extends ByteBinding {\r
+ \r
+ UnsignedByteBinding(ByteType type) {\r
+ super(type);\r
+ }\r
+ \r
+ public static class Immutable extends UnsignedByteBinding {\r
+ \r
+ public Immutable(ByteType type) {\r
+ super(type);\r
+ } \r
+ \r
+ @Override\r
+ public Object create(Number value) throws BindingException {\r
+ try {\r
+ return UnsignedByte.valueOf(value.longValue());\r
+ } catch (java.lang.IllegalArgumentException e) {\r
+ throw new BindingException( e );\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public Object create(String value) throws BindingException {\r
+ try {\r
+ return UnsignedByte.valueOf( Long.valueOf(value) );\r
+ } catch (java.lang.IllegalArgumentException e) {\r
+ throw new BindingException( e );\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void setValue(Object obj, Number value) throws BindingException {\r
+ throw new BindingException("UnsignedByte is immutable class");\r
+ }\r
+\r
+ @Override\r
+ public boolean isImmutable() {\r
+ return true;\r
+ }\r
+\r
+ @Override\r
+ public boolean isInstance(Object obj) {\r
+ return obj instanceof UnsignedByte.Immutable;\r
+ }\r
+\r
+ @Override\r
+ public Object create(byte value) throws BindingException {\r
+ try {\r
+ return UnsignedByte.valueOf(value);\r
+ } catch (java.lang.IllegalArgumentException e) {\r
+ throw new BindingException( e );\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public Object create(Byte value) throws BindingException {\r
+ try {\r
+ return UnsignedByte.valueOf(value);\r
+ } catch (java.lang.IllegalArgumentException e) {\r
+ throw new BindingException( e );\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void setValue(Object obj, byte value) throws BindingException {\r
+ throw new BindingException("UnsignedByte is immutable class");\r
+ }\r
+ \r
+ }\r
+ \r
+ public static class Mutable extends UnsignedByteBinding {\r
+ \r
+ public Mutable(ByteType type) {\r
+ super(type);\r
+ } \r
+\r
+ @Override\r
+ public Object create(Number value) throws BindingException {\r
+ return new UnsignedByte.Mutable(value.longValue());\r
+ }\r
+\r
+ @Override\r
+ public Object create(String value) throws BindingException {\r
+ return new UnsignedByte.Mutable(value);\r
+ }\r
+\r
+ @Override\r
+ public void setValue(Object obj, Number value) throws BindingException {\r
+ UnsignedByte.Mutable bb = (UnsignedByte.Mutable) obj;\r
+ bb.setBits(value.intValue());\r
+ }\r
+\r
+ @Override\r
+ public boolean isImmutable() {\r
+ return false;\r
+ }\r
+ \r
+ @Override\r
+ public boolean isInstance(Object obj) {\r
+ return obj instanceof UnsignedByte.Mutable;\r
+ }\r
+\r
+ @Override\r
+ public Object create(byte value) throws BindingException {\r
+ return new UnsignedByte.Mutable(value);\r
+ }\r
+\r
+ @Override\r
+ public Object create(Byte value) throws BindingException {\r
+ return new UnsignedByte.Mutable(value);\r
+ }\r
+\r
+ @Override\r
+ public void setValue(Object obj, byte value) throws BindingException {\r
+ UnsignedByte.Mutable bb = (UnsignedByte.Mutable) obj;\r
+ bb.setBits(value);\r
+ } \r
+ } \r
+\r
+ @Override\r
+ public Byte getValue(Object obj) throws BindingException {\r
+ return (byte) ((UnsignedByte)obj).toBits();\r
+ }\r
+\r
+ @Override\r
+ public byte getValue_(Object obj) throws BindingException {\r
+ return (byte) ((UnsignedByte)obj).toBits();\r
+ }\r
+ \r
+ @Override\r
+ public String toString(Object value) throws BindingException {\r
+ return value.toString();\r
+ }\r
+ \r
+}\r