From 45fa82f3f6b98f3b6f81e8e753d8e7341dee14b5 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Tue, 13 Apr 2010 11:08:15 +0200 Subject: Start writing a todo item handling framework. --- org/madore/damlengine/TodoItem.java | 42 ++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'org/madore/damlengine/TodoItem.java') diff --git a/org/madore/damlengine/TodoItem.java b/org/madore/damlengine/TodoItem.java index e058ae2..941460e 100644 --- a/org/madore/damlengine/TodoItem.java +++ b/org/madore/damlengine/TodoItem.java @@ -1,13 +1,30 @@ 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 Node node; - protected Map context; - protected Map options; + 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; @@ -15,4 +32,23 @@ public class TodoItem { 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"); + } + } + } -- cgit v1.2.3