]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.structural2/src/org/simantics/structural2/variables/AbstractVariableConnectionPointDescriptor.java
Work in progress
[simantics/platform.git] / bundles / org.simantics.structural2 / src / org / simantics / structural2 / variables / AbstractVariableConnectionPointDescriptor.java
1 package org.simantics.structural2.variables;
2
3 import java.util.Collection;
4
5 import org.simantics.db.ReadGraph;
6 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
7 import org.simantics.db.common.request.UnaryRead;
8 import org.simantics.db.exception.DatabaseException;
9 import org.simantics.db.layer0.request.PropertyInfo;
10 import org.simantics.db.layer0.request.PropertyInfoRequest;
11 import org.simantics.db.layer0.variable.Variable;
12 import org.simantics.db.layer0.variable.Variables;
13 import org.simantics.structural2.Functions;
14 import org.simantics.structural2.Functions.InterfaceResolution;
15
16 abstract public class AbstractVariableConnectionPointDescriptor implements VariableConnectionPointDescriptor {
17
18         static class ComputeInterfaceDescription extends UnaryRead<AbstractVariableConnectionPointDescriptor, Collection<InterfaceResolution>> {
19
20                 public ComputeInterfaceDescription(AbstractVariableConnectionPointDescriptor desc) {
21                         super(desc);
22                 }
23
24                 @Override
25                 public Collection<InterfaceResolution> perform(ReadGraph graph) throws DatabaseException {
26                         Variable var = parameter.getVariable(graph);
27                         System.err.println("ComputeInterfaceDescription " + var.getURI(graph));
28                         Collection<InterfaceResolution> res = Functions.computeInterfacePaths(graph, var.getParent(graph));
29                         for(InterfaceResolution r : res)
30                                 System.err.println("-res " + r);
31                         return res;
32                 }
33                 
34         }
35         
36         @Override
37         public Collection<InterfaceResolution> getInterfaceDescription(ReadGraph graph) throws DatabaseException {
38                 return graph.syncRequest(new ComputeInterfaceDescription(this), TransientCacheAsyncListener.<Collection<InterfaceResolution>>instance());
39         }
40         
41         @Override
42         public boolean isLeaf(ReadGraph graph) throws DatabaseException {
43                 
44                 Collection<InterfaceResolution> inf = getInterfaceDescription(graph);
45                 if(inf == null) return true;
46                 return inf.isEmpty();
47                 
48         }
49         
50         @Override
51         public boolean hasClassification(ReadGraph graph, String classification) throws DatabaseException {
52                 
53         PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(getConnectionPointResource(graph)), TransientCacheAsyncListener.<PropertyInfo>instance());
54         return info.hasClassification(classification);
55                 
56         }
57         
58         @Override
59         public String getRelativeRVI(ReadGraph graph, Variable base) throws DatabaseException {
60                 
61         String var = getURI(graph);
62         String baseURI = base.getURI(graph);
63         return Variables.getRelativeRVI(baseURI, var);
64
65         }
66
67 }