diff options
author | David A. Madore <david@procyon.(none)> | 2010-04-14 20:52:52 +0200 |
---|---|---|
committer | David A. Madore <david@procyon.(none)> | 2010-04-14 20:52:52 +0200 |
commit | 5c6ccfca16a421860cd57d11e41d94d8a70cda76 (patch) | |
tree | e4a8591e48ebaf93d003dc61f1a42bcf66c1033d /org/madore/damlengine/TodoElement.java | |
parent | 7d6eccbd43ba703306328e133c43e0760ceead8c (diff) | |
download | damlengine-5c6ccfca16a421860cd57d11e41d94d8a70cda76.tar.gz damlengine-5c6ccfca16a421860cd57d11e41d94d8a70cda76.tar.bz2 damlengine-5c6ccfca16a421860cd57d11e41d94d8a70cda76.zip |
Make handlers instances instead of using static methods.
Diffstat (limited to 'org/madore/damlengine/TodoElement.java')
-rw-r--r-- | org/madore/damlengine/TodoElement.java | 28 |
1 files changed, 6 insertions, 22 deletions
diff --git a/org/madore/damlengine/TodoElement.java b/org/madore/damlengine/TodoElement.java index f8eaeec..c3dbf0b 100644 --- a/org/madore/damlengine/TodoElement.java +++ b/org/madore/damlengine/TodoElement.java @@ -1,25 +1,17 @@ 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.Element; public class TodoElement extends TodoItem { - protected static Map<String,Method> damlHandlers; - protected static Method defaultHandler; + protected static Map<String,ElementHandler> damlHandlers; + protected static ElementHandler defaultHandler; { - Class[] handlerArgTypes = new Class[]{ TodoElement.class }; - damlHandlers = new HashMap<String,Method>(); - try { - defaultHandler = DefaultHandler.class.getMethod("handle", handlerArgTypes); - } catch (NoSuchMethodException e) { - // FIXME: this isn't good... - throw new Error("this is impossible"); - } + damlHandlers = new HashMap<String,ElementHandler>(); + defaultHandler = new DefaultHandler(); } Element node; @@ -33,7 +25,7 @@ public class TodoElement extends TodoItem { } public void dispatch() { - Method handler; + ElementHandler handler; String nsuri = node.getNamespaceURI(); if ( nsuri != null && nsuri.equals(DamlEngine.DAML_NS) ) { handler = damlHandlers.get(node.getLocalName()); @@ -41,15 +33,7 @@ public class TodoElement extends TodoItem { 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"); - } + handler.handle(this); } } |