summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine
diff options
context:
space:
mode:
authorDavid A. Madore <david@procyon.(none)>2010-04-13 11:08:15 +0200
committerDavid A. Madore <david@procyon.(none)>2010-04-13 11:08:15 +0200
commit45fa82f3f6b98f3b6f81e8e753d8e7341dee14b5 (patch)
treeee60dee79a61fbeb21ba23dc17a7c1a812494857 /org/madore/damlengine
parentb078ed40a25afd13e420da54c78ad67ad369e88e (diff)
downloaddamlengine-45fa82f3f6b98f3b6f81e8e753d8e7341dee14b5.tar.gz
damlengine-45fa82f3f6b98f3b6f81e8e753d8e7341dee14b5.tar.bz2
damlengine-45fa82f3f6b98f3b6f81e8e753d8e7341dee14b5.zip
Start writing a todo item handling framework.
Diffstat (limited to 'org/madore/damlengine')
-rw-r--r--org/madore/damlengine/DamlEngine.java3
-rw-r--r--org/madore/damlengine/DefaultHandler.java11
-rw-r--r--org/madore/damlengine/TodoItem.java42
3 files changed, 53 insertions, 3 deletions
diff --git a/org/madore/damlengine/DamlEngine.java b/org/madore/damlengine/DamlEngine.java
index 441e970..6afa628 100644
--- a/org/madore/damlengine/DamlEngine.java
+++ b/org/madore/damlengine/DamlEngine.java
@@ -11,6 +11,8 @@ import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl;
public final class DamlEngine {
+ public static final String DAML_NS = "http://www.madore.org/~david/NS/daml/";
+
private static Document doc;
private DamlEngine() { } // Forbid instantiation
@@ -22,6 +24,7 @@ public final class DamlEngine {
todoStack.add(new TodoItem(doc.getDocumentElement(),
new HashMap<String,Object>(),
options));
+ todoStack.removeFirst().dispatch();
// ...
}
diff --git a/org/madore/damlengine/DefaultHandler.java b/org/madore/damlengine/DefaultHandler.java
new file mode 100644
index 0000000..6a2c174
--- /dev/null
+++ b/org/madore/damlengine/DefaultHandler.java
@@ -0,0 +1,11 @@
+package org.madore.damlengine;
+
+public class DefaultHandler {
+
+ private DefaultHandler() { }
+
+ public static void handle(TodoItem that) {
+ System.err.println("handling a "+that.node.getNodeName()+" node");
+ }
+
+}
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<String,Object> context;
- protected Map<String,Object> options;
+ protected static Map<String,Method> damlHandlers;
+ protected static Method defaultHandler;
+
+ {
+ Class[] handlerArgTypes = new Class[]{ TodoItem.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");
+ }
+ }
+
+ Node node;
+ Map<String,Object> context;
+ Map<String,Object> options;
public TodoItem(Node node, Map<String,Object> context, Map<String,Object> 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");
+ }
+ }
+
}