From e3b7a9c657a6a5f5a7a8f3c7ee4fdff1aee6410f Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Tue, 13 Apr 2010 15:21:41 +0200 Subject: Framework for handling attributes. --- org/madore/damlengine/TodoAttr.java | 57 +++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 org/madore/damlengine/TodoAttr.java (limited to 'org/madore/damlengine/TodoAttr.java') diff --git a/org/madore/damlengine/TodoAttr.java b/org/madore/damlengine/TodoAttr.java new file mode 100644 index 0000000..d4d877e --- /dev/null +++ b/org/madore/damlengine/TodoAttr.java @@ -0,0 +1,57 @@ +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; +import org.w3c.dom.Attr; + +public class TodoAttr extends TodoItem { + + protected static Map damlHandlers; + + { + Class[] handlerArgTypes = new Class[]{ TodoAttr.class }; + damlHandlers = new HashMap(); + // try { + // ; + // } catch (NoSuchMethodException e) { + // // FIXME: this isn't good... + // throw new Error("this is impossible"); + // } + } + + Attr attr; + Element owner; + Map context; + Map options; + + public TodoAttr(Attr attr, Element owner, + Map context, Map options) { + this.attr = attr; + this.owner = owner; + this.context = context; + this.options = options; + } + + public void dispatch() { + Method handler; + String nsuri = attr.getNamespaceURI(); + if ( nsuri != null && nsuri.equals(DamlEngine.DAML_NS) ) { + handler = damlHandlers.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"); + } + } + +} -- cgit v1.2.3