]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.plant3d/src/org/simantics/plant3d/geometry/ParameterRead.java
Remove dependencies on log4j
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / geometry / ParameterRead.java
1 package org.simantics.plant3d.geometry;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import org.simantics.databoard.Bindings;
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.Resource;
9 import org.simantics.db.common.request.ResourceRead;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.layer0.Layer0;
12 import org.simantics.plant3d.ontology.Plant3D;
13
14 public class ParameterRead extends ResourceRead<Map<String, Object>> {
15             
16             public ParameterRead(Resource resource) {
17             super(resource);
18         }
19             
20             @Override
21             public Map<String, Object> perform(ReadGraph graph) throws DatabaseException {
22                 Map<String,Object> parameters = new HashMap<>();
23                 Layer0 L0 = Layer0.getInstance(graph);
24                 Plant3D P3D = Plant3D.getInstance(graph);
25                 
26                 for (Resource assertion : graph.getObjects(resource, L0.Asserts)) {
27                 Resource rel = graph.getSingleObject(assertion, L0.HasPredicate);
28                 if (!rel.equals(P3D.hasParameter))
29                     continue;
30                 Resource param = graph.getSingleObject(assertion, L0.HasObject);
31                 String name = graph.getRelatedValue(param, L0.HasName, Bindings.STRING);
32                 Object value = graph.getRelatedValue(param, P3D.hasParameterValue);
33                 parameters.put(name, value);
34             }
35                 for (Resource param : graph.getObjects(resource, P3D.hasParameter)) {
36                     String name = graph.getRelatedValue(param, L0.HasName, Bindings.STRING);
37                     Object value = graph.getRelatedValue(param, P3D.hasParameterValue);
38                     parameters.put(name, value);
39                 }
40                 
41                 return parameters;
42             }
43
44         }