]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java
Create separate requests for validating SCL values
[simantics/platform.git] / bundles / org.simantics.document.server / src / org / simantics / document / server / request / ServerSCLValueRequest.java
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);
+        }
+    }
 }