package org.madore.damlengine; import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; import java.util.Map; import java.util.HashMap; import org.w3c.dom.Node; public class TodoItem { protected static Map damlHandlers; protected static Method defaultHandler; { Class[] handlerArgTypes = new Class[]{ TodoItem.class }; damlHandlers = new HashMap(); try { defaultHandler = DefaultHandler.class.getMethod("handle", handlerArgTypes); } catch (NoSuchMethodException e) { // FIXME: this isn't good... throw new Error("this is impossible"); } } Node node; Map context; Map options; public TodoItem(Node node, Map context, Map options) { this.node = node; this.context = context; this.options = options; } public void dispatch() { Method handler; if ( node.getNamespaceURI().equals(DamlEngine.DAML_NS) ) { handler = damlHandlers.get(node.getLocalName()); if ( handler == null ) handler = defaultHandler; } else handler = defaultHandler; try { handler.invoke(null, new Object[]{this}); } catch (IllegalAccessException e) { // FIXME: this isn't good... throw new Error("this is impossible"); } catch (InvocationTargetException e) { // FIXME: this isn't good... throw new Error("this is impossible"); } } }