]> gerrit.simantics Code Review - simantics/platform.git/blob
ac08c945e11ce52a9d7618ba95f1ed6bc03429e4
[simantics/platform.git] /
1 package org.simantics.modeling;
2
3 import java.util.HashMap;
4 import java.util.HashSet;
5 import java.util.Map;
6
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;
18
19 public class ImmutableComponentVariableContentRequest extends ResourceRead<ImmutableComponentVariableContent> {
20
21         protected ImmutableComponentVariableContentRequest(Resource resource) {
22                 super(resource);
23         }
24         
25         @Override
26         public ImmutableComponentVariableContent perform(ReadGraph graph) throws DatabaseException {
27                 
28                 Layer0 L0 = Layer0.getInstance(graph);
29                 String name = graph.getRelatedValue(resource, L0.HasName, Bindings.STRING);
30                 ImmutableComponentVariableContent result = new ImmutableComponentVariableContent(resource, name);
31                 
32                 Map<String,PropertyInfo> pis = graph.syncRequest(new UnescapedPropertyMapOfResource(resource));
33                 
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));
38                                 if(pc != null) {
39                                         if(result.properties == null) result.properties = new HashMap<>();
40                                         result.properties.put(pc.pi.name, pc);
41                                 }
42                         }
43                 }
44
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);
49                         if(conn != null) {
50                                 if(result.properties == null) result.properties = new HashMap<>();
51                                 result.properties.put(pi.name, new ImmutableComponentPropertyContent(pi, conn, new ConnectionImpl(pi.predicate), null));
52                         }
53                 }
54                 
55                 HashSet<Resource> childSet = null;
56                 for(Resource child : graph.syncRequest(new StructuralChildMapOfResource(resource)).values()) {
57                         if(childSet == null)
58                                 childSet = new HashSet<>();
59                         childSet.add(child);
60                 }
61                 
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);
67                         }
68                 }
69                 
70                 return result;
71                 
72         }
73
74         
75 }