summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org/madore/damlengine/DamlEngine.java6
-rw-r--r--org/madore/damlengine/DefaultHandler.java27
-rw-r--r--org/madore/damlengine/TodoAttr.java57
-rw-r--r--org/madore/damlengine/TodoDeque.java4
-rw-r--r--org/madore/damlengine/TodoElement.java55
-rw-r--r--org/madore/damlengine/TodoItem.java51
6 files changed, 141 insertions, 59 deletions
diff --git a/org/madore/damlengine/DamlEngine.java b/org/madore/damlengine/DamlEngine.java
index f13d376..822b645 100644
--- a/org/madore/damlengine/DamlEngine.java
+++ b/org/madore/damlengine/DamlEngine.java
@@ -20,9 +20,9 @@ public final class DamlEngine {
public static void processDocument() {
HashMap<String,Object> options = new HashMap<String,Object>();
options.put("isRoot", true);
- TodoDeque.registerAtEnd(new TodoItem(doc.getDocumentElement(),
- new HashMap<String,Object>(),
- options));
+ TodoDeque.registerAtEnd(new TodoElement(doc.getDocumentElement(),
+ new HashMap<String,Object>(),
+ options));
TodoDeque.dispatchLoop();
}
diff --git a/org/madore/damlengine/DefaultHandler.java b/org/madore/damlengine/DefaultHandler.java
index 4720f67..ae23a3b 100644
--- a/org/madore/damlengine/DefaultHandler.java
+++ b/org/madore/damlengine/DefaultHandler.java
@@ -8,19 +8,36 @@ public class DefaultHandler {
private DefaultHandler() { }
- public static void handle(TodoItem that) {
- System.err.println("handling a "+that.node.getNodeName()+" node");
+ public static void handleAttributes(TodoElement that) {
+ NamedNodeMap attrs = that.node.getAttributes();
+ Node attr;
+ Vector<TodoAttr> toProcess = new Vector<TodoAttr>();
+ for ( int i=0 ; (attr=attrs.item(i)) != null ; i++ ) {
+ TodoAttr it = new TodoAttr((Attr)attr, that.node, that.context,
+ new HashMap<String,Object>());
+ toProcess.add(it);
+ }
+ TodoDeque.registerAtStart(toProcess);
+ }
+
+ public static void handleNodeOnly(TodoElement that) {
+ System.err.println("handling a "+that.node.getNodeName()+" element");
NodeList children = that.node.getChildNodes();
Node child;
- Vector<TodoItem> toProcess = new Vector<TodoItem>();
+ Vector<TodoElement> toProcess = new Vector<TodoElement>();
for ( int i=0 ; (child=children.item(i)) != null ; i++ ) {
if ( child.getNodeType() == Node.ELEMENT_NODE ) {
- TodoItem it = new TodoItem(child, that.context,
- new HashMap<String,Object>());
+ TodoElement it = new TodoElement((Element)child, that.context,
+ new HashMap<String,Object>());
toProcess.add(it);
}
}
TodoDeque.registerAtStart(toProcess);
}
+ public static void handle(TodoElement that) {
+ handleAttributes(that);
+ handleNodeOnly(that);
+ }
+
}
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<String,Method> damlHandlers;
+
+ {
+ Class[] handlerArgTypes = new Class[]{ TodoAttr.class };
+ damlHandlers = new HashMap<String,Method>();
+ // try {
+ // ;
+ // } catch (NoSuchMethodException e) {
+ // // FIXME: this isn't good...
+ // throw new Error("this is impossible");
+ // }
+ }
+
+ Attr attr;
+ Element owner;
+ Map<String,Object> context;
+ Map<String,Object> options;
+
+ public TodoAttr(Attr attr, Element owner,
+ Map<String,Object> context, Map<String,Object> 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");
+ }
+ }
+
+}
diff --git a/org/madore/damlengine/TodoDeque.java b/org/madore/damlengine/TodoDeque.java
index e030e29..037723b 100644
--- a/org/madore/damlengine/TodoDeque.java
+++ b/org/madore/damlengine/TodoDeque.java
@@ -20,7 +20,7 @@ public final class TodoDeque {
todoDeque.addLast(it);
}
- public static void registerAtEnd(Collection<TodoItem> them) {
+ public static void registerAtEnd(Collection<? extends TodoItem> them) {
todoDeque.addAll(them);
}
@@ -28,7 +28,7 @@ public final class TodoDeque {
todoDeque.addFirst(it);
}
- public static void registerAtStart(Collection<TodoItem> them) {
+ public static void registerAtStart(Collection<? extends TodoItem> them) {
todoDeque.addAll(0, them);
}
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");
+ }
+ }
+
+}
diff --git a/org/madore/damlengine/TodoItem.java b/org/madore/damlengine/TodoItem.java
index 941460e..677b3b1 100644
--- a/org/madore/damlengine/TodoItem.java
+++ b/org/madore/damlengine/TodoItem.java
@@ -1,54 +1,7 @@
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 abstract class TodoItem {
-public class TodoItem {
-
- 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;
- this.context = context;
- 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");
- }
- }
+ public abstract void dispatch();
}