summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/TodoElement.java
diff options
context:
space:
mode:
authorDavid A. Madore <david@procyon.(none)>2010-04-13 15:21:41 +0200
committerDavid A. Madore <david@procyon.(none)>2010-04-13 15:21:41 +0200
commite3b7a9c657a6a5f5a7a8f3c7ee4fdff1aee6410f (patch)
tree9a7f411ce9333aa6c67cd66522f4aaf60c35d194 /org/madore/damlengine/TodoElement.java
parent734a0b78ea5508f243caf18a50e36ac8918e11db (diff)
downloaddamlengine-e3b7a9c657a6a5f5a7a8f3c7ee4fdff1aee6410f.tar.gz
damlengine-e3b7a9c657a6a5f5a7a8f3c7ee4fdff1aee6410f.tar.bz2
damlengine-e3b7a9c657a6a5f5a7a8f3c7ee4fdff1aee6410f.zip
Framework for handling attributes.
Diffstat (limited to 'org/madore/damlengine/TodoElement.java')
-rw-r--r--org/madore/damlengine/TodoElement.java55
1 files changed, 55 insertions, 0 deletions
diff --git a/org/madore/damlengine/TodoElement.java b/org/madore/damlengine/TodoElement.java
new file mode 100644
index 0000000..f8eaeec
--- /dev/null
+++ b/org/madore/damlengine/TodoElement.java
@@ -0,0 +1,55 @@
+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;
+
+ {
+ 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");
+ }
+ }
+
+ Element node;
+ Map<String,Object> context;
+ Map<String,Object> options;
+
+ public TodoElement(Element node, Map<String,Object> context, Map<String,Object> options) {
+ this.node = node;
+ this.context = context;
+ this.options = options;
+ }
+
+ public void dispatch() {
+ Method handler;
+ String nsuri = node.getNamespaceURI();
+ if ( nsuri != null && nsuri.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");
+ }
+ }
+
+}