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 ComponentConnectionDescriptor extends AbstractVariableConnectionPointDescriptor {
\r
12 public Variable component;
\r
15 public ComponentConnectionDescriptor(Variable component, Resource cp) {
\r
16 this.component = component;
\r
20 public int hashCode() {
\r
21 return component.hashCode() + 31*cp.hashCode();
\r
24 public boolean equals(Object object) {
\r
27 else if (object == null)
\r
29 else if (!(object instanceof ComponentConnectionDescriptor))
\r
31 ComponentConnectionDescriptor r = (ComponentConnectionDescriptor)object;
\r
32 if(!r.cp.equals(cp)) return false;
\r
33 if(!r.component.equals(component)) return false;
\r
37 static class ComputeVariable extends UnaryRead<ComponentConnectionDescriptor, Variable> {
\r
39 public ComputeVariable(ComponentConnectionDescriptor desc) {
\r
44 public Variable perform(ReadGraph graph) throws DatabaseException {
\r
45 return parameter.component.getProperty(graph, parameter.cp);
\r
50 public Variable getVariable(ReadGraph graph) throws DatabaseException {
\r
51 return graph.syncRequest(new ComputeVariable(this), TransientCacheAsyncListener.<Variable>instance());
\r
53 public String getURI(ReadGraph graph) throws DatabaseException {
\r
54 return getVariable(graph).getURI(graph);
\r
57 public Resource getConnectionPointResource(ReadGraph graph) throws DatabaseException {
\r
58 return getVariable(graph).getPossiblePredicateResource(graph);
\r
62 public boolean isFlattenedFrom(ReadGraph graph, Variable possiblyStructuralCp) throws DatabaseException {
\r
64 Variable parent = possiblyStructuralCp.getParent(graph);
\r
66 String descURI = getURI(graph);
\r
67 String parentURI = parent.getURI(graph);
\r
68 if(descURI.startsWith(parentURI)) {
\r
69 // Children are in substructure
\r
70 if('/' == descURI.charAt(parentURI.length())) return true;
\r
71 // Otherwise require exact match
\r
72 return descURI.endsWith(possiblyStructuralCp.getName(graph));
\r