import org.simantics.db.RequestProcessor;
import org.simantics.db.Resource;
import org.simantics.db.common.NamedResource;
-import org.simantics.db.common.procedure.adapter.ListenerAdapter;
+import org.simantics.db.common.procedure.adapter.ProcedureAdapter;
import org.simantics.db.common.request.BinaryRead;
import org.simantics.db.common.request.ParametrizedPrimitiveRead;
import org.simantics.db.common.request.ResourceRead;
import org.simantics.db.common.request.UnaryRead;
import org.simantics.db.exception.AssumptionException;
import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.layer0.exception.VariableException;
+import org.simantics.db.layer0.exception.InvalidVariableException;
import org.simantics.db.layer0.request.VariableName;
import org.simantics.db.layer0.request.VariableURI;
import org.simantics.db.layer0.variable.Variable;
import org.simantics.db.layer0.variable.VariableBuilder;
import org.simantics.db.layer0.variable.Variables;
import org.simantics.db.procedure.Listener;
+import org.simantics.db.procedure.Procedure;
import org.simantics.layer0.Layer0;
import org.simantics.scenegraph.INode;
import org.simantics.scenegraph.LoaderNode;
import org.simantics.utils.datastructures.Pair;
import org.simantics.utils.threads.IThreadWorkQueue;
import org.simantics.utils.threads.ThreadUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class ScenegraphLoaderUtils {
-
- static Map<Pair<Variable, String>, Collection<Listener<Object>>> externalMap = new HashMap<Pair<Variable, String>, Collection<Listener<Object>>>();
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ScenegraphLoaderUtils.class);
+ static Map<Pair<Variable, String>, Collection<Procedure<Object>>> externalMap = new HashMap<Pair<Variable, String>, Collection<Procedure<Object>>>();
static Map<Pair<Variable, String>, Object> externalValueMap = new HashMap<Pair<Variable, String>, Object>();
final public static class ScenegraphPropertyReference<T> {
public void register(ReadGraph graph, final Listener<T> procedure) {
Object value = externalValueMap.get(parameter);
procedure.execute((T)value);
- Collection<Listener<Object>> listeners = externalMap.get(parameter);
+ Collection<Procedure<Object>> listeners = externalMap.get(parameter);
if(listeners == null) {
- listeners = new ArrayList<Listener<Object>>();
+ listeners = new ArrayList<Procedure<Object>>();
externalMap.put(parameter, listeners);
}
- listeners.add(new ListenerAdapter<Object>() {
+ listeners.add(new ProcedureAdapter<Object>() {
@Override
public void execute(Object result) {
}
public static Resource getRuntime(ReadGraph graph, Variable context) throws DatabaseException {
- SceneGraphContext vc = getContext(graph, context);
- if(vc != null) return vc.getRuntime();
- Variable parent = context.getParent(graph);
- if(parent == null) throw new DatabaseException("Runtime resource was not found from context Variable.");
- return getRuntime(graph, parent);
+ SceneGraphContext vc = getContext(graph, context);
+ if (vc != null)
+ return vc.getRuntime();
+ Variable parent = context.getParent(graph);
+ if (parent == null)
+ throw new InvalidVariableException("Runtime resource was not found from context Variable. " + context.getURI(graph));
+ return getRuntime(graph, parent);
}
public static SceneGraphContext getContext(ReadGraph graph, Variable context) throws DatabaseException {
public Boolean apply(String property, Object value) {
Pair<Variable, String> key = Pair.make(reference.first, reference.second + "#" + property);
externalValueMap.put(key, value);
- Collection<Listener<Object>> listeners = externalMap.get(key);
+ Collection<Procedure<Object>> listeners = externalMap.get(key);
if(listeners != null) {
- for(Listener<Object> listener : listeners) listener.execute(value);
+ for(Procedure<Object> listener : listeners) listener.execute(value);
}
return true;
}
}
- public static Variable getVariableSelection(ReadGraph graph, Variable context) throws DatabaseException {
-
- Variable runtimeVariable = getRuntimeVariable(graph, context);
- if (runtimeVariable == null)
- throw new VariableException("no runtime variable for context " + context.getURI(graph));
- return runtimeVariable.getPropertyValue(graph, "variable");
-
- }
-
- public static Variable getPossibleVariableSelection(ReadGraph graph, Variable context) throws DatabaseException {
- Variable runtimeVariable = getRuntimeVariable(graph, context);
- return runtimeVariable == null ? null : (Variable) runtimeVariable.getPossiblePropertyValue(graph, "variable");
- }
-
- public static Resource getResourceSelection(ReadGraph graph, Variable context) throws DatabaseException {
+ public static Variable getVariableSelection(ReadGraph graph, Variable context) throws DatabaseException {
+ Variable runtimeVariable = getRuntimeVariable(graph, context);
+ if (runtimeVariable == null)
+ throw new InvalidVariableException("no runtime variable for context " + context.getURI(graph));
+ return runtimeVariable.getPropertyValue(graph, "variable");
+ }
- Variable runtimeVariable = getRuntimeVariable(graph, context);
- if (runtimeVariable == null)
- throw new VariableException("no runtime variable for context " + context.getURI(graph));
- Resource sel = runtimeVariable.getPropertyValue(graph, "resource");
- return sel;
+ public static Variable getPossibleVariableSelection(ReadGraph graph, Variable context) throws DatabaseException {
+ Variable runtimeVariable = getRuntimeVariable(graph, context);
+ return runtimeVariable == null ? null : (Variable) runtimeVariable.getPossiblePropertyValue(graph, "variable");
+ }
- }
+ public static Resource getResourceSelection(ReadGraph graph, Variable context) throws DatabaseException {
+ Variable runtimeVariable = getRuntimeVariable(graph, context);
+ if (runtimeVariable == null)
+ throw new InvalidVariableException("no runtime variable for context " + context.getURI(graph));
+ Resource sel = runtimeVariable.getPropertyValue(graph, "resource");
+ return sel;
+ }
public static Resource getPossibleResourceSelection(ReadGraph graph, Variable context) throws DatabaseException {
try {
return node.getClass().getField(propertyName);
} catch (SecurityException e) {
- e.printStackTrace();
+ LOGGER.error("node: " + node, e);
} catch (NoSuchFieldException e) {
- System.err.println("node:" + node);
- e.printStackTrace();
+ LOGGER.error("node: " + node, e);
}
return null;
}