From 5c6ccfca16a421860cd57d11e41d94d8a70cda76 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Wed, 14 Apr 2010 20:52:52 +0200 Subject: Make handlers instances instead of using static methods. --- org/madore/damlengine/TodoAttr.java | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) (limited to 'org/madore/damlengine/TodoAttr.java') diff --git a/org/madore/damlengine/TodoAttr.java b/org/madore/damlengine/TodoAttr.java index c4e554a..e11abac 100644 --- a/org/madore/damlengine/TodoAttr.java +++ b/org/madore/damlengine/TodoAttr.java @@ -1,7 +1,5 @@ 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; @@ -9,18 +7,11 @@ import org.w3c.dom.Attr; public class TodoAttr extends TodoItem { - protected static Map damlHandlers; + protected static Map damlAttrHandlers; { - Class[] handlerArgTypes = new Class[]{ TodoAttr.class }; - damlHandlers = new HashMap(); - try { - damlHandlers.put("xempty", - XemptyAttrHandler.class.getMethod("handle", handlerArgTypes)); - } catch (NoSuchMethodException e) { - // FIXME: this isn't good... - throw new Error("this is impossible"); - } + damlAttrHandlers = new HashMap(); + damlAttrHandlers.put("xempty", new XemptyAttrHandler()); } Attr attr; @@ -37,22 +28,14 @@ public class TodoAttr extends TodoItem { } public void dispatch() { - Method handler; + AttrHandler handler; String nsuri = attr.getNamespaceURI(); if ( nsuri != null && nsuri.equals(DamlEngine.DAML_NS) ) { - handler = damlHandlers.get(attr.getLocalName()); + handler = damlAttrHandlers.get(attr.getLocalName()); } else handler = null; - try { - if ( handler != null ) - 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"); - } + if ( handler != null ) + handler.handle(this); } } -- cgit v1.2.3