1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.structural2;
14 import java.util.ArrayList;
15 import java.util.Collection;
17 import org.simantics.databoard.Bindings;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.Statement;
21 import org.simantics.db.common.request.ObjectsWithType;
22 import org.simantics.db.common.request.ResourceRead;
23 import org.simantics.db.exception.DatabaseException;
24 import org.simantics.layer0.Layer0;
25 import org.simantics.structural.stubs.StructuralResource2;
26 import org.simantics.structural2.Functions.InterfaceResolution;
28 public class DefinedUCInterfaceMap extends ResourceRead<Collection<InterfaceResolution>> {
30 public DefinedUCInterfaceMap(Resource resource) {
35 public Collection<InterfaceResolution> perform(ReadGraph graph)
36 throws DatabaseException {
38 StructuralResource2 STR = StructuralResource2.getInstance(graph);
39 Resource definition = graph.getPossibleObject(resource, STR.IsDefinedBy);
40 if(definition != null) {
41 Collection<InterfaceResolution> result = new ArrayList<>();
42 Layer0 L0 = Layer0.getInstance(graph);
43 for(Resource cp : graph.syncRequest(new ObjectsWithType(resource, L0.ConsistsOf, STR.ConnectionRelation))) {
44 String cpName = graph.getRelatedValue(cp, L0.HasName, Bindings.STRING);
45 for(Resource conn : graph.getObjects(cp, STR.IsBoundBy)) {
46 Statement stm = graph.getPossibleStatement(conn, STR.Connects);
47 if(stm == null) continue;
48 Resource component = stm.getObject();
49 String componentName = graph.getRelatedValue(component, L0.HasName, Bindings.STRING);
50 result.add(new InterfaceResolution(cp, cpName, componentName, graph.getInverse(stm.getPredicate())));