1 package org.simantics.db.layer0.variable;
3 import org.simantics.db.ReadGraph;
4 import org.simantics.db.exception.DatabaseException;
6 public class ProxyVariables {
8 public static Variable inputVariable(ReadGraph graph, Variable context) throws DatabaseException {
9 Variable session = graph.syncRequest(new ProxySessionRequest(context));
10 if(session == null) return null;
11 String uri = session.getPossiblePropertyValue(graph, "inputURI");
13 // TODO HAXX - Please fix this
14 // we have no URI so this probably means that someone has inserted a non-session
15 // into the proxy variable => return that instead
18 return Variables.getVariable(graph, uri);
21 public static Variable sessionVariable(ReadGraph graph, Variable self) throws DatabaseException {
22 return graph.syncRequest(new ProxySessionRequest(self));
25 public static Variable makeProxyVariable(ReadGraph graph, Variable base, Variable input) throws DatabaseException {
27 base = base.getChild(graph, ProxyChildVariable.CONTEXT_BEGIN);
28 String path = input.getURI(graph).substring("http:/".length());
29 base = base.browse(graph, path);
30 return base.getChild(graph, ProxyChildVariable.CONTEXT_END);
34 public static Variable proxySessionVariable(ReadGraph graph, Variable variable) throws DatabaseException {
38 Variable child = variable.getParent(graph);
39 Variable parent = child.getParent(graph);
41 if(parent instanceof ProxyChildVariable) {
42 Variable var = ((ProxyChildVariable)parent).other();
43 if(var.getParent(graph) == null) {
48 Variable input = parent.getPossiblePropertyValue(graph, "session");
50 System.out.println("null input for: " + parent.getURI(graph));
54 } catch (Throwable t) {
61 public static Variable proxyVariableBase(ReadGraph graph, Variable variable) throws DatabaseException {
65 Variable parent = variable.getParent(graph);
66 if(parent == null) return null;
68 if(parent instanceof ProxyChildVariable) {
69 return ((ProxyChildVariable)parent).base();
71 return proxyVariableBase(graph, parent);
74 } catch (Throwable t) {
81 public static Variable proxyVariableInput(ReadGraph graph, Variable variable) throws DatabaseException {
83 if(variable instanceof ProxyChildVariable) {
84 Variable var = ((ProxyChildVariable)variable).other();
85 if(var.getParent(graph) == null) {
90 Variable parent = variable.getParent(graph);
91 if(parent == null) return null;
92 else return proxyVariableBase(graph, parent);
97 public static Variable proxyVariableRoot(ReadGraph graph, Variable variable) throws DatabaseException {
101 Variable parent = variable.getParent(graph);
102 if(parent == null) return null;
104 if(parent instanceof ProxyChildVariable) {
107 return proxyVariableRoot(graph, parent);
110 } catch (Throwable t) {
117 public static boolean isProxy(ReadGraph graph, Variable variable) throws DatabaseException {
118 return proxyVariableRoot(graph, variable) != null;