summaryrefslogtreecommitdiffstats
path: root/org/madore
diff options
context:
space:
mode:
authorDavid A. Madore <david@procyon.(none)>2010-04-14 20:52:52 +0200
committerDavid A. Madore <david@procyon.(none)>2010-04-14 20:52:52 +0200
commit5c6ccfca16a421860cd57d11e41d94d8a70cda76 (patch)
treee4a8591e48ebaf93d003dc61f1a42bcf66c1033d /org/madore
parent7d6eccbd43ba703306328e133c43e0760ceead8c (diff)
downloaddamlengine-5c6ccfca16a421860cd57d11e41d94d8a70cda76.tar.gz
damlengine-5c6ccfca16a421860cd57d11e41d94d8a70cda76.tar.bz2
damlengine-5c6ccfca16a421860cd57d11e41d94d8a70cda76.zip
Make handlers instances instead of using static methods.
Diffstat (limited to 'org/madore')
-rw-r--r--org/madore/damlengine/AttrHandler.java10
-rw-r--r--org/madore/damlengine/DefaultHandler.java36
-rw-r--r--org/madore/damlengine/ElementHandler.java41
-rw-r--r--org/madore/damlengine/TodoAttr.java31
-rw-r--r--org/madore/damlengine/TodoElement.java28
-rw-r--r--org/madore/damlengine/XemptyAttrHandler.java6
6 files changed, 67 insertions, 85 deletions
diff --git a/org/madore/damlengine/AttrHandler.java b/org/madore/damlengine/AttrHandler.java
new file mode 100644
index 0000000..df1e18a
--- /dev/null
+++ b/org/madore/damlengine/AttrHandler.java
@@ -0,0 +1,10 @@
+package org.madore.damlengine;
+
+import org.w3c.dom.*;
+
+public abstract class AttrHandler {
+
+ public void handle(TodoAttr that) {
+ }
+
+}
diff --git a/org/madore/damlengine/DefaultHandler.java b/org/madore/damlengine/DefaultHandler.java
index ae23a3b..d22d8f4 100644
--- a/org/madore/damlengine/DefaultHandler.java
+++ b/org/madore/damlengine/DefaultHandler.java
@@ -4,40 +4,6 @@ import java.util.Vector;
import java.util.HashMap;
import org.w3c.dom.*;
-public class DefaultHandler {
-
- private DefaultHandler() { }
-
- 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<TodoElement> toProcess = new Vector<TodoElement>();
- for ( int i=0 ; (child=children.item(i)) != null ; i++ ) {
- if ( child.getNodeType() == Node.ELEMENT_NODE ) {
- 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);
- }
+public class DefaultHandler extends ElementHandler {
}
diff --git a/org/madore/damlengine/ElementHandler.java b/org/madore/damlengine/ElementHandler.java
new file mode 100644
index 0000000..4e14756
--- /dev/null
+++ b/org/madore/damlengine/ElementHandler.java
@@ -0,0 +1,41 @@
+package org.madore.damlengine;
+
+import java.util.Vector;
+import java.util.HashMap;
+import org.w3c.dom.*;
+
+public abstract class ElementHandler {
+
+ public 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 void handleNodeOnly(TodoElement that) {
+ System.err.println("handling a "+that.node.getNodeName()+" element");
+ NodeList children = that.node.getChildNodes();
+ Node child;
+ Vector<TodoElement> toProcess = new Vector<TodoElement>();
+ for ( int i=0 ; (child=children.item(i)) != null ; i++ ) {
+ if ( child.getNodeType() == Node.ELEMENT_NODE ) {
+ TodoElement it = new TodoElement((Element)child, that.context,
+ new HashMap<String,Object>());
+ toProcess.add(it);
+ }
+ }
+ TodoDeque.registerAtStart(toProcess);
+ }
+
+ public void handle(TodoElement that) {
+ handleAttributes(that);
+ handleNodeOnly(that);
+ }
+
+}
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<String,Method> damlHandlers;
+ protected static Map<String,AttrHandler> damlAttrHandlers;
{
- Class[] handlerArgTypes = new Class[]{ TodoAttr.class };
- damlHandlers = new HashMap<String,Method>();
- 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<String,AttrHandler>();
+ 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);
}
}
diff --git a/org/madore/damlengine/TodoElement.java b/org/madore/damlengine/TodoElement.java
index f8eaeec..c3dbf0b 100644
--- a/org/madore/damlengine/TodoElement.java
+++ b/org/madore/damlengine/TodoElement.java
@@ -1,25 +1,17 @@
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;
+ protected static Map<String,ElementHandler> damlHandlers;
+ protected static ElementHandler 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");
- }
+ damlHandlers = new HashMap<String,ElementHandler>();
+ defaultHandler = new DefaultHandler();
}
Element node;
@@ -33,7 +25,7 @@ public class TodoElement extends TodoItem {
}
public void dispatch() {
- Method handler;
+ ElementHandler handler;
String nsuri = node.getNamespaceURI();
if ( nsuri != null && nsuri.equals(DamlEngine.DAML_NS) ) {
handler = damlHandlers.get(node.getLocalName());
@@ -41,15 +33,7 @@ public class TodoElement extends TodoItem {
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");
- }
+ handler.handle(this);
}
}
diff --git a/org/madore/damlengine/XemptyAttrHandler.java b/org/madore/damlengine/XemptyAttrHandler.java
index 3120d26..16f8173 100644
--- a/org/madore/damlengine/XemptyAttrHandler.java
+++ b/org/madore/damlengine/XemptyAttrHandler.java
@@ -2,11 +2,9 @@ package org.madore.damlengine;
import org.w3c.dom.*;
-public class XemptyAttrHandler {
+public class XemptyAttrHandler extends AttrHandler {
- private XemptyAttrHandler() { }
-
- public static void handle(TodoAttr that) {
+ public void handle(TodoAttr that) {
that.owner.removeAttribute(that.attr.getName());
that.owner.appendChild(DamlEngine.doc.createComment(" EMPTY "));
}