+package org.simantics.databoard.binding.impl;\r
+\r
+import org.simantics.databoard.binding.IntegerBinding;\r
+import org.simantics.databoard.binding.error.BindingException;\r
+import org.simantics.databoard.primitives.UnsignedShort;\r
+import org.simantics.databoard.type.IntegerType;\r
+\r
+/**\r
+ * Binding of {@link UnsignedShort} to integer type.\r
+ * \r
+ * @author Toni Kalajainen <toni.kalajainen@iki.fi>\r
+ */\r
+public abstract class UnsignedShortBinding extends IntegerBinding {\r
+\r
+ UnsignedShortBinding(IntegerType type) {\r
+ super(type);\r
+ }\r
+\r
+ public static class Immutable extends UnsignedShortBinding {\r
+\r
+ public Immutable(IntegerType type) {\r
+ super(type);\r
+ }\r
+ \r
+ @Override\r
+ public Object create(int value) throws BindingException {\r
+ try {\r
+ return UnsignedShort.fromBits(value);\r
+ } catch (java.lang.IllegalArgumentException e) {\r
+ throw new BindingException( e );\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public Object create(Integer value) throws BindingException {\r
+ try {\r
+ return UnsignedShort.valueOf(value.intValue());\r
+ } catch (java.lang.IllegalArgumentException e) {\r
+ throw new BindingException( e );\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public Object create(Number value) throws BindingException {\r
+ try {\r
+ return UnsignedShort.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 UnsignedShort.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("UnsignedShort is immutable class");\r
+ }\r
+\r
+ @Override\r
+ public void setValue(Object obj, int value) throws BindingException {\r
+ throw new BindingException("UnsignedShort 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 UnsignedShort.Immutable;\r
+ }\r
+ \r
+ }\r
+\r
+ \r
+ public static class Mutable extends UnsignedShortBinding {\r
+\r
+ public Mutable(IntegerType type) {\r
+ super(type);\r
+ }\r
+ \r
+ @Override\r
+ public Object create(int value) throws BindingException {\r
+ try {\r
+ return new UnsignedShort.Mutable(value);\r
+ } catch (java.lang.IllegalArgumentException e) {\r
+ throw new BindingException( e );\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public Object create(Integer value) throws BindingException {\r
+ try {\r
+ return new UnsignedShort.Mutable(value);\r
+ } catch (java.lang.IllegalArgumentException e) {\r
+ throw new BindingException( e );\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public Object create(Number value) throws BindingException {\r
+ try {\r
+ return UnsignedShort.Mutable.fromBits(value.intValue());\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 new UnsignedShort.Mutable(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
+ UnsignedShort.Mutable mi = (UnsignedShort.Mutable) obj;\r
+ mi.setBits(value.intValue());\r
+ }\r
+\r
+ @Override\r
+ public void setValue(Object obj, int value) throws BindingException {\r
+ UnsignedShort.Mutable mi = (UnsignedShort.Mutable) obj;\r
+ mi.setBits(value);\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 UnsignedShort.Mutable;\r
+ } \r
+ \r
+ }\r
+ \r
+ @Override\r
+ public Integer getValue(Object obj) throws BindingException {\r
+ return ((UnsignedShort)obj).toBits();\r
+ }\r
+\r
+ @Override\r
+ public int getValue_(Object obj) throws BindingException {\r
+ return ((UnsignedShort)obj).toBits();\r
+ }\r
+\r
+ @Override\r
+ public String toString(Object value) throws BindingException {\r
+ return value.toString();\r
+ }\r
+\r
+\r
+}\r