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