]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/CellValue.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.spreadsheet.graph / src / org / simantics / spreadsheet / graph / CellValue.java
1 package org.simantics.spreadsheet.graph;
2
3 import org.simantics.databoard.Bindings;
4 import org.simantics.databoard.binding.Binding;
5 import org.simantics.databoard.binding.error.BindingConstructionException;
6 import org.simantics.databoard.binding.mutable.Variant;
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.exception.DatabaseException;
9 import org.simantics.db.layer0.request.VariableRead;
10 import org.simantics.db.layer0.variable.Variable;
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
13
14 public class CellValue extends VariableRead<Object> {
15
16         private static final Logger LOGGER = LoggerFactory.getLogger(CellValue.class);
17
18         public CellValue(Variable variable) {
19                 super(variable);
20         }
21
22         @Override
23         public Object perform(ReadGraph graph) throws DatabaseException {
24                 
25                 Object value = variable.getValue(graph);
26                 String propertyName = variable.getName(graph);
27                 
28                 if("content".equals(propertyName)) {
29                         if(value == null) {
30                                 return Variant.ofInstance("Null content: " + variable.getURI(graph));
31                         }
32                         if(value instanceof Variable) {
33                                 Variable var = (Variable)value;
34                                 
35                                 Object value2 = var.getValue(graph);
36                                 if(value2 instanceof Variant) {
37                                 return value;
38                                 } else {
39                                         if(value2 == null) return Variant.ofInstance("Null value from " + var.getURI(graph));
40                                 try {
41                                         Binding binding = Bindings.getBinding( value2.getClass() );
42                                 return new Variant(binding, value2);
43                                 } catch (BindingConstructionException e) {
44                                         String msg = "Unsupported content " + value2 + " from " + var.getURI(graph);
45                                         LOGGER.error(msg, e);
46                                 return Variant.ofInstance(msg);
47                                 }
48                                 }
49                         }
50                         if(!(value instanceof Variant)) {
51                                 try {
52                                         Binding binding = Bindings.getBinding( value.getClass() );
53                                 return new Variant(binding, value);
54                                 } catch (BindingConstructionException e) {
55                                         String msg = "Unsupported content " + value + " at " + variable.getURI(graph);
56                                         LOGGER.error(msg, e);
57                                         return Variant.ofInstance(msg);
58                                 }
59                         }
60                 }
61
62                 return value;
63                 
64         }
65         
66 }