Create separate requests for validating SCL values 77/1177/1
authorjsimomaa <jani.simomaa@gmail.com>
Wed, 1 Nov 2017 08:25:36 +0000 (10:25 +0200)
committerjsimomaa <jani.simomaa@gmail.com>
Wed, 1 Nov 2017 08:29:02 +0000 (10:29 +0200)
refs #7575

Change-Id: I47f9402407c0084e6a5f4859c7b05ef5557619b6

bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/scl/AbstractExpressionCompilationRequest.java
bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java
bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLHandlerValueRequest.java
bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java

index b12d0258ede32c4c48e60c287c35250496fa5c77..d40f82d4dc1219055b83fe4c722edff93703d63e 100644 (file)
@@ -1,7 +1,5 @@
 package org.simantics.db.layer0.scl;
 
-import gnu.trove.map.hash.THashMap;
-
 import java.util.ArrayList;
 import java.util.List;
 
@@ -37,6 +35,8 @@ import org.simantics.scl.runtime.SCLContext;
 import org.simantics.scl.runtime.function.Function1;
 import org.simantics.utils.datastructures.Pair;
 
+import gnu.trove.map.hash.THashMap;
+
 /**
  * <p>This is a base implementation for compiling expressions stored into 
  * graph. It provides a skeleton and a set of methods that must be
index a6e9d6ab6818eba35ff09cd6ea5d0549bde1f0aa..9c62924153681a788159cb40c0420468bc415387 100644 (file)
@@ -1312,7 +1312,7 @@ public class Functions {
 
     public static String compileDocumentSCLValueExpression(ReadGraph graph, Variable context) {
         try {
-            ServerSCLValueRequest.compile(graph, context);
+            ServerSCLValueRequest.validate(graph, context);
             return "";
         } catch (Exception e) {
             return resolveIssueMessage(e);
index 286cae2728c9f12660c71e5fe2dc38b934dd0568..4a4164303613c1a2c9d963693804d727305cdb2a 100644 (file)
@@ -22,10 +22,8 @@ import org.simantics.scl.compiler.elaboration.expressions.EVariable;
 import org.simantics.scl.compiler.elaboration.expressions.Expression;
 import org.simantics.scl.compiler.elaboration.modules.SCLValue;
 import org.simantics.scl.compiler.environment.Environment;
-import org.simantics.scl.compiler.environment.Environments;
 import org.simantics.scl.compiler.environment.specification.EnvironmentSpecification;
 import org.simantics.scl.compiler.runtime.RuntimeEnvironment;
-import org.simantics.scl.compiler.top.SCLExpressionCompilationException;
 import org.simantics.scl.compiler.types.TCon;
 import org.simantics.scl.compiler.types.Type;
 import org.simantics.scl.compiler.types.Types;
@@ -36,13 +34,9 @@ import org.simantics.structural2.scl.ComponentTypeProperty;
 import org.simantics.structural2.scl.FindPossibleComponentTypeRequest;
 import org.simantics.structural2.scl.ReadComponentTypeInterfaceRequest;
 import org.simantics.utils.datastructures.Pair;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public class ServerSCLHandlerValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Variable> {
 
-    private static final Logger LOGGER = LoggerFactory.getLogger(ServerSCLHandlerValueRequest.class);
-
        private final Variable context;
        private final Pair<Resource,Resource> componentTypeAndRoot;
        private final Resource literal;
@@ -230,17 +224,9 @@ public class ServerSCLHandlerValueRequest extends AbstractExpressionCompilationR
 
     @Override
     protected Type getExpectedType(ReadGraph graph, CompilationContext context) throws DatabaseException {
-        if(possibleExpectedValueType != null) {
-            try {
-                return Environments.getType(context.runtimeEnvironment.getEnvironment(), possibleExpectedValueType);
-            } catch (SCLExpressionCompilationException e) {
-                LOGGER.error("Could not get type for " + String.valueOf(possibleExpectedValueType), e);
-            }
-        }
         return super.getExpectedType(graph, context);
     }
 
-
        @Override
        public int hashCode() {
                final int prime = 31;
index b4d4d2c1fc2970b567541240a9c706a63b502262..f9181d271073964b6082fef5119a679e8c371075 100644 (file)
@@ -42,8 +42,6 @@ import org.slf4j.LoggerFactory;
 
 public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest<CompilationContext, Variable> {
 
-    private static final Logger LOGGER = LoggerFactory.getLogger(ServerSCLValueRequest.class);
-    
        private final Pair<Resource,Resource> componentTypeAndRoot;
        private final Resource literal;
     protected String possibleExpectedValueType;
@@ -206,13 +204,6 @@ public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest<
        
     @Override
     protected Type getExpectedType(ReadGraph graph, CompilationContext context) throws DatabaseException {
-        if(possibleExpectedValueType != null) {
-            try {
-                return Environments.getType(context.runtimeEnvironment.getEnvironment(), possibleExpectedValueType);
-            } catch (SCLExpressionCompilationException e) {
-                LOGGER.error("Could not get type for " + String.valueOf(possibleExpectedValueType), e);
-            }
-        }
         return super.getExpectedType(graph, context);
     }
 
@@ -231,4 +222,29 @@ public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest<
                ServerSCLValueRequest other = (ServerSCLValueRequest)obj;
                return literal.equals(other.literal) && componentTypeAndRoot.equals(other.componentTypeAndRoot);
        }
+
+    public static Function1<Variable, Object> validate(ReadGraph graph, Variable context) throws DatabaseException {
+        return graph.syncRequest(new ServerSCLValueValidationRequest(graph, context), TransientCacheListener.<Function1<Variable,Object>>instance());
+    }
+    
+    public static class ServerSCLValueValidationRequest extends ServerSCLValueRequest {
+
+        private static final Logger LOGGER = LoggerFactory.getLogger(ServerSCLHandlerValueRequest.class);
+
+        public ServerSCLValueValidationRequest(ReadGraph graph, Variable context) throws DatabaseException {
+            super(graph, context);
+        }
+
+        @Override
+        protected Type getExpectedType(ReadGraph graph, CompilationContext context) throws DatabaseException {
+            if(possibleExpectedValueType != null) {
+                try {
+                    return Environments.getType(context.runtimeEnvironment.getEnvironment(), possibleExpectedValueType);
+                } catch (SCLExpressionCompilationException e) {
+                    LOGGER.error("Could not get type for " + String.valueOf(possibleExpectedValueType), e);
+                }
+            }
+            return super.getExpectedType(graph, context);
+        }
+    }
 }