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