--- /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.reflection;\r
+\r
+import org.simantics.databoard.binding.Binding;\r
+import org.simantics.databoard.binding.RecordBinding;\r
+import org.simantics.databoard.binding.error.BindingException;\r
+import org.simantics.databoard.type.Datatype;\r
+\r
+public class ConstantBinding extends RecordBinding {\r
+\r
+ Object value;\r
+ \r
+ public ConstantBinding(Datatype type, Object constantValue) {\r
+ this.type = type;\r
+ this.componentBindings = new Binding[0];\r
+ this.value = constantValue;\r
+ }\r
+\r
+ @Override\r
+ public Object create(Object... value) throws BindingException {\r
+ return this.value;\r
+ }\r
+\r
+ @Override\r
+ public Object getComponent(Object obj, int index) throws BindingException {\r
+ throw new BindingException();\r
+ }\r
+\r
+ @Override\r
+ public Object createPartial() throws BindingException {\r
+ return value;\r
+ }\r
+\r
+ @Override\r
+ public void setComponents(Object obj, Object... value) throws BindingException {\r
+// throw new BindingException();\r
+ }\r
+ \r
+ @Override\r
+ public void setComponent(Object obj, int index, Object value)\r
+ throws BindingException {\r
+// throw new BindingException();\r
+ }\r
+\r
+ @Override\r
+ public boolean isInstance(Object obj) {\r
+ return obj==value;\r
+ }\r
+ \r
+ @Override\r
+ public boolean isImmutable() {\r
+ return true;\r
+ }\r
+ \r
+ @Override\r
+ protected boolean baseEquals( Object obj ) {\r
+ return super.baseEquals( obj ) && value == ((ConstantBinding)obj).value;\r
+ }\r
+ \r
+ @Override\r
+ public int baseHashCode() {\r
+ return super.baseHashCode() + 7 * value.hashCode(); \r
+ } \r
+}\r
+\r