]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Documented difference of RuntimeEnvironmentRequest and Runti...quest2 86/2286/1
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Tue, 9 Oct 2018 07:20:50 +0000 (10:20 +0300)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Tue, 9 Oct 2018 07:20:50 +0000 (10:20 +0300)
Removed also all cosmetic differences between the classes to make
comparison possible.

Change-Id: I83e96d09a6e33594a9076df83de887b733d4de46

bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/RuntimeEnvironmentRequest.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/RuntimeEnvironmentRequest2.java

index cde4e02396a48515a31ca777e1265870e8903cc8..9f6b8fe530799439bcad7f3d9fab82319fc2733a 100644 (file)
@@ -26,36 +26,36 @@ public class RuntimeEnvironmentRequest extends UnaryRead<Resource, RuntimeEnviro
     public RuntimeEnvironmentRequest(Resource parameter) {
         super(parameter);
     }
-    
+
     protected void fillEnvironmentSpecification(EnvironmentSpecification environmentSpecification) {
     }
 
     static class UpdateListenerImpl extends UpdateListener {
-               
-       final EnvironmentSpecification environmentSpecification;
-       final Listener<RuntimeEnvironment> callback;
-       
-       UpdateListenerImpl(EnvironmentSpecification environmentSpecification, Listener<RuntimeEnvironment> callback) {
-               this.environmentSpecification = environmentSpecification;
-               this.callback = callback;
-       }
+
+        final EnvironmentSpecification environmentSpecification;
+        final Listener<RuntimeEnvironment> callback;
+
+        UpdateListenerImpl(EnvironmentSpecification environmentSpecification, Listener<RuntimeEnvironment> callback) {
+            this.environmentSpecification = environmentSpecification;
+            this.callback = callback;
+        }
 
         @Override
         public void notifyAboutUpdate() {
-               if(callback.isDisposed()) {
-                   stopListening();
-                       return;
-               }
-               getRuntimeEnvironment(environmentSpecification, callback, this);
+            if(callback.isDisposed()) {
+                stopListening();
+                return;
+            }
+            getRuntimeEnvironment(environmentSpecification, callback, this);
         }
-    };     
+    };
 
     public static void getRuntimeEnvironment(EnvironmentSpecification environmentSpecification, Listener<RuntimeEnvironment> callback, UpdateListenerImpl listener) {
 
         try {
-            
+
             SCLContext context = SCLContext.getCurrent();
-            
+
             RuntimeEnvironment env;
             Object graph = context.get("graph");
             if(graph == null)
@@ -63,7 +63,7 @@ public class RuntimeEnvironmentRequest extends UnaryRead<Resource, RuntimeEnviro
                     env = SimanticsInternal.getSession().syncRequest(new Read<RuntimeEnvironment>() {
                         @Override
                         public RuntimeEnvironment perform(ReadGraph graph) throws DatabaseException {
-                            
+
                             SCLContext sclContext = SCLContext.getCurrent();
                             Object oldGraph = sclContext.get("graph");
                             try {
@@ -94,7 +94,7 @@ public class RuntimeEnvironmentRequest extends UnaryRead<Resource, RuntimeEnviro
         }
 
     }
-    
+
     @Override
     public RuntimeEnvironment perform(ReadGraph graph)
             throws DatabaseException {
@@ -103,6 +103,7 @@ public class RuntimeEnvironmentRequest extends UnaryRead<Resource, RuntimeEnviro
                 "StandardLibrary", "",
                 "Simantics/All", "");
         fillEnvironmentSpecification(environmentSpecification);
+
         Resource mainModule = Layer0Utils.getPossibleChild(graph, parameter, "SCLMain");
         String mainModuleUri;
         if(mainModule != null) {
@@ -111,40 +112,40 @@ public class RuntimeEnvironmentRequest extends UnaryRead<Resource, RuntimeEnviro
         }
         else
             mainModuleUri = graph.getURI(parameter) + "/#"; // Add something dummy to the model uri that cannot be in a real URI
-        
-            return graph.syncRequest(new ParametrizedPrimitiveRead<String, RuntimeEnvironment>(mainModuleUri) {
-                
-                UpdateListenerImpl sclListener;
-                
-               @Override
-               public void register(ReadGraph graph, Listener<RuntimeEnvironment> procedure) {
-
-                       SCLContext context = SCLContext.getCurrent();
-                       Object oldGraph = context.put("graph", graph);
-                       try {
-
-                               if(procedure.isDisposed()) {
-                                       getRuntimeEnvironment(environmentSpecification, procedure, null);
-                               } else {
-                                   sclListener = new UpdateListenerImpl(environmentSpecification, procedure);
-                                   sclListener.notifyAboutUpdate();
-                                       }
-
-                       } finally {
-                               context.put("graph", oldGraph);
-                       }
-
-               }
-                
-                @Override
-                public void unregistered() {
-                       if(sclListener != null)
-                           sclListener.stopListening();
+
+        return graph.syncRequest(new ParametrizedPrimitiveRead<String, RuntimeEnvironment>(mainModuleUri) {
+
+            UpdateListenerImpl sclListener;
+
+            @Override
+            public void register(ReadGraph graph, Listener<RuntimeEnvironment> procedure) {
+
+                SCLContext context = SCLContext.getCurrent();
+                Object oldGraph = context.put("graph", graph);
+                try {
+
+                    if(procedure.isDisposed()) {
+                        getRuntimeEnvironment(environmentSpecification, procedure, null);
+                    } else {
+                        sclListener = new UpdateListenerImpl(environmentSpecification, procedure);
+                        sclListener.notifyAboutUpdate();
+                    }
+
+                } finally {
+                    context.put("graph", oldGraph);
                 }
-                
-            });
+
+            }
+
+            @Override
+            public void unregistered() {
+                if(sclListener != null)
+                    sclListener.stopListening();
+            }
+
+        });
     }
-    
+
     @Override
     public int hashCode() {
         return 31*getClass().hashCode() + super.hashCode();
index 4bbd480020141b5e602c9e7f73fb1b8170410995..ca8bc07cd53ab9a3b73d05a02e73d7473ae7db2a 100644 (file)
@@ -1,8 +1,6 @@
 package org.simantics.db.layer0.util;
 
 import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
 
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
@@ -26,13 +24,17 @@ import org.simantics.scl.runtime.SCLContext;
  * 
  * @author Hannu Niemist&ouml;
  * @author Antti Villberg
+ * 
+ * Difference between this class and {@code RuntimeEnvironmentRequest} is an additional parameter
+ * that is typically some component type. All modules under this resource are added to the environment
+ * in addition to the SCLMain of the root resource. 
  */
 public class RuntimeEnvironmentRequest2 extends BinaryRead<Resource, Resource, RuntimeEnvironment> {
 
-    public RuntimeEnvironmentRequest2(Resource parameter, Resource parameter2) {
-        super(parameter, parameter2);
+    public RuntimeEnvironmentRequest2(Resource componentType, Resource indexRoot) {
+        super(componentType, indexRoot);
     }
-    
+
     protected void fillEnvironmentSpecification(EnvironmentSpecification environmentSpecification) {
     }
 
@@ -56,7 +58,7 @@ public class RuntimeEnvironmentRequest2 extends BinaryRead<Resource, Resource, R
         }
     };
 
-    final public static void getRuntimeEnvironment(EnvironmentSpecification environmentSpecification, Listener<RuntimeEnvironment> callback, UpdateListenerImpl listener) {
+    public static void getRuntimeEnvironment(EnvironmentSpecification environmentSpecification, Listener<RuntimeEnvironment> callback, UpdateListenerImpl listener) {
 
         try {
 
@@ -120,7 +122,9 @@ public class RuntimeEnvironmentRequest2 extends BinaryRead<Resource, Resource, R
             environmentSpecification.importModule(graph.getURI(mainModule), "");
 
         return graph.syncRequest(new ParametrizedPrimitiveRead<EnvironmentSpecification, RuntimeEnvironment>(environmentSpecification) {
+
             UpdateListenerImpl sclListener;
+
             @Override
             public void register(ReadGraph graph, Listener<RuntimeEnvironment> procedure) {
 
@@ -155,4 +159,4 @@ public class RuntimeEnvironmentRequest2 extends BinaryRead<Resource, Resource, R
         return 31*getClass().hashCode() + super.hashCode();
     }
 
-}
\ No newline at end of file
+}