1 package org.simantics.document.server.request;
3 import org.simantics.db.ReadGraph;
4 import org.simantics.db.exception.DatabaseException;
5 import org.simantics.db.layer0.variable.Variable;
6 import org.simantics.db.layer0.variable.Variables;
7 import org.simantics.db.request.Read;
8 import org.simantics.document.server.handler.AbstractEventHandler;
9 import org.simantics.structural.stubs.StructuralResource2;
11 public class HandleEventRequest implements Read<AbstractEventHandler> {
15 public HandleEventRequest(String id) {
20 public AbstractEventHandler perform(ReadGraph graph) throws DatabaseException {
22 StructuralResource2.getInstance(graph);
24 Variable variable = Variables.getPossibleVariable(graph, id);
25 if(variable == null) return null;
27 // System.err.println("EVENT " + variable.getURI(graph));
28 Object handler = variable.getValue(graph);
29 if(handler instanceof AbstractEventHandler)
30 return (AbstractEventHandler) handler;
32 throw new DatabaseException("Handler for " + id + " is not instance of AbstractEventHandler (it is instance of " + (handler != null ? handler.getClass() : null) + ")");