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 {
19 * This is the parent of the component to be connected
21 final private Variable procedural;
23 final private Collection<Pair<String,Resource>> cps = new ArrayList<Pair<String,Resource>>();
25 public FixedConnection(Variable procedural) {
26 this.procedural = procedural;
29 public void addAll(List<Pair<String,Resource>> cps) throws DatabaseException {
31 * For interface connections the name is null
33 for(Pair<String,Resource> cp : cps) {
42 public void addConnectionDescriptors(ReadGraph graph, Variable curConfiguration, Collection<VariableConnectionPointDescriptor> result) throws DatabaseException {
43 for(Pair<String,Resource> cpzz : cps) {
44 // This is a connection to an interface terminal. It is handled by ConnectionBrowser in separate logic. We should never have gotten this far
45 if(cpzz.first == null) {
46 String message = "Lifted connection was not resolved. Child = " + procedural.getURI(graph);
47 throw new DatabaseException(message);
49 result.add(new PairConnectionDescriptor(curConfiguration, cpzz));
54 public Collection<Variable> getConnectionPoints(ReadGraph graph, Resource relationType) throws DatabaseException {
55 Set<Variable> result = new THashSet<Variable>();
56 for(Pair<String,Resource> cp : cps) {
57 Variable component = cp.first == null ? procedural : procedural.getChild(graph, cp.first);
58 Variable cp2 = component.getPossibleProperty(graph, cp.second);
60 for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second, relationType)) {
61 result.add(desc.getVariable(graph));
64 StandardProceduralChildVariable.LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
70 public Collection<String> getConnectionPointURIs(ReadGraph graph, Resource relationType) throws DatabaseException {
71 Set<String> result = new THashSet<String>();
72 for(Pair<String,Resource> cp : cps) {
73 Variable component = cp.first == null ? procedural : procedural.getChild(graph, cp.first);
74 Variable cp2 = component.getPossibleProperty(graph, cp.second);
76 for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second, relationType)) {
77 result.add(desc.getURI(graph));
80 StandardProceduralChildVariable.LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
86 public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph, Resource relationType) throws DatabaseException {
87 Set<VariableConnectionPointDescriptor> result = new THashSet<VariableConnectionPointDescriptor>();
88 for(Pair<String,Resource> cp : cps) {
89 Variable component = cp.first == null ? procedural : procedural.getChild(graph, cp.first);
90 Variable cp2 = component.getPossibleProperty(graph, cp.second);
92 result.addAll(ConnectionBrowser.flatten(graph, component, cp.second, relationType));
94 StandardProceduralChildVariable.LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
100 public int hashCode() {
101 final int prime = 31;
103 result = prime * result + ((cps == null) ? 0 : cps.hashCode());
104 result = prime * result
105 + ((procedural == null) ? 0 : procedural.hashCode());
110 public boolean equals(Object obj) {
115 if (getClass() != obj.getClass())
117 FixedConnection other = (FixedConnection) obj;
119 if (other.cps != null)
121 } else if (!cps.equals(other.cps))
123 if (procedural == null) {
124 if (other.procedural != null)
126 } else if (!procedural.equals(other.procedural))
132 public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph,
133 Variable component_, Resource relationType) throws DatabaseException {
134 Set<VariableConnectionPointDescriptor> result = new THashSet<VariableConnectionPointDescriptor>();
135 for(Pair<String,Resource> cp : cps) {
136 Variable component = cp.first == null ? component_.getParent(graph) : component_;
137 Variable cp2 = component.getPossibleProperty(graph, cp.second);
139 result.addAll(ConnectionBrowser.flatten(graph, component, cp.second, relationType));
141 StandardProceduralChildVariable.LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
147 public Collection<Variable> getConnectionPoints(ReadGraph graph, Variable component_, Resource relationType)
148 throws DatabaseException {
149 Set<Variable> result = new THashSet<Variable>();
150 for(Pair<String,Resource> cp : cps) {
151 Variable component = cp.first == null ? component_.getParent(graph) : component_;
152 Variable cp2 = component.getPossibleProperty(graph, cp.second);
154 for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second, relationType)) {
155 result.add(desc.getVariable(graph));
158 StandardProceduralChildVariable.LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
164 public Collection<String> getConnectionPointURIs(ReadGraph graph, Variable component_, Resource relationType)
165 throws DatabaseException {
166 Set<String> result = new THashSet<String>();
167 for(Pair<String,Resource> cp : cps) {
168 Variable component = cp.first == null ? component_.getParent(graph) : component_;
169 Variable cp2 = component.getPossibleProperty(graph, cp.second);
171 for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second, relationType)) {
172 result.add(desc.getURI(graph));
175 StandardProceduralChildVariable.LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
181 public Connection2 getConnection2() {