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