]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/binding/reflection/ConstantBinding.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / binding / reflection / ConstantBinding.java
1 /*******************************************************************************\r
2  *  Copyright (c) 2010 Association for Decentralized Information Management in\r
3  *  Industry THTH ry.\r
4  *  All rights reserved. This program and the accompanying materials\r
5  *  are made available under the terms of the Eclipse Public License v1.0\r
6  *  which accompanies this distribution, and is available at\r
7  *  http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  *  Contributors:\r
10  *      VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.databoard.binding.reflection;\r
13 \r
14 import org.simantics.databoard.binding.Binding;\r
15 import org.simantics.databoard.binding.RecordBinding;\r
16 import org.simantics.databoard.binding.error.BindingException;\r
17 import org.simantics.databoard.type.Datatype;\r
18 \r
19 public class ConstantBinding extends RecordBinding {\r
20 \r
21     Object value;\r
22     \r
23     public ConstantBinding(Datatype type, Object constantValue) {\r
24         this.type = type;\r
25         this.componentBindings = new Binding[0];\r
26         this.value = constantValue;\r
27     }\r
28 \r
29     @Override\r
30     public Object create(Object... value) throws BindingException {\r
31         return this.value;\r
32     }\r
33 \r
34     @Override\r
35     public Object getComponent(Object obj, int index) throws BindingException {\r
36         throw new BindingException();\r
37     }\r
38 \r
39     @Override\r
40     public Object createPartial() throws BindingException {\r
41         return value;\r
42     }\r
43 \r
44     @Override\r
45     public void setComponents(Object obj, Object... value) throws BindingException {\r
46 //        throw new BindingException();\r
47     }\r
48     \r
49     @Override\r
50     public void setComponent(Object obj, int index, Object value)\r
51                 throws BindingException {\r
52 //        throw new BindingException();\r
53     }\r
54 \r
55     @Override\r
56     public boolean isInstance(Object obj) {\r
57         return obj==value;\r
58     }\r
59     \r
60         @Override\r
61         public boolean isImmutable() {\r
62                 return true;\r
63         }\r
64         \r
65         @Override\r
66         protected boolean baseEquals( Object obj ) {\r
67             return super.baseEquals( obj ) && value == ((ConstantBinding)obj).value;\r
68         }\r
69         \r
70         @Override\r
71         public int baseHashCode() {\r
72             return super.baseHashCode() + 7 * value.hashCode(); \r
73         }    \r
74 }\r
75 \r