-package org.simantics.graph.compiler.internal.validation;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.concurrent.Callable;\r
-\r
-import org.simantics.graph.compiler.GraphCompilerPreferences;\r
-import org.simantics.graph.compiler.ValidationMode;\r
-import org.simantics.graph.compiler.internal.store.LocationStore;\r
-import org.simantics.graph.query.CompositeGraph;\r
-import org.simantics.graph.query.Path;\r
-import org.simantics.graph.query.Paths;\r
-import org.simantics.graph.query.Res;\r
-import org.simantics.graph.store.GraphStore;\r
-import org.simantics.graph.store.IdRes;\r
-import org.simantics.graph.utils.GraphExecutor;\r
-import org.simantics.ltk.Location;\r
-import org.simantics.ltk.Problem;\r
-\r
-public class ValidateGraph implements Runnable {\r
- CompositeGraph graph;\r
- Collection<Problem> problems;\r
- GraphStore store;\r
- GraphCompilerPreferences preferences;\r
- Paths paths;\r
-\r
- public ValidateGraph(CompositeGraph graph,\r
- Collection<Problem> problems,\r
- GraphStore store,\r
- GraphCompilerPreferences preferences) {\r
- this.graph = graph;\r
- this.problems = problems;\r
- this.store = store;\r
- this.preferences = preferences;\r
- this.paths = graph.getPaths();\r
- }\r
- \r
- private void emit(int id, ValidationMode mode, String message) {\r
- LocationStore locations = store.getStore(LocationStore.class);\r
- Location location = locations.getLocation(id);\r
- Problem problem = new Problem(location, message);\r
- synchronized(problems) { \r
- problems.add(problem);\r
- }\r
- }\r
-\r
- public void validate(int id, Res resource) {\r
- if(!graph.rawGetObjects(resource, paths.SubrelationOf).isEmpty()) {\r
- for(Res res : graph.rawGetObjects(resource, paths.InverseOf)) {\r
- if(resource instanceof IdRes && res instanceof Path)\r
- emit(id, ValidationMode.ERROR, "Resource " + resource + " doesn't have URI but its inverse has.");\r
- if(res instanceof IdRes && resource instanceof Path) {\r
- emit(store.resToId(res), ValidationMode.ERROR, "Resource " + res + " doesn't have URI but its inverse has.");\r
- }\r
- } \r
- }\r
- else {\r
- if(preferences.validateResourceHasType != ValidationMode.IGNORE) {\r
- if(!graph.rawGetObjects(resource, paths.InstanceOf).isEmpty()) {\r
- }\r
- else if(!graph.rawGetObjects(resource, paths.Inherits).isEmpty()) { \r
- }\r
- else\r
- emit(id, preferences.validateResourceHasType, "Resource " + resource + " does not have a type, it has to instantiate or inherit some other resource.");\r
- }\r
- }\r
- /*if(preferences.validateRelationRestrictions != ValidationMode.IGNORE) {\r
- store.statements.forStatementsWithSubject(id, new IStatementProcedure() {\r
- @Override\r
- public void execute(int s, int p, int o) {\r
- \r
- }\r
- });\r
- }*/\r
- }\r
-\r
- @Override\r
- public void run() {\r
- int resourceCount = store.identities.getResourceCount();\r
- int segmentLength = Math.max(256, resourceCount / GraphExecutor.EXECUTOR_THREADS / 4 + 1);\r
- ArrayList<Callable<Object>> tasks = new ArrayList<Callable<Object>>();\r
- for(int segmentStart_ = 0;segmentStart_ < resourceCount;segmentStart_ += segmentLength) {\r
- final int segmentStart = segmentStart_;\r
- final int segmentEnd = Math.min(segmentStart + segmentLength, resourceCount);\r
- tasks.add(new Callable<Object>() {\r
- @Override\r
- public Object call() {\r
- for(int id = segmentStart;id<segmentEnd;++id) {\r
- Res res = store.idToRes(id);\r
- if(res instanceof Path) {\r
- if(store.identities.isNewResource(id)) {\r
- if(graph.countOccurences(res) > 1) {\r
- emit(id, ValidationMode.ERROR, "Resource " + res + " is already defined in dependencies, but it is marked new in this graph.");\r
- continue;\r
- }\r
- }\r
- else {\r
- if(graph.countOccurences(res) <= 1) {\r
- emit(id, ValidationMode.ERROR, "Resource " + res + " is not defined in dependencies and it is not marked new in this graph.");\r
- continue;\r
- }\r
- }\r
- } \r
- validate(id, res);\r
- }\r
- return null;\r
- }\r
- }); \r
- }\r
- try {\r
- GraphExecutor.EXECUTOR.invokeAll(tasks);\r
- } catch (InterruptedException e) {\r
- throw new RuntimeException(e);\r
- }\r
- }\r
- \r
-}\r
+package org.simantics.graph.compiler.internal.validation;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.concurrent.Callable;
+
+import org.simantics.graph.compiler.GraphCompilerPreferences;
+import org.simantics.graph.compiler.ValidationMode;
+import org.simantics.graph.compiler.internal.store.LocationStore;
+import org.simantics.graph.query.CompositeGraph;
+import org.simantics.graph.query.Path;
+import org.simantics.graph.query.Paths;
+import org.simantics.graph.query.Res;
+import org.simantics.graph.store.GraphStore;
+import org.simantics.graph.store.IdRes;
+import org.simantics.graph.utils.GraphExecutor;
+import org.simantics.ltk.Location;
+import org.simantics.ltk.Problem;
+
+public class ValidateGraph implements Runnable {
+ CompositeGraph graph;
+ Collection<Problem> problems;
+ GraphStore store;
+ GraphCompilerPreferences preferences;
+ Paths paths;
+
+ public ValidateGraph(CompositeGraph graph,
+ Collection<Problem> problems,
+ GraphStore store,
+ GraphCompilerPreferences preferences) {
+ this.graph = graph;
+ this.problems = problems;
+ this.store = store;
+ this.preferences = preferences;
+ this.paths = graph.getPaths();
+ }
+
+ private void emit(int id, ValidationMode mode, String message) {
+ LocationStore locations = store.getStore(LocationStore.class);
+ Location location = locations.getLocation(id);
+ Problem problem = new Problem(location, message);
+ synchronized(problems) {
+ problems.add(problem);
+ }
+ }
+
+ public void validate(int id, Res resource) {
+ if(!graph.rawGetObjects(resource, paths.SubrelationOf).isEmpty()) {
+ for(Res res : graph.rawGetObjects(resource, paths.InverseOf)) {
+ if(resource instanceof IdRes && res instanceof Path)
+ emit(id, ValidationMode.ERROR, "Resource " + resource + " doesn't have URI but its inverse has.");
+ if(res instanceof IdRes && resource instanceof Path) {
+ emit(store.resToId(res), ValidationMode.ERROR, "Resource " + res + " doesn't have URI but its inverse has.");
+ }
+ }
+ }
+ else {
+ if(preferences.validateResourceHasType != ValidationMode.IGNORE) {
+ if(!graph.rawGetObjects(resource, paths.InstanceOf).isEmpty()) {
+ }
+ else if(!graph.rawGetObjects(resource, paths.Inherits).isEmpty()) {
+ }
+ else
+ emit(id, preferences.validateResourceHasType, "Resource " + resource + " does not have a type, it has to instantiate or inherit some other resource.");
+ }
+ }
+ /*if(preferences.validateRelationRestrictions != ValidationMode.IGNORE) {
+ store.statements.forStatementsWithSubject(id, new IStatementProcedure() {
+ @Override
+ public void execute(int s, int p, int o) {
+
+ }
+ });
+ }*/
+ }
+
+ @Override
+ public void run() {
+ int resourceCount = store.identities.getResourceCount();
+ int segmentLength = Math.max(256, resourceCount / GraphExecutor.EXECUTOR_THREADS / 4 + 1);
+ ArrayList<Callable<Object>> tasks = new ArrayList<Callable<Object>>();
+ for(int segmentStart_ = 0;segmentStart_ < resourceCount;segmentStart_ += segmentLength) {
+ final int segmentStart = segmentStart_;
+ final int segmentEnd = Math.min(segmentStart + segmentLength, resourceCount);
+ tasks.add(new Callable<Object>() {
+ @Override
+ public Object call() {
+ for(int id = segmentStart;id<segmentEnd;++id) {
+ Res res = store.idToRes(id);
+ if(res instanceof Path) {
+ if(store.identities.isNewResource(id)) {
+ if(graph.countOccurences(res) > 1) {
+ emit(id, ValidationMode.ERROR, "Resource " + res + " is already defined in dependencies, but it is marked new in this graph.");
+ continue;
+ }
+ }
+ else {
+ if(graph.countOccurences(res) <= 1) {
+ emit(id, ValidationMode.ERROR, "Resource " + res + " is not defined in dependencies and it is not marked new in this graph.");
+ continue;
+ }
+ }
+ }
+ validate(id, res);
+ }
+ return null;
+ }
+ });
+ }
+ try {
+ GraphExecutor.EXECUTOR.invokeAll(tasks);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}