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