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.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 StructuralResource2 STR = StructuralResource2.getInstance(graph);
33 Resource componentType = graph.getPossibleType(resource, STR.Component);
34 if(componentType != null)
35 result.procedural = graph.isInstanceOf(componentType, STR.ProceduralComponentType);
37 Map<String,PropertyInfo> pis = graph.syncRequest(new UnescapedPropertyMapOfResource(resource));
39 for(Map.Entry<String, PropertyInfo> e : pis.entrySet()) {
40 PropertyInfo pi = e.getValue();
41 if(pi.isHasProperty) {
42 ImmutableComponentPropertyContent pc = graph.syncRequest(new ImmutableComponentPropertyContentRequest(resource, pi));
44 if(result.properties == null) result.properties = new HashMap<>();
45 result.properties.put(pc.pi.name, pc);
50 Map<String,PropertyInfo> cps = graph.syncRequest(new ConnectionPointMapOfResource(graph, resource));
51 for(Map.Entry<String, PropertyInfo> e : cps.entrySet()) {
52 PropertyInfo pi = e.getValue();
53 Resource conn = graph.getPossibleObject(resource, pi.predicate);
55 if(result.properties == null) result.properties = new HashMap<>();
56 result.properties.put(pi.name, new ImmutableComponentPropertyContent(pi, conn, new ConnectionImpl(pi.predicate), null));
60 HashSet<Resource> childSet = null;
62 Resource container = resource;
63 Resource possibleType = graph.getPossibleType(resource, STR.Component);
64 if(possibleType != null) {
65 Resource def = graph.getPossibleObject(possibleType, STR.IsDefinedBy);
66 if(def != null) container = def;
69 for(Resource child : graph.getChildren(container).values()) {
71 childSet = new HashSet<>();
75 if(childSet != null) {
76 result.children = new HashMap<>();
77 for(Resource child : childSet) {
78 ImmutableComponentVariableContent content = graph.syncRequest(new ImmutableComponentVariableContentRequest(child));
79 result.children.put(content.name, content);