summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/TodoAttr.java
diff options
context:
space:
mode:
authorDavid A. Madore <david@procyon.(none)>2010-04-15 23:06:03 +0200
committerDavid A. Madore <david@procyon.(none)>2010-04-15 23:06:03 +0200
commitc18d6e561179a3a96d93a9ae8c6034115ba36923 (patch)
treed349bbc9f2e53d45e693b15b965812d7b531fe0d /org/madore/damlengine/TodoAttr.java
parent9176d80ae6dcad88da79714d934b226afe66c1ad (diff)
downloaddamlengine-c18d6e561179a3a96d93a9ae8c6034115ba36923.tar.gz
damlengine-c18d6e561179a3a96d93a9ae8c6034115ba36923.tar.bz2
damlengine-c18d6e561179a3a96d93a9ae8c6034115ba36923.zip
Change dispatching approach: handlers are now part of todoItems.
Instead of dispatching the todo item in function of the DAML node's local name at todo-handling time, the appropriate todo handler subclass is now instantiated in the todo deque by dispatching the creation of the todo item to the appropriate constructor.
Diffstat (limited to 'org/madore/damlengine/TodoAttr.java')
-rw-r--r--org/madore/damlengine/TodoAttr.java45
1 files changed, 32 insertions, 13 deletions
diff --git a/org/madore/damlengine/TodoAttr.java b/org/madore/damlengine/TodoAttr.java
index e11abac..b9cb800 100644
--- a/org/madore/damlengine/TodoAttr.java
+++ b/org/madore/damlengine/TodoAttr.java
@@ -1,17 +1,25 @@
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;
import org.w3c.dom.Attr;
-public class TodoAttr extends TodoItem {
+public abstract class TodoAttr extends TodoItem {
- protected static Map<String,AttrHandler> damlAttrHandlers;
+ protected static Map<String,Constructor<? extends TodoAttr>> damlAttrConstructors;
- {
- damlAttrHandlers = new HashMap<String,AttrHandler>();
- damlAttrHandlers.put("xempty", new XemptyAttrHandler());
+ protected static void initializeDamlAttrConstructors() {
+ // FIXME: this should be a static initializer, but for some reason does not work...
+ damlAttrConstructors = new HashMap<String,Constructor<? extends TodoAttr>>();
+ Class[] argTypes = new Class[]{ Attr.class, Element.class, Map.class, Map.class };
+ try {
+ damlAttrConstructors.put("xempty", TodoXemptyAttr.class.getConstructor(argTypes));
+ } catch (NoSuchMethodException e) {
+ // FIXME: Do something intelligent here!
+ }
}
Attr attr;
@@ -27,15 +35,26 @@ public class TodoAttr extends TodoItem {
this.options = options;
}
- public void dispatch() {
- AttrHandler handler;
+ public static TodoAttr getTodoAttr(Attr attr, Element owner,
+ Map<String,Object> context,
+ Map<String,Object> options) {
+ Constructor<? extends TodoAttr> constructor = null;
String nsuri = attr.getNamespaceURI();
- if ( nsuri != null && nsuri.equals(DamlEngine.DAML_NS) ) {
- handler = damlAttrHandlers.get(attr.getLocalName());
- } else
- handler = null;
- if ( handler != null )
- handler.handle(this);
+ if ( damlAttrConstructors == null )
+ initializeDamlAttrConstructors(); // FIXME: see above
+ if ( nsuri != null && nsuri.equals(DamlEngine.DAML_NS) )
+ constructor = damlAttrConstructors.get(attr.getLocalName());
+ if ( constructor != null )
+ try {
+ return constructor.newInstance(new Object[]{attr, owner, 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 null;
}
}