]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/ReflectionComputationalValue.java
Variable optimizations for documents (Simupedia)
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / adapter / ReflectionComputationalValue.java
1 package org.simantics.db.layer0.adapter;
2
3 import org.simantics.db.ComputationalValue;
4 import org.simantics.db.ReadGraph;
5 import org.simantics.db.Resource;
6 import org.simantics.db.exception.DatabaseException;
7 import org.simantics.scl.reflection.ReflectionUtils;
8 import org.simantics.scl.reflection.ValueNotFoundException;
9
10 public class ReflectionComputationalValue implements ComputationalValue {
11
12         @SuppressWarnings("unchecked")
13         @Override
14         public <T> T getValue(ReadGraph graph, Resource resource) throws DatabaseException {
15                 
16                 try {
17                         return (T)ReflectionUtils.getValue(graph.getURI(resource)).getValue();
18                 } catch(ValueNotFoundException e) {
19                         throw new DatabaseException(e);
20                 } catch(ClassCastException e) {
21                         throw new DatabaseException(e);
22                 }
23                 
24         }
25
26 }