]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ProxyVariables.java
Merge "Add missing javax.servlet-api bundle requirement for jersey bundles"
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / variable / ProxyVariables.java
index db552650b09c7098074bfd069b954a9b5d80ca15..cd38064a89be00e83c4cf085ad8e83eaa2102c4b 100644 (file)
@@ -2,9 +2,29 @@ package org.simantics.db.layer0.variable;
 
 import org.simantics.db.ReadGraph;
 import org.simantics.db.exception.DatabaseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ProxyVariables {
-       
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(ProxyVariables.class);
+
+    public static Variable tryToOwn(ReadGraph graph, Variable parent, Variable variable) {
+        if (variable instanceof ProxyVariableSupport) {
+            ProxyVariableSupport pvs = (ProxyVariableSupport) variable;
+            return pvs.attachTo(graph, parent);
+        }
+        return null;
+    }
+
+    public static Variable tryToOwnRenamed(ReadGraph graph, Variable parent, Variable variable, String name) {
+        if (variable instanceof ProxyVariableSupport) {
+            ProxyVariableSupport pvs = (ProxyVariableSupport) variable;
+            return pvs.attachToRenamed(graph, parent, name);
+        }
+        return null;
+    }
+
        public static Variable inputVariable(ReadGraph graph, Variable context) throws DatabaseException {
        Variable session = graph.syncRequest(new ProxySessionRequest(context));
        if(session == null) return null;
@@ -32,27 +52,11 @@ public class ProxyVariables {
        }
        
     public static Variable proxySessionVariable(ReadGraph graph, Variable variable) throws DatabaseException {
-       
-       try {
-               
-               Variable child = variable.getParent(graph);
-               Variable parent = child.getParent(graph);
 
-               if(parent instanceof ProxyChildVariable) {
-                       Variable var = ((ProxyChildVariable)parent).other();
-                       if(var.getParent(graph) == null) {
-                               return null;
-                       }
-                       return var;
-               } else {
-                       Variable input = parent.getPossiblePropertyValue(graph, "session");
-                       if(input == null) {
-                           System.out.println("null input for: " + parent.getURI(graph));
-                       }
-                       return input;
-               }
+        try {
+            return proxyVariableInput(graph, variable);
         } catch (Throwable t) {
-            t.printStackTrace();
+            LOGGER.error("proxySessionVariable failed", t);
             return null;
         }
 
@@ -72,7 +76,7 @@ public class ProxyVariables {
                }
                
         } catch (Throwable t) {
-            t.printStackTrace();
+            LOGGER.error("proxyVariableBase failed", t);
             return null;
         }
 
@@ -89,7 +93,7 @@ public class ProxyVariables {
                } else {
                        Variable parent = variable.getParent(graph);
                        if(parent == null) return null;
-                       else return proxyVariableBase(graph, parent);
+                       else return proxyVariableInput(graph, parent);
                }
        
     }
@@ -108,7 +112,7 @@ public class ProxyVariables {
                }
                
         } catch (Throwable t) {
-            t.printStackTrace();
+            LOGGER.error("proxyVariableRoot failed", t);
             return null;
         }
 
@@ -118,5 +122,4 @@ public class ProxyVariables {
        return proxyVariableRoot(graph, variable) != null;
     }
 
-    
 }