1 package org.simantics.modeling;
3 import java.util.HashMap;
4 import java.util.HashSet;
7 import org.simantics.databoard.Bindings;
8 import org.simantics.db.ReadGraph;
9 import org.simantics.db.Resource;
10 import org.simantics.db.common.request.ResourceRead;
11 import org.simantics.db.exception.DatabaseException;
12 import org.simantics.db.layer0.request.PropertyInfo;
13 import org.simantics.db.layer0.request.UnescapedPropertyMapOfResource;
14 import org.simantics.layer0.Layer0;
15 import org.simantics.structural2.ConnectionImpl;
16 import org.simantics.structural2.Functions.StructuralChildMapOfResource;
17 import org.simantics.structural2.queries.ConnectionPointMapOfResource;
19 public class ImmutableComponentVariableContentRequest extends ResourceRead<ImmutableComponentVariableContent> {
21 protected ImmutableComponentVariableContentRequest(Resource resource) {
26 public ImmutableComponentVariableContent perform(ReadGraph graph) throws DatabaseException {
28 Layer0 L0 = Layer0.getInstance(graph);
29 String name = graph.getRelatedValue(resource, L0.HasName, Bindings.STRING);
30 ImmutableComponentVariableContent result = new ImmutableComponentVariableContent(resource, name);
32 Map<String,PropertyInfo> pis = graph.syncRequest(new UnescapedPropertyMapOfResource(resource));
34 for(Map.Entry<String, PropertyInfo> e : pis.entrySet()) {
35 PropertyInfo pi = e.getValue();
36 if(pi.isHasProperty) {
37 ImmutableComponentPropertyContent pc = graph.syncRequest(new ImmutableComponentPropertyContentRequest(resource, pi));
39 if(result.properties == null) result.properties = new HashMap<>();
40 result.properties.put(pc.pi.name, pc);
45 Map<String,PropertyInfo> cps = graph.syncRequest(new ConnectionPointMapOfResource(graph, resource));
46 for(Map.Entry<String, PropertyInfo> e : cps.entrySet()) {
47 PropertyInfo pi = e.getValue();
48 Resource conn = graph.getPossibleObject(resource, pi.predicate);
50 if(result.properties == null) result.properties = new HashMap<>();
51 result.properties.put(pi.name, new ImmutableComponentPropertyContent(pi, conn, new ConnectionImpl(pi.predicate), null));
55 HashSet<Resource> childSet = null;
56 for(Resource child : graph.syncRequest(new StructuralChildMapOfResource(resource)).values()) {
58 childSet = new HashSet<>();
62 if(childSet != null) {
63 result.children = new HashMap<>();
64 for(Resource child : childSet) {
65 ImmutableComponentVariableContent content = graph.syncRequest(new ImmutableComponentVariableContentRequest(child));
66 result.children.put(content.name, content);