]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
More Validations and separated validations for dependencies and expressions
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 14 Oct 2011 14:03:10 +0000 (14:03 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 14 Oct 2011 14:03:10 +0000 (14:03 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@22745 ac1ea38d-2e2b-0410-8846-a27921b304fc

12 files changed:
org.simantics.sysdyn.ontology/graph.tg
org.simantics.sysdyn.ontology/graph/Validation.pgraph
org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java
org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ModelUtils.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/DependencyFunction.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ExpressionIssueFunction.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/NoSuchVariableException.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/SyntaxErrorException.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/UndefinedExpressionException.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/UnsupportedCharactersException.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ValidationUtils.java [new file with mode: 0644]

index a8cc35be2a275f1e0408f3753597ee9c3ce081b4..14b2d4f329d56191a881bd8a7dadcd0dc24db9af 100644 (file)
Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ
index 7ee8e1ff1d0b46d4341b474462628a07593c357e..3ff190eadf13ef697afe00c0fbb3e22df083107c 100644 (file)
@@ -7,18 +7,32 @@ VALIDATIONS = SYSDYN.Validations : L0.Library
 \r
 SYSDYN.SysdynIssue <T ISSUE.TextualIssue\r
 \r
-VALIDATIONS.DependencyConnectionsIssueSource <T ISSUE.DependencyIssueSource\r
+// DEPENDENCIES\r
+SYSDYN.DependencyIssue <T SYSDYN.SysdynIssue\r
+VALIDATIONS.Dependencies : L0.Library\r
+\r
+VALIDATIONS.Dependencies.DependencyConnectionsIssueSource <T ISSUE.DependencyIssueSource\r
   @L0.assert ISSUE.DependencyIssueSource.HasType SYSDYN.Variable\r
-  @L0.assert ISSUE.DependencyIssueSource.HasValidator VALIDATIONS.dependencyValidator\r
-  @L0.assert ISSUE.DependencyIssueSource.HasSynchronizer VALIDATIONS.dependencySynchronizer\r
-  @L0.assert ISSUE.DependencyIssueSource.HasBaseFunction VALIDATIONS.dependencyBaseRealizationFunction\r
+  @L0.assert ISSUE.DependencyIssueSource.HasValidator VALIDATIONS.Dependencies.dependencyValidator\r
+  @L0.assert ISSUE.DependencyIssueSource.HasSynchronizer VALIDATIONS.Dependencies.dependencySynchronizer\r
+  @L0.assert ISSUE.DependencyIssueSource.HasBaseFunction VALIDATIONS.Dependencies.dependencyBaseRealizationFunction\r
   \r
   \r
-VALIDATIONS.dependencyValidator : L0X.Function\r
-\r
-\r
-VALIDATIONS.dependencySynchronizer : L0X.Function\r
-\r
+VALIDATIONS.Dependencies.dependencyValidator : L0X.Function\r
+VALIDATIONS.Dependencies.dependencySynchronizer : L0X.Function\r
+VALIDATIONS.Dependencies.dependencyBaseRealizationFunction : L0X.Function\r
+  \r
+// EXPRESSIONS  \r
+SYSDYN.ExpressionIssue <T SYSDYN.SysdynIssue\r
+VALIDATIONS.Expressions : L0.Library\r
 \r
-VALIDATIONS.dependencyBaseRealizationFunction : L0X.Function\r
+VALIDATIONS.Expressions.ExpressionIssueSource <T ISSUE.DependencyIssueSource\r
+  @L0.assert ISSUE.DependencyIssueSource.HasType SYSDYN.Variable\r
+  @L0.assert ISSUE.DependencyIssueSource.HasValidator VALIDATIONS.Expressions.expressionValidator\r
+  @L0.assert ISSUE.DependencyIssueSource.HasSynchronizer VALIDATIONS.Expressions.expressionSynchronizer\r
+  @L0.assert ISSUE.DependencyIssueSource.HasBaseFunction VALIDATIONS.Expressions.expressionBaseRealizationFunction\r
+    \r
+VALIDATIONS.Expressions.expressionValidator : L0X.Function\r
+VALIDATIONS.Expressions.expressionSynchronizer : L0X.Function\r
+VALIDATIONS.Expressions.expressionBaseRealizationFunction : L0X.Function\r
   
\ No newline at end of file
index 85bd17005ee8ba4dcbdc1fc4f6739938b3bd93c3..7d8488e9c7dabf9456fbee64ee01834597f283b9 100644 (file)
@@ -51,6 +51,7 @@ public class SysdynResource {
     public final Resource DelayExpression;\r
     public final Resource Dependency;\r
     public final Resource DependencyConnection;\r
+    public final Resource DependencyIssue;\r
     public final Resource DiagramToCompositeMapping;\r
     public final Resource Enumeration;\r
     public final Resource EnumerationIndex;\r
@@ -58,6 +59,7 @@ public class SysdynResource {
     public final Resource EnumerationIndexes_Inverse;\r
     public final Resource Experiment;\r
     public final Resource Expression;\r
+    public final Resource ExpressionIssue;\r
     public final Resource Expressions;\r
     public final Resource Expressions_Inverse;\r
     public final Resource ExternalFunctionFile;\r
@@ -191,10 +193,16 @@ public class SysdynResource {
     public final Resource SysdynModuleLibrary;\r
     public final Resource SysdynTerminal;\r
     public final Resource Validations;\r
-    public final Resource Validations_DependencyConnectionsIssueSource;\r
-    public final Resource Validations_dependencyBaseRealizationFunction;\r
-    public final Resource Validations_dependencySynchronizer;\r
-    public final Resource Validations_dependencyValidator;\r
+    public final Resource Validations_Dependencies;\r
+    public final Resource Validations_Dependencies_DependencyConnectionsIssueSource;\r
+    public final Resource Validations_Dependencies_dependencyBaseRealizationFunction;\r
+    public final Resource Validations_Dependencies_dependencySynchronizer;\r
+    public final Resource Validations_Dependencies_dependencyValidator;\r
+    public final Resource Validations_Expressions;\r
+    public final Resource Validations_Expressions_ExpressionIssueSource;\r
+    public final Resource Validations_Expressions_expressionBaseRealizationFunction;\r
+    public final Resource Validations_Expressions_expressionSynchronizer;\r
+    public final Resource Validations_Expressions_expressionValidator;\r
     public final Resource Valve;\r
     public final Resource ValveSymbol;\r
     public final Resource Variable;\r
@@ -248,6 +256,7 @@ public class SysdynResource {
         public static final String DelayExpression = "http://www.simantics.org/Sysdyn-1.0/DelayExpression";\r
         public static final String Dependency = "http://www.simantics.org/Sysdyn-1.0/Dependency";\r
         public static final String DependencyConnection = "http://www.simantics.org/Sysdyn-1.0/DependencyConnection";\r
+        public static final String DependencyIssue = "http://www.simantics.org/Sysdyn-1.0/DependencyIssue";\r
         public static final String DiagramToCompositeMapping = "http://www.simantics.org/Sysdyn-1.0/DiagramToCompositeMapping";\r
         public static final String Enumeration = "http://www.simantics.org/Sysdyn-1.0/Enumeration";\r
         public static final String EnumerationIndex = "http://www.simantics.org/Sysdyn-1.0/EnumerationIndex";\r
@@ -255,6 +264,7 @@ public class SysdynResource {
         public static final String EnumerationIndexes_Inverse = "http://www.simantics.org/Sysdyn-1.0/EnumerationIndexes/Inverse";\r
         public static final String Experiment = "http://www.simantics.org/Sysdyn-1.0/Experiment";\r
         public static final String Expression = "http://www.simantics.org/Sysdyn-1.0/Expression";\r
+        public static final String ExpressionIssue = "http://www.simantics.org/Sysdyn-1.0/ExpressionIssue";\r
         public static final String Expressions = "http://www.simantics.org/Sysdyn-1.0/Expressions";\r
         public static final String Expressions_Inverse = "http://www.simantics.org/Sysdyn-1.0/Expressions/Inverse";\r
         public static final String ExternalFunctionFile = "http://www.simantics.org/Sysdyn-1.0/ExternalFunctionFile";\r
@@ -388,10 +398,16 @@ public class SysdynResource {
         public static final String SysdynModuleLibrary = "http://www.simantics.org/Sysdyn-1.0/SysdynModuleLibrary";\r
         public static final String SysdynTerminal = "http://www.simantics.org/Sysdyn-1.0/SysdynTerminal";\r
         public static final String Validations = "http://www.simantics.org/Sysdyn-1.0/Validations";\r
-        public static final String Validations_DependencyConnectionsIssueSource = "http://www.simantics.org/Sysdyn-1.0/Validations/DependencyConnectionsIssueSource";\r
-        public static final String Validations_dependencyBaseRealizationFunction = "http://www.simantics.org/Sysdyn-1.0/Validations/dependencyBaseRealizationFunction";\r
-        public static final String Validations_dependencySynchronizer = "http://www.simantics.org/Sysdyn-1.0/Validations/dependencySynchronizer";\r
-        public static final String Validations_dependencyValidator = "http://www.simantics.org/Sysdyn-1.0/Validations/dependencyValidator";\r
+        public static final String Validations_Dependencies = "http://www.simantics.org/Sysdyn-1.0/Validations/Dependencies";\r
+        public static final String Validations_Dependencies_DependencyConnectionsIssueSource = "http://www.simantics.org/Sysdyn-1.0/Validations/Dependencies/DependencyConnectionsIssueSource";\r
+        public static final String Validations_Dependencies_dependencyBaseRealizationFunction = "http://www.simantics.org/Sysdyn-1.0/Validations/Dependencies/dependencyBaseRealizationFunction";\r
+        public static final String Validations_Dependencies_dependencySynchronizer = "http://www.simantics.org/Sysdyn-1.0/Validations/Dependencies/dependencySynchronizer";\r
+        public static final String Validations_Dependencies_dependencyValidator = "http://www.simantics.org/Sysdyn-1.0/Validations/Dependencies/dependencyValidator";\r
+        public static final String Validations_Expressions = "http://www.simantics.org/Sysdyn-1.0/Validations/Expressions";\r
+        public static final String Validations_Expressions_ExpressionIssueSource = "http://www.simantics.org/Sysdyn-1.0/Validations/Expressions/ExpressionIssueSource";\r
+        public static final String Validations_Expressions_expressionBaseRealizationFunction = "http://www.simantics.org/Sysdyn-1.0/Validations/Expressions/expressionBaseRealizationFunction";\r
+        public static final String Validations_Expressions_expressionSynchronizer = "http://www.simantics.org/Sysdyn-1.0/Validations/Expressions/expressionSynchronizer";\r
+        public static final String Validations_Expressions_expressionValidator = "http://www.simantics.org/Sysdyn-1.0/Validations/Expressions/expressionValidator";\r
         public static final String Valve = "http://www.simantics.org/Sysdyn-1.0/Valve";\r
         public static final String ValveSymbol = "http://www.simantics.org/Sysdyn-1.0/ValveSymbol";\r
         public static final String Variable = "http://www.simantics.org/Sysdyn-1.0/Variable";\r
@@ -455,6 +471,7 @@ public class SysdynResource {
         DelayExpression = getResourceOrNull(graph, URIs.DelayExpression);\r
         Dependency = getResourceOrNull(graph, URIs.Dependency);\r
         DependencyConnection = getResourceOrNull(graph, URIs.DependencyConnection);\r
+        DependencyIssue = getResourceOrNull(graph, URIs.DependencyIssue);\r
         DiagramToCompositeMapping = getResourceOrNull(graph, URIs.DiagramToCompositeMapping);\r
         Enumeration = getResourceOrNull(graph, URIs.Enumeration);\r
         EnumerationIndex = getResourceOrNull(graph, URIs.EnumerationIndex);\r
@@ -462,6 +479,7 @@ public class SysdynResource {
         EnumerationIndexes_Inverse = getResourceOrNull(graph, URIs.EnumerationIndexes_Inverse);\r
         Experiment = getResourceOrNull(graph, URIs.Experiment);\r
         Expression = getResourceOrNull(graph, URIs.Expression);\r
+        ExpressionIssue = getResourceOrNull(graph, URIs.ExpressionIssue);\r
         Expressions = getResourceOrNull(graph, URIs.Expressions);\r
         Expressions_Inverse = getResourceOrNull(graph, URIs.Expressions_Inverse);\r
         ExternalFunctionFile = getResourceOrNull(graph, URIs.ExternalFunctionFile);\r
@@ -595,10 +613,16 @@ public class SysdynResource {
         SysdynModuleLibrary = getResourceOrNull(graph, URIs.SysdynModuleLibrary);\r
         SysdynTerminal = getResourceOrNull(graph, URIs.SysdynTerminal);\r
         Validations = getResourceOrNull(graph, URIs.Validations);\r
-        Validations_DependencyConnectionsIssueSource = getResourceOrNull(graph, URIs.Validations_DependencyConnectionsIssueSource);\r
-        Validations_dependencyBaseRealizationFunction = getResourceOrNull(graph, URIs.Validations_dependencyBaseRealizationFunction);\r
-        Validations_dependencySynchronizer = getResourceOrNull(graph, URIs.Validations_dependencySynchronizer);\r
-        Validations_dependencyValidator = getResourceOrNull(graph, URIs.Validations_dependencyValidator);\r
+        Validations_Dependencies = getResourceOrNull(graph, URIs.Validations_Dependencies);\r
+        Validations_Dependencies_DependencyConnectionsIssueSource = getResourceOrNull(graph, URIs.Validations_Dependencies_DependencyConnectionsIssueSource);\r
+        Validations_Dependencies_dependencyBaseRealizationFunction = getResourceOrNull(graph, URIs.Validations_Dependencies_dependencyBaseRealizationFunction);\r
+        Validations_Dependencies_dependencySynchronizer = getResourceOrNull(graph, URIs.Validations_Dependencies_dependencySynchronizer);\r
+        Validations_Dependencies_dependencyValidator = getResourceOrNull(graph, URIs.Validations_Dependencies_dependencyValidator);\r
+        Validations_Expressions = getResourceOrNull(graph, URIs.Validations_Expressions);\r
+        Validations_Expressions_ExpressionIssueSource = getResourceOrNull(graph, URIs.Validations_Expressions_ExpressionIssueSource);\r
+        Validations_Expressions_expressionBaseRealizationFunction = getResourceOrNull(graph, URIs.Validations_Expressions_expressionBaseRealizationFunction);\r
+        Validations_Expressions_expressionSynchronizer = getResourceOrNull(graph, URIs.Validations_Expressions_expressionSynchronizer);\r
+        Validations_Expressions_expressionValidator = getResourceOrNull(graph, URIs.Validations_Expressions_expressionValidator);\r
         Valve = getResourceOrNull(graph, URIs.Valve);\r
         ValveSymbol = getResourceOrNull(graph, URIs.ValveSymbol);\r
         Variable = getResourceOrNull(graph, URIs.Variable);\r
index 9179e5173e1836d32b2f704e716d1e43cdd51427..a23cc2f2f71ec6eb3affa1f7ca4212985ce8c87b 100644 (file)
    \r
    <extension point="org.simantics.scl.reflection.binding">\r
       <namespace path="http://www.simantics.org/Sysdyn-1.0/Validations">\r
-         <class className="org.simantics.sysdyn.ui.validation.DependencyFunction"/>\r
+        <namespace path="Dependencies">\r
+            <class className="org.simantics.sysdyn.ui.validation.DependencyFunction"/>\r
+        </namespace>\r
+        <namespace path="Expressions">\r
+            <class className="org.simantics.sysdyn.ui.validation.ExpressionIssueFunction"/>\r
+        </namespace>\r
       </namespace>\r
    </extension>\r
 </plugin>\r
index cfa0f15fb62da677858a6f2dca892dfe497a60a7..3ce5b532ce24dc73541a3891b682f01fbd22465d 100644 (file)
@@ -73,7 +73,13 @@ public class ModelUtils {
                     );\r
 \r
             GraphUtils.create2(g,\r
-                    sr.Validations_DependencyConnectionsIssueSource,\r
+                    sr.Validations_Dependencies_DependencyConnectionsIssueSource,\r
+                    L0X.IsActivatedBy, model,\r
+                    l0.PartOf, model\r
+                    );\r
+            \r
+            GraphUtils.create2(g,\r
+                    sr.Validations_Expressions_ExpressionIssueSource,\r
                     L0X.IsActivatedBy, model,\r
                     l0.PartOf, model\r
                     );\r
index edd32658a54042b0b2f88fdef53dfe2f5f26a455..a6431ad4f1e30027c7903658fb116d2837730541 100644 (file)
@@ -1,44 +1,35 @@
 package org.simantics.sysdyn.ui.validation;\r
 \r
-import java.io.StringReader;\r
-import java.text.DateFormat;\r
-import java.text.SimpleDateFormat;\r
-import java.util.Calendar;\r
 import java.util.Collection;\r
 import java.util.HashSet;\r
-import java.util.List;\r
 import java.util.Set;\r
-import java.util.UUID;\r
 \r
 import org.simantics.databoard.Bindings;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.ObjectsWithType;\r
-import org.simantics.db.common.utils.OrderedSetUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.issues.ontology.IssueResource;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.scl.reflection.annotations.SCLValue;\r
 import org.simantics.simulation.ontology.SimulationResource;\r
 import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.expressionParser.ExpressionParser;\r
-import org.simantics.sysdyn.expressionParser.ParseException;\r
-import org.simantics.sysdyn.expressionParser.TokenMgrError;\r
 \r
 public class DependencyFunction {\r
 \r
 \r
     private static String getMissingLinkLabel(String name, String dependency) throws DatabaseException {\r
-        String label = "Missing link " + dependency + " in " + name;\r
-        return label;\r
+        return "Missing link " + dependency + " in " + name;\r
     }\r
     \r
-    private static String getUnusedDependencyLabel(String name, String dependency) throws DatabaseException {\r
-        String label = "Unused dependency " + dependency + " in " + name;\r
-        return label;\r
+    private static String getNoSuchVariableLabel(String name, String dependency) throws DatabaseException {\r
+        return name + " refers to variable " + dependency + " that does not exist";\r
     }\r
 \r
+    private static String getUnusedDependencyLabel(String name, String dependency) throws DatabaseException {\r
+        return "Unused dependency " + dependency + " in " + name;\r
+    }\r
+    \r
     /**\r
      * \r
      * One issue is enough. The first encounter of a new issue returns Boolean.FALSE.\r
@@ -55,38 +46,51 @@ public class DependencyFunction {
         ReadGraph graph = (ReadGraph)_graph;\r
         Resource variable = (Resource)_resource;\r
         Collection<Resource> existing = (Collection<Resource>)_existing;\r
-\r
-        Set<String> references = getReferences(graph, variable);\r
-        Set<String> dependencies = getDependencies(graph, variable);\r
         \r
+        if(!graph.hasStatement(variable) || !graph.hasStatement(variable, Layer0.getInstance(graph).PartOf))\r
+            return Boolean.FALSE;\r
+\r
         String name = graph.getRelatedValue(variable, Layer0.getInstance(graph).HasName, Bindings.STRING);\r
-        \r
-        for(String reference : references) {\r
-            if(!dependencies.contains(reference) && match(graph, existing, variable, getMissingLinkLabel(name, reference)) == null)\r
-                return Boolean.FALSE;\r
-        }\r
-        \r
-        for(String dependency : dependencies) {\r
-            if(!references.contains(dependency) && match(graph, existing, variable, getUnusedDependencyLabel(name, dependency)) == null)\r
-                return Boolean.FALSE;\r
+\r
+        Set<String> references;\r
+        Set<String> dependencies;\r
+        try {\r
+            references = ValidationUtils.getReferences(graph, variable);\r
+            dependencies = ValidationUtils.getDependencies(graph, variable);\r
+            \r
+            \r
+            for(String reference : references) {\r
+                if(!dependencies.contains(reference) && match(graph, existing, variable, getMissingLinkLabel(name, reference)) == null)\r
+                    return Boolean.FALSE;\r
+            }\r
+\r
+            for(String dependency : dependencies) {\r
+                if(!references.contains(dependency) && match(graph, existing, variable, getUnusedDependencyLabel(name, dependency)) == null)\r
+                    return Boolean.FALSE;\r
+            }\r
+        } catch (SyntaxErrorException e) {\r
+        } catch (UnsupportedCharactersException e) {\r
+        } catch (UndefinedExpressionException e) {\r
         }\r
         \r
-        \r
-        /*\r
-         * See if there are any unnecessary issues in existing\r
-         * \r
-         * FIXME: Currently there are no other issues, so this can check ALL issues.\r
-         */\r
         IssueResource ISSUE = IssueResource.getInstance(graph);\r
-\r
+        SysdynResource sr = SysdynResource.getInstance(graph);\r
+        Layer0 l0 = Layer0.getInstance(graph);\r
+        \r
+        Resource context;\r
         for(Resource exist : existing) {\r
-            if(variable.equals(graph.getSingleObject(exist, ISSUE.HasIssueContext))) {\r
+            context = graph.getSingleObject(exist, ISSUE.HasIssueContext);\r
+            if(!graph.hasStatement(context) || graph.hasStatement(context, l0.PartOf))\r
+                return Boolean.FALSE;\r
+            if(variable.equals(context) && graph.isInstanceOf(exist, sr.DependencyIssue)) {\r
                 return Boolean.FALSE;\r
             }\r
         }\r
+\r
         return Boolean.TRUE;\r
     }\r
 \r
+    \r
     @SCLValue(type = "a -> b -> c -> d -> e -> f")\r
     public static Object dependencySynchronizer(Object _graph, Object _resource, Object _source, Object _model, Object _existing) throws DatabaseException {\r
 \r
@@ -96,87 +100,72 @@ public class DependencyFunction {
         Resource source = (Resource)_source;\r
         Collection<Resource> existing = (Collection<Resource>)_existing;\r
         Layer0 L0 = Layer0.getInstance(graph);\r
-\r
-        Set<String> references = getReferences(graph, variable);\r
-        Set<String> dependencies = getDependencies(graph, variable);\r
-\r
+        IssueResource ISSUE = IssueResource.getInstance(graph);\r
+        SysdynResource sr = SysdynResource.getInstance(graph);\r
         \r
         String name = graph.getRelatedValue(variable, L0.HasName, Bindings.STRING);\r
-        \r
+\r
         Set<String> labels = new HashSet<String>();\r
         String label;\r
         \r
-        for(String reference : references) {\r
-            label = getMissingLinkLabel(name, reference);\r
-            if(!dependencies.contains(reference)) {\r
-                labels.add(label);\r
-                if(match(graph, existing, variable, label) == null) {\r
-                    createIssue(graph, model, source, variable, label);\r
-                }\r
-            } \r
-            /*else {\r
-                if((issue = match(graph, existing, variable, label)) != null) {\r
-                    removeIssue(graph, model, source, variable, issue, existing);\r
-                }\r
-            }*/\r
-        }\r
-        \r
-        for(String dependency : dependencies) {\r
-            label = getUnusedDependencyLabel(name, dependency);\r
-            if(!references.contains(dependency)) {\r
-                labels.add(label);\r
-                if(match(graph, existing, variable, label) == null) {\r
-                    createIssue(graph, model, source, variable, label);\r
-                }\r
+        Set<String> references;\r
+        Set<String> dependencies;\r
+        try {\r
+            references = ValidationUtils.getReferences(graph, variable);\r
+            dependencies = ValidationUtils.getDependencies(graph, variable);\r
+            for(String reference : references) {\r
+                if(!dependencies.contains(reference)) {\r
+                    if(ValidationUtils.isReachable(graph, variable, reference)) {\r
+                        label = getMissingLinkLabel(name, reference);\r
+                        labels.add(label);\r
+                        if(match(graph, existing, variable, label) == null) {\r
+                            ValidationUtils.createIssue(graph, model, source, variable, label, ISSUE.Severity_Warning, sr.DependencyIssue);\r
+                        }\r
+                    } else {\r
+                        label = getNoSuchVariableLabel(name, reference);\r
+                        labels.add(label);\r
+                        if(match(graph, existing, variable, label) == null) {\r
+                            ValidationUtils.createIssue(graph, model, source, variable, label, ISSUE.Severity_Error, sr.DependencyIssue);\r
+                        }\r
+                    }\r
+                } \r
             }\r
-            \r
-            /*else {\r
-                if((issue = match(graph, existing, variable, label)) != null) {\r
-                    removeIssue(graph, model, source, variable, issue, existing);\r
+\r
+            for(String dependency : dependencies) {\r
+                label = getUnusedDependencyLabel(name, dependency);\r
+                if(!references.contains(dependency)) {\r
+                    labels.add(label);\r
+                    if(match(graph, existing, variable, label) == null) {\r
+                        ValidationUtils.createIssue(graph, model, source, variable, label, ISSUE.Severity_Warning, sr.DependencyIssue);\r
+                    }\r
                 }\r
-            }*/\r
+            }\r
+        } catch (SyntaxErrorException e) {\r
+        } catch (UnsupportedCharactersException e) {\r
+        } catch (UndefinedExpressionException e) {\r
         }\r
-        \r
+\r
         Set<Resource> toBeRemoved = new HashSet<Resource>();\r
+        Resource context;\r
         for(Resource exist : existing) {\r
-            String l = graph.getRelatedValue(exist, L0.HasLabel);\r
-            Resource i = graph.getSingleObject(exist, IssueResource.getInstance(graph).HasIssueContext);\r
-            if(variable.equals(i) && !labels.contains(l))\r
+            context = graph.getSingleObject(exist, ISSUE.HasIssueContext);\r
+            if(!graph.hasStatement(context) || !graph.hasStatement(context, L0.PartOf))\r
                 toBeRemoved.add(exist);\r
+            if(graph.isInstanceOf(exist, sr.DependencyIssue) && variable.equals(context)) {\r
+                String l = graph.getRelatedValue(exist, L0.HasLabel);\r
+                if(!labels.contains(l))\r
+                    toBeRemoved.add(exist);\r
+            }\r
         }\r
-        \r
+\r
         for(Resource r : toBeRemoved) {\r
-            removeIssue(graph, model, source, variable, r, existing);\r
+            ValidationUtils.removeIssue(graph, model, source, variable, r, existing);\r
         }\r
-        \r
+\r
 \r
         return Boolean.TRUE;\r
 \r
     }\r
-    \r
-    private static Resource createIssue(WriteGraph graph, Resource model, Resource source, Resource variable, String label) throws DatabaseException {\r
-        Layer0 L0 = Layer0.getInstance(graph);\r
-        IssueResource ISSUE = IssueResource.getInstance(graph);\r
-        \r
-        Resource issue = graph.newResource();\r
-        graph.claim(issue, L0.InstanceOf, null, ISSUE.Issue);\r
-        graph.claim(issue, ISSUE.HasIssueContext, null, variable);\r
-        graph.claim(issue, ISSUE.HasSeverity, ISSUE.Severity_Warning);\r
-        graph.claimLiteral(issue, L0.HasLabel, label, Bindings.STRING);\r
-        graph.claimLiteral(issue, L0.HasName, UUID.randomUUID().toString(), Bindings.STRING);\r
-        DateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");\r
-        String created = format.format(Calendar.getInstance().getTime());\r
-        graph.claimLiteral(issue, ISSUE.HasCreationTime, created, Bindings.STRING);\r
-        graph.claim(source, ISSUE.Manages, issue);\r
-        graph.claim(model, L0.ConsistsOf, issue);    \r
-        return issue;\r
-    }\r
-    \r
-    private static void removeIssue(WriteGraph graph, Resource model, Resource source, Resource variable, Resource issue, Collection<Resource> existing) throws DatabaseException {\r
-        graph.deny(issue, Layer0.getInstance(graph).PartOf);\r
-        graph.deny(source, IssueResource.getInstance(graph).Manages, issue);\r
-        existing.remove(issue);\r
-    }\r
 \r
     @SCLValue(type = "a -> b -> c")\r
     public static Object dependencyBaseRealizationFunction(Object _graph, Object _model) throws DatabaseException {\r
@@ -198,58 +187,5 @@ public class DependencyFunction {
         }\r
         return null;\r
     }\r
-    \r
-    // Returns the names of the related variables (dependencies)\r
-    private static HashSet<String> getDependencies(ReadGraph graph, Resource r) throws DatabaseException {\r
-        HashSet<String> variables = new HashSet<String>();\r
-        if(graph != null && r != null) {\r
-            SysdynResource sr = SysdynResource.getInstance(graph);\r
-            Layer0 l0 = Layer0.getInstance(graph);\r
-\r
-            Collection<Resource> dependencies = graph.getObjects(r, sr.IsHeadOf);\r
-\r
-            for(Resource d : dependencies) {\r
-                if(graph.isInstanceOf(d, sr.Dependency)) {\r
-                    Resource tail = graph.getPossibleObject(d, sr.HasTail);\r
-                    if(tail != null) {\r
-                        Object name = graph.getPossibleRelatedValue(tail, l0.HasName);\r
-                        if(name != null)\r
-                            variables.add((String)name);\r
-                    }\r
-                }\r
-            }\r
-        }\r
-        return variables;\r
-    }\r
-    \r
-    private static HashSet<String> getReferences(ReadGraph graph, Resource r) throws DatabaseException {\r
-        HashSet<String> references = new HashSet<String>();\r
-        ExpressionParser parser = new ExpressionParser(new StringReader(""));\r
 \r
-        SysdynResource sr = SysdynResource.getInstance(graph);\r
-        Layer0 l0 = Layer0.getInstance(graph);\r
-        Resource hasExpressions = graph.getPossibleObject(r, sr.HasExpressions);\r
-        if(hasExpressions != null){\r
-            List<Resource> expressionList = OrderedSetUtils.toList(graph, hasExpressions);\r
-            for(Resource expression : expressionList) {\r
-                for(Resource s : graph.syncRequest(new ObjectsWithType(expression, sr.HasEquation, l0.String))) {\r
-                    String value = graph.getValue(s, Bindings.STRING);\r
-                    parser.ReInit(new StringReader(value));\r
-                    try {\r
-                        parser.expr();\r
-                        references.addAll(parser.getReferences().keySet());\r
-                    } catch (ParseException e1) {\r
-                        // TODO: Issue\r
-                        System.out.println("SYNTAX ERROR");\r
-//                        ef.setSyntaxError(e1.currentToken, "Syntax Error");\r
-                    } catch (TokenMgrError err) {\r
-                        // TODO: Issue\r
-                        System.out.println("UNSUPPORTED CHARACTERS");\r
-//                        ef.setSyntaxError(0, textString.length(), ExpressionField.SYNTAX_ERROR, "Expression contains unsupported characters");\r
-                    }\r
-                }\r
-            }\r
-        }\r
-        return references;\r
-    }\r
 }\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ExpressionIssueFunction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ExpressionIssueFunction.java
new file mode 100644 (file)
index 0000000..344310f
--- /dev/null
@@ -0,0 +1,151 @@
+package org.simantics.sysdyn.ui.validation;\r
+\r
+import java.util.Collection;\r
+import java.util.HashSet;\r
+import java.util.Set;\r
+\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.issues.ontology.IssueResource;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.scl.reflection.annotations.SCLValue;\r
+import org.simantics.simulation.ontology.SimulationResource;\r
+import org.simantics.sysdyn.SysdynResource;\r
+\r
+/**\r
+ * Detects syntax errors, unsupported characters and undefined expressions from variables.\r
+ * \r
+ * @author tlteemu\r
+ *\r
+ */\r
+public class ExpressionIssueFunction {\r
+    \r
+    private static String getSyntaxErrorLabel(String name) throws DatabaseException {\r
+        return "Syntax error in " + name;\r
+    }\r
+    \r
+    private static String getUnsupportedCharacterLabel(String name) throws DatabaseException {\r
+        return "Unsupported character(s) in " + name;\r
+    }\r
+    \r
+    private static String getUndefinedExpressionLabel(String name) throws DatabaseException {\r
+        return "Undefined expression in " + name;\r
+    }\r
+    \r
+    @SCLValue(type = "a -> b -> c -> d")\r
+    public static Object expressionValidator(Object _graph, Object _resource, Object _existing) throws DatabaseException {\r
+        \r
+        ReadGraph graph = (ReadGraph)_graph;\r
+        Resource variable = (Resource)_resource;\r
+        Collection<Resource> existing = (Collection<Resource>)_existing;\r
+        String name = graph.getRelatedValue(variable, Layer0.getInstance(graph).HasName, Bindings.STRING);\r
+\r
+        // Try if there are any errors while parsing the expressions\r
+        try {\r
+            ValidationUtils.getReferences(graph, variable);\r
+        } catch (SyntaxErrorException e) {\r
+            if(match(graph, existing, variable, getSyntaxErrorLabel(name)) == null)\r
+                return Boolean.FALSE;\r
+        } catch (UnsupportedCharactersException e) {\r
+            if(match(graph, existing, variable, getUnsupportedCharacterLabel(name)) == null)\r
+                return Boolean.FALSE;\r
+        } catch (UndefinedExpressionException e) {\r
+            if(match(graph, existing, variable, getUndefinedExpressionLabel(name)) == null)\r
+                return Boolean.FALSE;\r
+        }    \r
+        \r
+        SysdynResource sr = SysdynResource.getInstance(graph);\r
+        IssueResource ISSUE = IssueResource.getInstance(graph);\r
+        Layer0 l0 = Layer0.getInstance(graph);\r
+\r
+        Resource context;\r
+        // There were no errors -> There should be no expression issues for this variable\r
+        for(Resource exist : existing) {\r
+            context = graph.getSingleObject(exist, ISSUE.HasIssueContext);\r
+            if(!graph.hasStatement(context) || graph.hasStatement(context, l0.PartOf))\r
+                return Boolean.FALSE;\r
+            if(variable.equals(context) && graph.isInstanceOf(exist, sr.ExpressionIssue)) {\r
+                return Boolean.FALSE;\r
+            }\r
+        }\r
+        \r
+        \r
+        return Boolean.TRUE;\r
+    }\r
+\r
+    \r
+    @SCLValue(type = "a -> b -> c -> d -> e -> f")\r
+    public static Object expressionSynchronizer(Object _graph, Object _resource, Object _source, Object _model, Object _existing) throws DatabaseException {\r
+        WriteGraph graph = (WriteGraph)_graph;\r
+        Resource variable = (Resource)_resource;\r
+        Resource model = (Resource)_model;\r
+        Resource source = (Resource)_source;\r
+        Collection<Resource> existing = (Collection<Resource>)_existing;\r
+        Layer0 L0 = Layer0.getInstance(graph);\r
+        IssueResource ISSUE = IssueResource.getInstance(graph);\r
+        SysdynResource sr = SysdynResource.getInstance(graph);\r
+        \r
+        String name = graph.getRelatedValue(variable, L0.HasName, Bindings.STRING);\r
+        String label = null; \r
+        Resource issue = null;\r
+        try {\r
+            ValidationUtils.getReferences(graph, variable);\r
+        } catch (SyntaxErrorException e) {\r
+            label = getSyntaxErrorLabel(name);\r
+            if(match(graph, existing, variable, label) == null)\r
+                issue = ValidationUtils.createIssue(graph, model, source, variable, label, ISSUE.Severity_Error, sr.ExpressionIssue);\r
+        } catch (UnsupportedCharactersException e) {\r
+            label = getUnsupportedCharacterLabel(name);\r
+            if(match(graph, existing, variable, label) == null)\r
+                issue = ValidationUtils.createIssue(graph, model, source, variable, label, ISSUE.Severity_Error, sr.ExpressionIssue);\r
+        } catch (UndefinedExpressionException e) {\r
+            label = getUndefinedExpressionLabel(name);\r
+            if(match(graph, existing, variable, label) == null)\r
+                issue = ValidationUtils.createIssue(graph, model, source, variable, label, ISSUE.Severity_Error, sr.ExpressionIssue);\r
+        }\r
+        \r
+        Resource context;\r
+        Set<Resource> toBeRemoved = new HashSet<Resource>();\r
+        for(Resource exist : existing) {\r
+            context = graph.getSingleObject(exist, ISSUE.HasIssueContext);\r
+            if(!graph.hasStatement(context) || !graph.hasStatement(context, L0.PartOf))\r
+                toBeRemoved.add(exist);\r
+            else if(!exist.equals(issue) && graph.isInstanceOf(exist, sr.ExpressionIssue) && variable.equals(context)) {\r
+                String l = graph.getRelatedValue(exist, L0.HasLabel);\r
+                if(!l.equals(label)) {\r
+                    toBeRemoved.add(exist);\r
+                }\r
+            }\r
+        }\r
+        \r
+        for(Resource r : toBeRemoved) {\r
+            ValidationUtils.removeIssue(graph, model, source, variable, r, existing);\r
+        }\r
+        \r
+        return Boolean.TRUE;\r
+    }\r
+\r
+\r
+    @SCLValue(type = "a -> b -> c")\r
+    public static Object expressionBaseRealizationFunction(Object _graph, Object _model) throws DatabaseException {\r
+        ReadGraph graph = (ReadGraph)_graph;\r
+        Resource model = (Resource)_model;\r
+        return graph.getSingleObject(model, SimulationResource.getInstance(graph).HasConfiguration);\r
+    }\r
+    \r
+    \r
+    private static Resource match(ReadGraph graph, Collection<Resource> existing, Resource variable, String description) throws DatabaseException {\r
+        Layer0 L0 = Layer0.getInstance(graph);\r
+        IssueResource ISSUE = IssueResource.getInstance(graph);\r
+        for(Resource exist : existing) {\r
+            Resource source = graph.getSingleObject(exist, ISSUE.HasIssueContext);\r
+            String desc = graph.getRelatedValue(exist, L0.HasLabel);\r
+            if(source.equals(variable) && desc.equals(description)) return exist;\r
+        }\r
+        return null;\r
+    }\r
+    \r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/NoSuchVariableException.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/NoSuchVariableException.java
new file mode 100644 (file)
index 0000000..668ddee
--- /dev/null
@@ -0,0 +1,6 @@
+package org.simantics.sysdyn.ui.validation;\r
+\r
+public class NoSuchVariableException extends RuntimeException {\r
+    private static final long serialVersionUID = -5766352512554068379L;\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/SyntaxErrorException.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/SyntaxErrorException.java
new file mode 100644 (file)
index 0000000..8d577c9
--- /dev/null
@@ -0,0 +1,7 @@
+package org.simantics.sysdyn.ui.validation;\r
+\r
+public class SyntaxErrorException extends RuntimeException {\r
+    private static final long serialVersionUID = -6466653179001958636L;\r
+    \r
+    \r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/UndefinedExpressionException.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/UndefinedExpressionException.java
new file mode 100644 (file)
index 0000000..bffa074
--- /dev/null
@@ -0,0 +1,6 @@
+package org.simantics.sysdyn.ui.validation;\r
+\r
+public class UndefinedExpressionException extends RuntimeException {\r
+    private static final long serialVersionUID = 7352486116119189105L;\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/UnsupportedCharactersException.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/UnsupportedCharactersException.java
new file mode 100644 (file)
index 0000000..e96b609
--- /dev/null
@@ -0,0 +1,6 @@
+package org.simantics.sysdyn.ui.validation;\r
+\r
+public class UnsupportedCharactersException extends RuntimeException {\r
+    private static final long serialVersionUID = 8210873686720503188L;\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ValidationUtils.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ValidationUtils.java
new file mode 100644 (file)
index 0000000..349e030
--- /dev/null
@@ -0,0 +1,152 @@
+package org.simantics.sysdyn.ui.validation;\r
+\r
+import java.io.StringReader;\r
+import java.text.DateFormat;\r
+import java.text.SimpleDateFormat;\r
+import java.util.Calendar;\r
+import java.util.Collection;\r
+import java.util.HashSet;\r
+import java.util.List;\r
+import java.util.UUID;\r
+\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.issues.ontology.IssueResource;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.expressionParser.ExpressionParser;\r
+import org.simantics.sysdyn.expressionParser.ParseException;\r
+import org.simantics.sysdyn.expressionParser.TokenMgrError;\r
+\r
+public class ValidationUtils {\r
+    \r
+    public static void removeIssue(WriteGraph graph, Resource model, Resource source, Resource variable, Resource issue, Collection<Resource> existing) throws DatabaseException {\r
+        graph.deny(issue, Layer0.getInstance(graph).PartOf);\r
+        graph.deny(source, IssueResource.getInstance(graph).Manages, issue);\r
+        existing.remove(issue);\r
+    }\r
+    \r
+    public static Resource createIssue(WriteGraph graph, Resource model, Resource source, Resource variable, String label) throws DatabaseException {\r
+        return createIssue(graph, model, source, variable, label, IssueResource.getInstance(graph).Severity_Error);\r
+    }\r
+\r
+    \r
+    public static Resource createIssue(WriteGraph graph, Resource model, Resource source, Resource variable, String label, Resource severity) throws DatabaseException {\r
+        return createIssue(graph, model, source, variable, label, severity, SysdynResource.getInstance(graph).SysdynIssue);\r
+    }\r
+\r
+    \r
+    public static Resource createIssue(WriteGraph graph, Resource model, Resource source, Resource variable, String label, Resource severity, Resource type) throws DatabaseException {\r
+        Layer0 L0 = Layer0.getInstance(graph);\r
+        IssueResource ISSUE = IssueResource.getInstance(graph);\r
+\r
+        Resource issue = graph.newResource();\r
+        graph.claim(issue, L0.InstanceOf, null, type);\r
+        graph.claim(issue, ISSUE.HasIssueContext, null, variable);\r
+        graph.claim(issue, ISSUE.HasSeverity, severity);\r
+        graph.claimLiteral(issue, L0.HasLabel, label, Bindings.STRING);\r
+        graph.claimLiteral(issue, L0.HasName, UUID.randomUUID().toString(), Bindings.STRING);\r
+        DateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");\r
+        String created = format.format(Calendar.getInstance().getTime());\r
+        graph.claimLiteral(issue, ISSUE.HasCreationTime, created, Bindings.STRING);\r
+        graph.claim(source, ISSUE.Manages, issue);\r
+        graph.claim(model, L0.ConsistsOf, issue);    \r
+        return issue;\r
+    }\r
+    \r
+    public static HashSet<String> getReferences(ReadGraph graph, Resource r) throws DatabaseException, SyntaxErrorException, UnsupportedCharactersException, UndefinedExpressionException {\r
+        HashSet<String> references = new HashSet<String>();\r
+        ExpressionParser parser = new ExpressionParser(new StringReader(""));\r
+\r
+        SysdynResource sr = SysdynResource.getInstance(graph);\r
+        Layer0 l0 = Layer0.getInstance(graph);\r
+        List<Resource> expressionList = getExpressions(graph, r);\r
+        if(expressionList == null || expressionList.isEmpty())\r
+            throw new UndefinedExpressionException();\r
+        for(Resource expression : expressionList) {\r
+            for(Resource s : graph.syncRequest(new ObjectsWithType(expression, sr.HasEquation, l0.String))) {\r
+                String value = graph.getValue(s, Bindings.STRING);\r
+                if(value.length() == 0)\r
+                    throw new UndefinedExpressionException();\r
+\r
+                parser.ReInit(new StringReader(value));\r
+                try {\r
+                    parser.expr();\r
+                    references.addAll(parser.getReferences().keySet());\r
+                } catch (ParseException e1) {\r
+                    throw new SyntaxErrorException();\r
+                } catch (TokenMgrError err) {\r
+                    throw new UnsupportedCharactersException();\r
+                }\r
+            }\r
+        }\r
+        return references;\r
+    }\r
+    \r
+    private static List<Resource> getExpressions(ReadGraph graph, Resource r) throws DatabaseException {\r
+        SysdynResource sr = SysdynResource.getInstance(graph);\r
+        Resource hasExpressions = graph.getPossibleObject(r, sr.HasExpressions);\r
+        if(hasExpressions != null)\r
+            return OrderedSetUtils.toList(graph, hasExpressions);\r
+        else\r
+            return null;\r
+    }\r
+\r
+    \r
+    /**\r
+     * Returns the names of the related variables (dependencies)\r
+     * \r
+     * @param graph\r
+     * @param r\r
+     * @return\r
+     * @throws DatabaseException\r
+     */\r
+    public static HashSet<String> getDependencies(ReadGraph graph, Resource r) throws DatabaseException {\r
+        HashSet<String> variables = new HashSet<String>();\r
+        if(graph != null && r != null) {\r
+            SysdynResource sr = SysdynResource.getInstance(graph);\r
+            Layer0 l0 = Layer0.getInstance(graph);\r
+\r
+            Collection<Resource> dependencies = graph.getObjects(r, sr.IsHeadOf);\r
+\r
+            for(Resource d : dependencies) {\r
+                if(graph.isInstanceOf(d, sr.Dependency)) {\r
+                    Resource tail = graph.getPossibleObject(d, sr.HasTail);\r
+                    if(tail != null) {\r
+                        Object name = graph.getPossibleRelatedValue(tail, l0.HasName);\r
+                        if(name != null)\r
+                            variables.add((String)name);\r
+                    }\r
+                }\r
+            }\r
+        }\r
+        return variables;\r
+    }\r
+    \r
+    /**\r
+     * Is reference reachable from variable\r
+     * \r
+     * @param graph\r
+     * @param variable\r
+     * @param reference\r
+     * @return\r
+     * @throws DatabaseException\r
+     */\r
+    public static boolean isReachable(ReadGraph graph, Resource variable, String reference) throws DatabaseException {\r
+        Layer0 l0 = Layer0.getInstance(graph);\r
+        SysdynResource sr = SysdynResource.getInstance(graph);\r
+        Resource configuration = graph.getSingleObject(variable, l0.PartOf);\r
+        String varName;\r
+        for(Resource var : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Variable))) {\r
+            varName = graph.getRelatedValue(var, l0.HasName, Bindings.STRING);\r
+            if(varName != null && reference.equals(varName))\r
+                return true;\r
+        }\r
+        return false;\r
+    }\r
+}\r