]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ConstantValueStandardGraphPropertyVariable.java
Merge commit 'ad8333027322fda6b9a8a524c7a7e15a54c52f38'
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / variable / ConstantValueStandardGraphPropertyVariable.java
1 package org.simantics.db.layer0.variable;\r
2 \r
3 import org.simantics.databoard.Bindings;\r
4 import org.simantics.databoard.adapter.AdaptException;\r
5 import org.simantics.databoard.binding.Binding;\r
6 import org.simantics.databoard.type.Datatype;\r
7 import org.simantics.db.ReadGraph;\r
8 import org.simantics.db.Resource;\r
9 import org.simantics.db.WriteGraph;\r
10 import org.simantics.db.exception.DatabaseException;\r
11 \r
12 public class ConstantValueStandardGraphPropertyVariable extends StandardGraphPropertyVariable {\r
13 \r
14         final private Object value;\r
15         final private Datatype datatype;\r
16 \r
17         public ConstantValueStandardGraphPropertyVariable(ReadGraph graph, Variable parent, Resource parentResource, Resource predicate, Object value, Datatype datatype) throws DatabaseException {\r
18                 super(graph, parent, null, parentResource, predicate);\r
19                 this.value = value;\r
20                 this.datatype = datatype;\r
21         }\r
22         \r
23         @SuppressWarnings("unchecked")\r
24         @Override\r
25         public <T> T getValue(ReadGraph graph) throws DatabaseException {\r
26                 return (T)value;\r
27         }\r
28         \r
29         @SuppressWarnings("unchecked")\r
30         @Override\r
31         public <T> T getValue(ReadGraph graph, Binding binding) throws DatabaseException {\r
32                 try {\r
33                         return (T)Bindings.adapt(value, Bindings.getBinding(datatype), binding);\r
34                 } catch (AdaptException e) {\r
35                         throw new DatabaseException(e);\r
36                 }\r
37         }\r
38         \r
39         @Override\r
40         public Datatype getDatatype(ReadGraph graph) throws DatabaseException {\r
41                 return datatype;\r
42         }\r
43 \r
44         @Override\r
45         public void setValue(WriteGraph graph, Object value) throws DatabaseException {\r
46                 throw new DatabaseException("setValue is not supported.");\r
47         }\r
48         \r
49         @Override\r
50         public void setValue(WriteGraph graph, Object value, Binding binding) throws DatabaseException {\r
51                 throw new DatabaseException("setValue is not supported.");\r
52         }\r
53         \r
54 }\r