]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.common/src/org/simantics/db/common/request/AdaptValue.java
Utilize SVGNode's transformation when generating SVG image
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / request / AdaptValue.java
1 package org.simantics.db.common.request;
2
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;
12
13 /**
14  * Adapts a resource to (SCL) value.
15  * @author Hannu Niemistö
16  */
17 public class AdaptValue extends ResourceRead<Object> {
18     
19     public AdaptValue(Resource resource) {
20         super(resource);
21     }
22
23     private static final FunctionImpl3<ReadGraph,Resource,Object,Object> functionApplication = new FunctionImpl3<ReadGraph,Resource,Object,Object>() {
24
25                 @Override
26                 public Object apply(ReadGraph graph, Resource resource, Object context) {
27                         try {
28                                 return Functions.exec(graph, resource, graph, resource, context);
29                         } catch (DatabaseException e) {
30                                 throw new RuntimeDatabaseException(e);
31                         }
32                 }
33
34         };
35     
36     @Override
37     public Object perform(ReadGraph graph) throws DatabaseException {
38         String uri = graph.getURI(resource);        
39         try {
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);
44         }
45     }
46
47 }