package org.simantics.modeling; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.request.ResourceRead; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.request.PropertyInfo; import org.simantics.db.layer0.request.UnescapedPropertyMapOfResource; import org.simantics.layer0.Layer0; import org.simantics.structural2.ConnectionImpl; import org.simantics.structural2.Functions.StructuralChildMapOfResource; import org.simantics.structural2.queries.ConnectionPointMapOfResource; public class ImmutableComponentVariableContentRequest extends ResourceRead { protected ImmutableComponentVariableContentRequest(Resource resource) { super(resource); } @Override public ImmutableComponentVariableContent perform(ReadGraph graph) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); String name = graph.getRelatedValue(resource, L0.HasName, Bindings.STRING); ImmutableComponentVariableContent result = new ImmutableComponentVariableContent(resource, name); Map pis = graph.syncRequest(new UnescapedPropertyMapOfResource(resource)); for(Map.Entry e : pis.entrySet()) { PropertyInfo pi = e.getValue(); if(pi.isHasProperty) { ImmutableComponentPropertyContent pc = graph.syncRequest(new ImmutableComponentPropertyContentRequest(resource, pi)); if(pc != null) { if(result.properties == null) result.properties = new HashMap<>(); result.properties.put(pc.pi.name, pc); } } } Map cps = graph.syncRequest(new ConnectionPointMapOfResource(graph, resource)); for(Map.Entry e : cps.entrySet()) { PropertyInfo pi = e.getValue(); Resource conn = graph.getPossibleObject(resource, pi.predicate); if(conn != null) { if(result.properties == null) result.properties = new HashMap<>(); result.properties.put(pi.name, new ImmutableComponentPropertyContent(pi, conn, new ConnectionImpl(pi.predicate), null)); } } HashSet childSet = null; for(Resource child : graph.syncRequest(new StructuralChildMapOfResource(resource)).values()) { if(childSet == null) childSet = new HashSet<>(); childSet.add(child); } if(childSet != null) { result.children = new HashMap<>(); for(Resource child : childSet) { ImmutableComponentVariableContent content = graph.syncRequest(new ImmutableComponentVariableContentRequest(child)); result.children.put(content.name, content); } } return result; } }