]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/AbstractVariableConnectionPointDescriptor.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/AbstractVariableConnectionPointDescriptor.java
new file mode 100644 (file)
index 0000000..5615677
--- /dev/null
@@ -0,0 +1,62 @@
+package org.simantics.structural2.variables;\r
+\r
+import java.util.Collection;\r
+\r
+import org.simantics.db.ReadGraph;\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.request.PropertyInfo;\r
+import org.simantics.db.layer0.request.PropertyInfoRequest;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.db.layer0.variable.Variables;\r
+import org.simantics.structural2.Functions;\r
+import org.simantics.structural2.Functions.InterfaceResolution;\r
+\r
+abstract public class AbstractVariableConnectionPointDescriptor implements VariableConnectionPointDescriptor {\r
+\r
+       static class ComputeInterfaceDescription extends UnaryRead<AbstractVariableConnectionPointDescriptor, Collection<InterfaceResolution>> {\r
+\r
+               public ComputeInterfaceDescription(AbstractVariableConnectionPointDescriptor desc) {\r
+                       super(desc);\r
+               }\r
+\r
+               @Override\r
+               public Collection<InterfaceResolution> perform(ReadGraph graph) throws DatabaseException {\r
+                       return Functions.computeInterfacePaths(graph, parameter.getVariable(graph).getParent(graph));\r
+               }\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public Collection<InterfaceResolution> getInterfaceDescription(ReadGraph graph) throws DatabaseException {\r
+               return graph.syncRequest(new ComputeInterfaceDescription(this), TransientCacheAsyncListener.<Collection<InterfaceResolution>>instance());\r
+       }\r
+       \r
+       @Override\r
+       public boolean isLeaf(ReadGraph graph) throws DatabaseException {\r
+               \r
+               Collection<InterfaceResolution> inf = getInterfaceDescription(graph);\r
+               if(inf == null) return true;\r
+               return inf.isEmpty();\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public boolean hasClassification(ReadGraph graph, String classification) throws DatabaseException {\r
+               \r
+       PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(getConnectionPointResource(graph)), TransientCacheAsyncListener.<PropertyInfo>instance());\r
+       return info.hasClassification(classification);\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public String getRelativeRVI(ReadGraph graph, Variable base) throws DatabaseException {\r
+               \r
+       String var = getURI(graph);\r
+       String baseURI = base.getURI(graph);\r
+       return Variables.getRelativeRVI(baseURI, var);\r
+\r
+       }\r
+\r
+}\r