1 package org.simantics.db.common.request;
3 import org.simantics.db.ReadGraph;
4 import org.simantics.db.Resource;
5 import org.simantics.db.common.utils.Functions;
6 import org.simantics.db.exception.DatabaseException;
7 import org.simantics.db.exception.RuntimeDatabaseException;
8 import org.simantics.layer0.Layer0;
9 import org.simantics.scl.reflection.ReflectionUtils;
10 import org.simantics.scl.reflection.ValueNotFoundException;
11 import org.simantics.scl.runtime.function.FunctionImpl3;
14 * Adapts a resource to (SCL) value.
15 * @author Hannu Niemistö
17 public class AdaptValue extends ResourceRead<Object> {
19 public AdaptValue(Resource resource) {
23 private static final FunctionImpl3<ReadGraph,Resource,Object,Object> functionApplication = new FunctionImpl3<ReadGraph,Resource,Object,Object>() {
26 public Object apply(ReadGraph graph, Resource resource, Object context) {
28 return Functions.exec(graph, resource, graph, resource, context);
29 } catch (DatabaseException e) {
30 throw new RuntimeDatabaseException(e);
37 public Object perform(ReadGraph graph) throws DatabaseException {
38 String uri = graph.getURI(resource);
40 if(Layer0.URIs.Functions_functionApplication.equals(uri)) return functionApplication;
41 return ReflectionUtils.getValue(uri).getValue();
42 } catch (ValueNotFoundException e) {
43 throw new DatabaseException("Couldn't adapt the value " + uri, e);