1 package org.simantics.structural2.variables;
3 import org.simantics.db.ReadGraph;
4 import org.simantics.db.Resource;
5 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
6 import org.simantics.db.common.request.UnaryRead;
7 import org.simantics.db.exception.DatabaseException;
8 import org.simantics.db.layer0.variable.Variable;
9 import org.simantics.utils.datastructures.Pair;
11 public class PairConnectionDescriptor extends AbstractVariableConnectionPointDescriptor {
14 public Pair<String,Resource> pair;
16 public PairConnectionDescriptor(Variable base, Pair<String,Resource> pair) {
21 public int hashCode() {
22 return base.hashCode() + 31*pair.hashCode();
25 public boolean equals(Object object) {
28 else if (object == null)
30 else if (!(object instanceof PairConnectionDescriptor))
32 PairConnectionDescriptor r = (PairConnectionDescriptor)object;
33 if(!r.pair.equals(pair)) return false;
34 if(!r.base.equals(base)) return false;
38 static class ComputeVariable extends UnaryRead<PairConnectionDescriptor, Variable> {
40 public ComputeVariable(PairConnectionDescriptor desc) {
45 public Variable perform(ReadGraph graph) throws DatabaseException {
46 return parameter.base.getChild(graph, parameter.pair.first).getProperty(graph, parameter.pair.second);
51 public Variable getVariable(ReadGraph graph) throws DatabaseException {
52 return graph.syncRequest(new ComputeVariable(this), TransientCacheAsyncListener.<Variable>instance());
54 public String getURI(ReadGraph graph) throws DatabaseException {
55 return getVariable(graph).getURI(graph);
58 public Resource getConnectionPointResource(ReadGraph graph) throws DatabaseException {
59 return getVariable(graph).getPossiblePredicateResource(graph);
63 public boolean isFlattenedFrom(ReadGraph graph, Variable possiblyStructuralCp) throws DatabaseException {
65 Variable parent = possiblyStructuralCp.getParent(graph);
67 String descURI = getURI(graph);
68 String parentURI = parent.getURI(graph);
69 if(descURI.startsWith(parentURI)) {
70 // Children are in substructure
71 if('/' == descURI.charAt(parentURI.length())) return true;
72 // Otherwise require exact match
73 return descURI.endsWith(possiblyStructuralCp.getName(graph));