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.structural.stubs.StructuralResource2;
16 import org.simantics.structural2.ConnectionImpl;
17 import org.simantics.structural2.Functions.StructuralChildMapOfResource;
18 import org.simantics.structural2.queries.ConnectionPointMapOfResource;
20 public class ImmutableComponentVariableContentRequest extends ResourceRead<ImmutableComponentVariableContent> {
22 protected ImmutableComponentVariableContentRequest(Resource resource) {
27 public ImmutableComponentVariableContent perform(ReadGraph graph) throws DatabaseException {
29 Layer0 L0 = Layer0.getInstance(graph);
30 String name = graph.getRelatedValue(resource, L0.HasName, Bindings.STRING);
31 ImmutableComponentVariableContent result = new ImmutableComponentVariableContent(resource, name);
33 StructuralResource2 STR = StructuralResource2.getInstance(graph);
34 Resource componentType = graph.getPossibleType(resource, STR.Component);
35 if(componentType != null)
36 result.procedural = graph.isInstanceOf(componentType, STR.ProceduralComponentType);
38 Map<String,PropertyInfo> pis = graph.syncRequest(new UnescapedPropertyMapOfResource(resource));
40 for(Map.Entry<String, PropertyInfo> e : pis.entrySet()) {
41 PropertyInfo pi = e.getValue();
42 if(pi.isHasProperty) {
43 ImmutableComponentPropertyContent pc = graph.syncRequest(new ImmutableComponentPropertyContentRequest(resource, pi));
45 if(result.properties == null) result.properties = new HashMap<>();
46 result.properties.put(pc.pi.name, pc);
51 Map<String,PropertyInfo> cps = graph.syncRequest(new ConnectionPointMapOfResource(graph, resource));
52 for(Map.Entry<String, PropertyInfo> e : cps.entrySet()) {
53 PropertyInfo pi = e.getValue();
54 Resource conn = graph.getPossibleObject(resource, pi.predicate);
56 if(result.properties == null) result.properties = new HashMap<>();
57 result.properties.put(pi.name, new ImmutableComponentPropertyContent(pi, conn, new ConnectionImpl(pi.predicate), null));
61 HashSet<Resource> childSet = null;
62 for(Resource child : graph.syncRequest(new StructuralChildMapOfResource(resource)).values()) {
64 childSet = new HashSet<>();
68 if(childSet != null) {
69 result.children = new HashMap<>();
70 for(Resource child : childSet) {
71 ImmutableComponentVariableContent content = graph.syncRequest(new ImmutableComponentVariableContentRequest(child));
72 result.children.put(content.name, content);