-package org.simantics.structural2.variables;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;\r
-import org.simantics.db.common.request.UnaryRead;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.variable.Variable;\r
-\r
-public class BrowseConnectionDescriptor extends AbstractVariableConnectionPointDescriptor {\r
- \r
- public Variable base;\r
- public String rel;\r
- \r
- public BrowseConnectionDescriptor(Variable base, String rel) {\r
- this.base = base;\r
- this.rel = rel;\r
- }\r
- @Override\r
- public int hashCode() {\r
- return base.hashCode() + 31*rel.hashCode();\r
- }\r
- @Override\r
- public boolean equals(Object object) {\r
- if (this == object)\r
- return true;\r
- else if (object == null)\r
- return false;\r
- else if (!(object instanceof BrowseConnectionDescriptor))\r
- return false;\r
- BrowseConnectionDescriptor r = (BrowseConnectionDescriptor)object;\r
- if(!r.rel.equals(rel)) return false;\r
- if(!r.base.equals(base)) return false;\r
- return true;\r
- }\r
- static class ComputeVariable extends UnaryRead<BrowseConnectionDescriptor, Variable> {\r
-\r
- public ComputeVariable(BrowseConnectionDescriptor desc) {\r
- super(desc);\r
- }\r
-\r
- @Override\r
- public Variable perform(ReadGraph graph) throws DatabaseException {\r
- return parameter.base.browse(graph, parameter.rel);\r
- }\r
- \r
- }\r
- @Override\r
- public Variable getVariable(ReadGraph graph) throws DatabaseException {\r
- return graph.syncRequest(new ComputeVariable(this), TransientCacheAsyncListener.<Variable>instance());\r
- }\r
- public String getURI(ReadGraph graph) throws DatabaseException {\r
- return getVariable(graph).getURI(graph);\r
- }\r
- @Override\r
- public Resource getConnectionPointResource(ReadGraph graph) throws DatabaseException {\r
- return getVariable(graph).getPossiblePredicateResource(graph);\r
- }\r
- \r
- @Override\r
- public boolean isFlattenedFrom(ReadGraph graph, Variable possiblyStructuralCp) throws DatabaseException {\r
- \r
- Variable baseParent = base.getParent(graph);\r
- Variable parent = possiblyStructuralCp.getParent(graph);\r
- Variable parentParent = parent.getParent(graph);\r
- \r
- if(baseParent.equals(parentParent)) {\r
- if(!parent.equals(base)) return false;\r
- }\r
-\r
- String descURI = getURI(graph);\r
- String parentURI = parent.getURI(graph);\r
- if(descURI.startsWith(parentURI)) {\r
- // Children are in substructure\r
- if('/' == descURI.charAt(parentURI.length())) return true;\r
- // Otherwise require exact match\r
- return descURI.endsWith(possiblyStructuralCp.getName(graph));\r
- } else {\r
- return false;\r
- }\r
- \r
- }\r
- \r
+package org.simantics.structural2.variables;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
+import org.simantics.db.common.request.UnaryRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+
+public class BrowseConnectionDescriptor extends AbstractVariableConnectionPointDescriptor {
+
+ public Variable base;
+ public String rel;
+
+ public BrowseConnectionDescriptor(Variable base, String rel) {
+ this.base = base;
+ this.rel = rel;
+ }
+ @Override
+ public int hashCode() {
+ return base.hashCode() + 31*rel.hashCode();
+ }
+ @Override
+ public boolean equals(Object object) {
+ if (this == object)
+ return true;
+ else if (object == null)
+ return false;
+ else if (!(object instanceof BrowseConnectionDescriptor))
+ return false;
+ BrowseConnectionDescriptor r = (BrowseConnectionDescriptor)object;
+ if(!r.rel.equals(rel)) return false;
+ if(!r.base.equals(base)) return false;
+ return true;
+ }
+ static class ComputeVariable extends UnaryRead<BrowseConnectionDescriptor, Variable> {
+
+ public ComputeVariable(BrowseConnectionDescriptor desc) {
+ super(desc);
+ }
+
+ @Override
+ public Variable perform(ReadGraph graph) throws DatabaseException {
+ return parameter.base.browse(graph, parameter.rel);
+ }
+
+ }
+ @Override
+ public Variable getVariable(ReadGraph graph) throws DatabaseException {
+ return graph.syncRequest(new ComputeVariable(this), TransientCacheAsyncListener.<Variable>instance());
+ }
+ public String getURI(ReadGraph graph) throws DatabaseException {
+ return getVariable(graph).getURI(graph);
+ }
+ @Override
+ public Resource getConnectionPointResource(ReadGraph graph) throws DatabaseException {
+ return getVariable(graph).getPossiblePredicateResource(graph);
+ }
+
+ @Override
+ public boolean isFlattenedFrom(ReadGraph graph, Variable possiblyStructuralCp) throws DatabaseException {
+
+ Variable baseParent = base.getParent(graph);
+ Variable parent = possiblyStructuralCp.getParent(graph);
+ Variable parentParent = parent.getParent(graph);
+
+ if(baseParent.equals(parentParent)) {
+ if(!parent.equals(base)) return false;
+ }
+
+ String descURI = getURI(graph);
+ String parentURI = parent.getURI(graph);
+ if(descURI.startsWith(parentURI)) {
+ // Children are in substructure
+ if('/' == descURI.charAt(parentURI.length())) return true;
+ // Otherwise require exact match
+ return descURI.endsWith(possiblyStructuralCp.getName(graph));
+ } else {
+ return false;
+ }
+
+ }
+
}
\ No newline at end of file