1 package org.simantics.structural2.variables;
3 import java.util.ArrayList;
4 import java.util.Collection;
8 import org.simantics.db.ReadGraph;
9 import org.simantics.db.Resource;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.db.layer0.variable.Variable;
12 import org.simantics.utils.datastructures.Pair;
14 import gnu.trove.set.hash.THashSet;
16 public class FixedConnection implements Connection, Connection2 {
18 final private Variable parent;
20 final private Collection<Pair<String,Resource>> cps = new ArrayList<Pair<String,Resource>>();
22 public FixedConnection(Variable parent) {
26 public void addAll(List<Pair<String,Resource>> cps) throws DatabaseException {
27 for(Pair<String,Resource> cp : cps) {
36 public void addConnectionDescriptors(ReadGraph graph, Variable curConfiguration, Collection<VariableConnectionPointDescriptor> result) throws DatabaseException {
37 for(Pair<String,Resource> cpzz : cps) {
38 // This is a connection to an interface terminal. It is handled by ConnectionBrowser in separate logic. Do not include it here.
39 if(cpzz.first == null) continue;
40 /*if(cpzz.first == null) {
41 String message = "Lifted connection was not resolved. Child = " + parent.getURI(graph);
42 throw new DatabaseException(message);
44 result.add(new PairConnectionDescriptor(curConfiguration, cpzz));
49 public Collection<Variable> getConnectionPoints(ReadGraph graph, Resource relationType) throws DatabaseException {
50 return getConnectionPoints(graph, parent, relationType);
54 public Collection<String> getConnectionPointURIs(ReadGraph graph, Resource relationType) throws DatabaseException {
55 return getConnectionPointURIs(graph, parent, relationType);
60 public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph, Resource relationType) throws DatabaseException {
61 return getConnectionPointDescriptors(graph, parent, relationType);
65 public int hashCode() {
68 result = prime * result + ((cps == null) ? 0 : cps.hashCode());
69 result = prime * result
70 + ((parent == null) ? 0 : parent.hashCode());
75 public boolean equals(Object obj) {
80 if (getClass() != obj.getClass())
82 FixedConnection other = (FixedConnection) obj;
84 if (other.cps != null)
86 } else if (!cps.equals(other.cps))
89 if (other.parent != null)
91 } else if (!parent.equals(other.parent))
97 public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph,
98 Variable parent, Resource relationType) throws DatabaseException {
99 Set<VariableConnectionPointDescriptor> result = new THashSet<VariableConnectionPointDescriptor>();
100 for(Pair<String,Resource> cp : cps) {
101 Variable component = cp.first == null ? parent : parent.getChild(graph, cp.first);
102 Variable cp2 = component.getPossibleProperty(graph, cp.second);
104 result.addAll(ConnectionBrowser.flatten(graph, component, cp.second, relationType));
106 StandardProceduralChildVariable.LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
112 public Collection<Variable> getConnectionPoints(ReadGraph graph, Variable parent, Resource relationType)
113 throws DatabaseException {
114 Set<Variable> result = new THashSet<Variable>();
115 for(Pair<String,Resource> cp : cps) {
116 Variable component = cp.first == null ? parent : parent.getChild(graph, cp.first);
117 Variable cp2 = component.getPossibleProperty(graph, cp.second);
119 for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second, relationType)) {
120 result.add(desc.getVariable(graph));
123 StandardProceduralChildVariable.LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
129 public Collection<String> getConnectionPointURIs(ReadGraph graph, Variable parent, Resource relationType)
130 throws DatabaseException {
131 Set<String> result = new THashSet<String>();
132 for(Pair<String,Resource> cp : cps) {
133 Variable component = cp.first == null ? parent : parent.getChild(graph, cp.first);
134 Variable cp2 = component.getPossibleProperty(graph, cp.second);
136 for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second, relationType)) {
137 result.add(desc.getURI(graph));
140 StandardProceduralChildVariable.LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
146 public Connection2 getConnection2() {