--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.databoard.binding.impl;
+
+import org.simantics.databoard.binding.IntegerBinding;\r
+import org.simantics.databoard.binding.error.BindingException;\r
+import org.simantics.databoard.binding.error.UnsupportedOperationException;\r
+import org.simantics.databoard.type.IntegerType;\r
+
+/**
+ * Binds Integer Type to java.lang.Integer
+ *
+ * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
+ */
+public class IntegerBindingDefault extends IntegerBinding {
+
+ public IntegerBindingDefault(IntegerType type) {
+ super( type );
+ }
+
+ public Object create(int value) {
+ return Integer.valueOf(value);
+ }
+
+ public Object create(Integer value) {
+ return value;
+ }
+
+ @Override
+ public Object create(Number value)
+ {
+ if (value.getClass()==Integer.class) return value;
+ return Integer.valueOf( value.intValue() );
+ }
+
+ @Override
+ public Object create(String value) throws BindingException {\r
+ try {
+ return Integer.parseInt(value);
+ } catch (java.lang.NumberFormatException e) {\r
+ throw new BindingException( e );\r
+ }\r
+ }
+
+ public Integer getValue(Object obj)
+ throws BindingException
+ {
+ if (obj.getClass()!=Integer.class)
+ throw new BindingException("Unexpected class "+obj.getClass().getSimpleName()+", Integer expected");
+ return ((Integer)obj);
+ }
+
+ public int getValue_(Object obj)
+ throws BindingException
+ {
+ if (obj.getClass()!=Integer.class)
+ throw new BindingException("Unexpected class "+obj.getClass().getSimpleName()+", Integer expected");
+ return ((Integer)obj);
+ }
+
+ @Override
+ public void setValue(Object obj, Number value) throws BindingException {
+ throw new UnsupportedOperationException("Cannot change the value of immutable java.lang.Integer");
+ }
+
+ public void setValue(Object obj, int value) throws BindingException {
+ throw new UnsupportedOperationException("Cannot change the value of immutable java.lang.Integer");
+ }
+
+ @Override
+ public boolean isInstance(Object obj) {
+ return obj instanceof Integer;
+ }
+
+ @Override
+ public boolean isImmutable() {
+ return true;
+ }
+ \r
+ @Override\r
+ public int compare(Object o1, Object o2)\r
+ {\r
+ int i1 = (Integer) o1;\r
+ int i2 = (Integer) o2;\r
+ return (i1<i2 ? -1 : (i1==i2 ? 0 : 1));\r
+ }\r
+ \r
+
+}
+