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
10 public class BrowseConnectionDescriptor extends AbstractVariableConnectionPointDescriptor {
\r
12 public Variable base;
\r
15 public BrowseConnectionDescriptor(Variable base, String rel) {
\r
20 public int hashCode() {
\r
21 return base.hashCode() + 31*rel.hashCode();
\r
24 public boolean equals(Object object) {
\r
27 else if (object == null)
\r
29 else if (!(object instanceof BrowseConnectionDescriptor))
\r
31 BrowseConnectionDescriptor r = (BrowseConnectionDescriptor)object;
\r
32 if(!r.rel.equals(rel)) return false;
\r
33 if(!r.base.equals(base)) return false;
\r
36 static class ComputeVariable extends UnaryRead<BrowseConnectionDescriptor, Variable> {
\r
38 public ComputeVariable(BrowseConnectionDescriptor desc) {
\r
43 public Variable perform(ReadGraph graph) throws DatabaseException {
\r
44 return parameter.base.browse(graph, parameter.rel);
\r
49 public Variable getVariable(ReadGraph graph) throws DatabaseException {
\r
50 return graph.syncRequest(new ComputeVariable(this), TransientCacheAsyncListener.<Variable>instance());
\r
52 public String getURI(ReadGraph graph) throws DatabaseException {
\r
53 return getVariable(graph).getURI(graph);
\r
56 public Resource getConnectionPointResource(ReadGraph graph) throws DatabaseException {
\r
57 return getVariable(graph).getPossiblePredicateResource(graph);
\r
61 public boolean isFlattenedFrom(ReadGraph graph, Variable possiblyStructuralCp) throws DatabaseException {
\r
63 Variable baseParent = base.getParent(graph);
\r
64 Variable parent = possiblyStructuralCp.getParent(graph);
\r
65 Variable parentParent = parent.getParent(graph);
\r
67 if(baseParent.equals(parentParent)) {
\r
68 if(!parent.equals(base)) return false;
\r
71 String descURI = getURI(graph);
\r
72 String parentURI = parent.getURI(graph);
\r
73 if(descURI.startsWith(parentURI)) {
\r
74 // Children are in substructure
\r
75 if('/' == descURI.charAt(parentURI.length())) return true;
\r
76 // Otherwise require exact match
\r
77 return descURI.endsWith(possiblyStructuralCp.getName(graph));
\r