]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/validation/ValidationUtils.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / validation / ValidationUtils.java
index b5ea24686b4daeb7f2c7111bc14b748d348dfee9..673eeaee5847e0bbc2c9dfba59f0038cc2143e0d 100644 (file)
@@ -1,81 +1,81 @@
-package org.simantics.db.layer0.validation;\r
-\r
-import gnu.trove.set.hash.THashSet;\r
-\r
-import java.util.Collections;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.Set;\r
-\r
-import org.simantics.db.Issue;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.utils.Functions;\r
-import org.simantics.db.common.utils.Logger;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.adapter.SubgraphExtent.ExtentStatus;\r
-import org.simantics.db.layer0.util.DomainProcessor3;\r
-import org.simantics.db.layer0.util.ModelTransferableGraphSourceRequest;\r
-import org.simantics.layer0.Layer0;\r
-\r
-public class ValidationUtils {\r
-\r
-    /**\r
-     * Performs L0.Constraint validations for the specified resource and puts\r
-     * the resulting issues in the specified {@link Issue} set. If the specified\r
-     * issue set is <code>null</code>, a new set will be created and returned.\r
-     * Otherwise the method function will return the same set as its return\r
-     * value.\r
-     * \r
-     * @param graph\r
-     *            database read access handle\r
-     * @param r\r
-     *            resource to validate against ontology-defined constraints\r
-     * @param result\r
-     *            a set for the resulting issues or <code>null</code> to\r
-     *            allocate a new set if necessary\r
-     * @return the discovered set of issues in <code>r</code>\r
-     * @throws DatabaseException\r
-     */\r
-    public static Set<Issue> validateConstraints(ReadGraph graph, Resource r, Set<Issue> result) throws DatabaseException {\r
-        Layer0 L0 = Layer0.getInstance(graph);\r
-\r
-        for (Resource constraint : graph.syncRequest(new GetConstraints(r))) {\r
-            try {\r
-                Resource function = graph.getSingleObject(constraint, L0.Constraint_Validator);\r
-                @SuppressWarnings("unchecked")\r
-                List<Issue> issues = (List<Issue>)Functions.exec(graph, function, graph, r);\r
-                if (issues != null && !issues.isEmpty()) {\r
-                    if (result == null)\r
-                        result = new THashSet<Issue>();\r
-                    result.addAll(issues);\r
-                }\r
-            } catch (Throwable t) {\r
-                Logger.defaultLogError(t);\r
-            }\r
-        }\r
-\r
-        return result != null ? result : Collections.<Issue>emptySet();\r
-    }\r
-\r
-    public static Set<Issue> validateConstraints(ReadGraph graph, Resource r) throws DatabaseException {\r
-        return validateConstraints(graph, r, null);\r
-    }\r
-\r
-    public static Set<Issue> validateConstraintsForDomain(ReadGraph graph, Resource r) throws DatabaseException {\r
-        Set<Issue> result = null;\r
-\r
-        DomainProcessor3 dp = ModelTransferableGraphSourceRequest.getDomainOnly(graph, null, r);\r
-        for(Map.Entry<Resource,ExtentStatus> status : dp.getStatus().entrySet()) {\r
-            if(ExtentStatus.INTERNAL.equals(status.getValue())) {\r
-                Resource rr = status.getKey();\r
-                Set<Issue> issues = validateConstraints(graph, rr, result);\r
-                if (!issues.isEmpty())\r
-                    result = issues;\r
-            }\r
-        }\r
-\r
-        return result != null ? result : Collections.<Issue>emptySet();\r
-    }\r
-\r
-}\r
+package org.simantics.db.layer0.validation;
+
+import gnu.trove.set.hash.THashSet;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.simantics.db.Issue;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.utils.Functions;
+import org.simantics.db.common.utils.Logger;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.SubgraphExtent.ExtentStatus;
+import org.simantics.db.layer0.util.DomainProcessor3;
+import org.simantics.db.layer0.util.ModelTransferableGraphSourceRequest;
+import org.simantics.layer0.Layer0;
+
+public class ValidationUtils {
+
+    /**
+     * Performs L0.Constraint validations for the specified resource and puts
+     * the resulting issues in the specified {@link Issue} set. If the specified
+     * issue set is <code>null</code>, a new set will be created and returned.
+     * Otherwise the method function will return the same set as its return
+     * value.
+     * 
+     * @param graph
+     *            database read access handle
+     * @param r
+     *            resource to validate against ontology-defined constraints
+     * @param result
+     *            a set for the resulting issues or <code>null</code> to
+     *            allocate a new set if necessary
+     * @return the discovered set of issues in <code>r</code>
+     * @throws DatabaseException
+     */
+    public static Set<Issue> validateConstraints(ReadGraph graph, Resource r, Set<Issue> result) throws DatabaseException {
+        Layer0 L0 = Layer0.getInstance(graph);
+
+        for (Resource constraint : graph.syncRequest(new GetConstraints(r))) {
+            try {
+                Resource function = graph.getSingleObject(constraint, L0.Constraint_Validator);
+                @SuppressWarnings("unchecked")
+                List<Issue> issues = (List<Issue>)Functions.exec(graph, function, graph, r);
+                if (issues != null && !issues.isEmpty()) {
+                    if (result == null)
+                        result = new THashSet<Issue>();
+                    result.addAll(issues);
+                }
+            } catch (Throwable t) {
+                Logger.defaultLogError(t);
+            }
+        }
+
+        return result != null ? result : Collections.<Issue>emptySet();
+    }
+
+    public static Set<Issue> validateConstraints(ReadGraph graph, Resource r) throws DatabaseException {
+        return validateConstraints(graph, r, null);
+    }
+
+    public static Set<Issue> validateConstraintsForDomain(ReadGraph graph, Resource r) throws DatabaseException {
+        Set<Issue> result = null;
+
+        DomainProcessor3 dp = ModelTransferableGraphSourceRequest.getDomainOnly(graph, null, r);
+        for(Map.Entry<Resource,ExtentStatus> status : dp.getStatus().entrySet()) {
+            if(ExtentStatus.INTERNAL.equals(status.getValue())) {
+                Resource rr = status.getKey();
+                Set<Issue> issues = validateConstraints(graph, rr, result);
+                if (!issues.isEmpty())
+                    result = issues;
+            }
+        }
+
+        return result != null ? result : Collections.<Issue>emptySet();
+    }
+
+}