summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/TodoElement.java
diff options
context:
space:
mode:
Diffstat (limited to 'org/madore/damlengine/TodoElement.java')
-rw-r--r--org/madore/damlengine/TodoElement.java41
1 files changed, 26 insertions, 15 deletions
diff --git a/org/madore/damlengine/TodoElement.java b/org/madore/damlengine/TodoElement.java
index c3dbf0b..f8dcca1 100644
--- a/org/madore/damlengine/TodoElement.java
+++ b/org/madore/damlengine/TodoElement.java
@@ -1,17 +1,18 @@
package org.madore.damlengine;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.HashMap;
import org.w3c.dom.Element;
-public class TodoElement extends TodoItem {
+public abstract class TodoElement extends TodoItem {
- protected static Map<String,ElementHandler> damlHandlers;
- protected static ElementHandler defaultHandler;
+ protected static Map<String,Constructor<? extends TodoElement>> damlConstructors;
- {
- damlHandlers = new HashMap<String,ElementHandler>();
- defaultHandler = new DefaultHandler();
+ protected static void initializeDamlConstructors() {
+ // FIXME: this should be a static initializer, but for some reason does not work...
+ damlConstructors = new HashMap<String,Constructor<? extends TodoElement>>();
}
Element node;
@@ -24,16 +25,26 @@ public class TodoElement extends TodoItem {
this.options = options;
}
- public void dispatch() {
- ElementHandler handler;
+ public static TodoElement getTodoElement(Element node,
+ Map<String,Object> context,
+ Map<String,Object> options) {
+ Constructor<? extends TodoElement> constructor = null;
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;
- handler.handle(this);
+ if ( damlConstructors == null )
+ initializeDamlConstructors(); // FIXME: see above
+ if ( nsuri != null && nsuri.equals(DamlEngine.DAML_NS) )
+ constructor = damlConstructors.get(node.getLocalName());
+ if ( constructor != null )
+ try {
+ return constructor.newInstance(new Object[]{node, context, options});
+ } catch (InstantiationException e) {
+ // FIXME: Do something intelligent here!
+ } catch (IllegalAccessException e) {
+ // FIXME: Do something intelligent here!
+ } catch (InvocationTargetException e) {
+ // FIXME: Do something intelligent here!
+ }
+ return new TodoDefaultElement(node, context, options);
}
}