- public static class FixedConnection implements org.simantics.structural2.variables.Connection {
-
- final public Collection<Pair<String,Resource>> cps = new ArrayList<Pair<String,Resource>>();
-
- final private Variable parent;
-
- public FixedConnection(Variable parent) {
- this.parent = parent;
- }
-
- @Override
- public Collection<Variable> getConnectionPoints(ReadGraph graph, Resource relationType) throws DatabaseException {
-
- Set<Variable> result = new THashSet<Variable>();
- for(Pair<String,Resource> cp : cps) {
- Variable component = cp.first == null ? parent : parent.getChild(graph, cp.first);
- Variable cp2 = component.getPossibleProperty(graph, cp.second);
- if(cp2 != null)
- for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second, relationType)) {
- result.add(desc.getVariable(graph));
- }
- else
- LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
- }
- return result;
-
- }
-
- @Override
- public Collection<String> getConnectionPointURIs(ReadGraph graph, Resource relationType) throws DatabaseException {
-
- Set<String> result = new THashSet<String>();
- for(Pair<String,Resource> cp : cps) {
- Variable component = cp.first == null ? parent : parent.getChild(graph, cp.first);
- Variable cp2 = component.getPossibleProperty(graph, cp.second);
- if(cp2 != null)
- for(VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second, relationType)) {
- result.add(desc.getURI(graph));
- }
- else
- LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
- }
- return result;
-
- }
-
- @Override
- public Collection<VariableConnectionPointDescriptor> getConnectionPointDescriptors(ReadGraph graph, Resource relationType) throws DatabaseException {
-
- Set<VariableConnectionPointDescriptor> result = new THashSet<VariableConnectionPointDescriptor>();
- for(Pair<String,Resource> cp : cps) {
- Variable component = cp.first == null ? parent : parent.getChild(graph, cp.first);
- Variable cp2 = component.getPossibleProperty(graph, cp.second);
- if(cp2 != null)
- result.addAll(ConnectionBrowser.flatten(graph, component, cp.second, relationType));
- else
- LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph));
- }
- return result;
-
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((cps == null) ? 0 : cps.hashCode());
- result = prime * result
- + ((parent == null) ? 0 : parent.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- FixedConnection other = (FixedConnection) obj;
- if (cps == null) {
- if (other.cps != null)
- return false;
- } else if (!cps.equals(other.cps))
- return false;
- if (parent == null) {
- if (other.parent != null)
- return false;
- } else if (!parent.equals(other.parent))
- return false;
- return true;
- }
-
- }
-