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