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