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