]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Fix server SCL handler value request for procedural user components 87/2787/2
authorjsimomaa <jani.simomaa@gmail.com>
Tue, 19 Mar 2019 08:27:17 +0000 (10:27 +0200)
committerJani Simomaa <jani.simomaa@semantum.fi>
Tue, 19 Mar 2019 15:04:03 +0000 (15:04 +0000)
gitlab #277

Change-Id: Iedfbcec6411f98a197eff947673c0400fcd0d4b8

bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLHandlerValueRequest.java

index ab5e7a8e40e985a8a52e4b3b81b5013eaf621def..8ca55eaa5ab67affe0460dcd7ff0c2ff4a81d277 100644 (file)
@@ -1,5 +1,6 @@
 package org.simantics.document.server.request;
 
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
@@ -65,7 +66,7 @@ public class ServerSCLHandlerValueRequest extends AbstractExpressionCompilationR
        }
 
        public ServerSCLHandlerValueRequest(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException {
-               this(getComponentTypeAndRoot(graph, s), o, resolveExpectedValueType(graph, p));
+               this(getComponentTypeAndRoot(graph, s, o), o, resolveExpectedValueType(graph, p));
        }
 
        private static Pair<Resource,Resource> getComponentTypeAndRoot(ReadGraph graph, Variable property)  throws DatabaseException {
@@ -83,7 +84,7 @@ public class ServerSCLHandlerValueRequest extends AbstractExpressionCompilationR
                return Pair.make(parent.getType(graph), root);
        }
 
-       private static Pair<Resource,Resource> getComponentTypeAndRoot(ReadGraph graph, Resource component)  throws DatabaseException {
+       private static Pair<Resource,Resource> getComponentTypeAndRoot(ReadGraph graph, Resource component, Resource literal)  throws DatabaseException {
                if(component != null) {
                        Resource type = graph.syncRequest(new FindPossibleComponentTypeRequest(component));
                        if(type != null) {
@@ -95,8 +96,15 @@ public class ServerSCLHandlerValueRequest extends AbstractExpressionCompilationR
                                Resource root = graph.syncRequest(new IndexRoot(doc));
                                return Pair.make(componentType, root);
                        }
+                       // TODO: For Antti to consider and fix later
+                       // Introduced to handle procedural user components where component == null
+               } else if (literal != null) {
+                   Resource root = graph.syncRequest(new IndexRoot(literal));
+                   return Pair.make(null, root);
+               } else {
+                   throw new DatabaseException("Couldn't resolve component type and root for component == null && literal == null");
                }
-               throw new IllegalStateException();
+               //throw new IllegalStateException();
        }
 
     public static List<TCon> getEffects(ReadGraph graph, Variable context) throws DatabaseException {
@@ -158,9 +166,19 @@ public class ServerSCLHandlerValueRequest extends AbstractExpressionCompilationR
                        @Override
                        public CompilationContext perform(ReadGraph graph) throws DatabaseException {
                                RuntimeEnvironment runtimeEnvironment = graph.syncRequest(getRuntimeEnvironmentRequest(parameter.first, parameter.second));
-                               Map<String, ComponentTypeProperty> propertyMap =
-                                               graph.syncRequest(new ReadComponentTypeInterfaceRequest(parameter.first, runtimeEnvironment.getEnvironment()),
-                                                               TransientCacheListener.<Map<String, ComponentTypeProperty>>instance());
+                Map<String, ComponentTypeProperty> propertyMap;
+                if (parameter.first != null) {
+                    propertyMap =
+                        graph.syncRequest(new ReadComponentTypeInterfaceRequest(parameter.first, runtimeEnvironment.getEnvironment()),
+                                TransientCacheListener.<Map<String, ComponentTypeProperty>>instance());
+                } else {
+                    // TODO: Antti to consider
+                    // To handle procedural user components
+                    propertyMap = Collections.emptyMap();
+                }
+//                             Map<String, ComponentTypeProperty> propertyMap =
+//                                             graph.syncRequest(new ReadComponentTypeInterfaceRequest(parameter.first, runtimeEnvironment.getEnvironment()),
+//                                                             TransientCacheListener.<Map<String, ComponentTypeProperty>>instance());
                                return new CompilationContext(runtimeEnvironment, propertyMap);
                        }
                });