summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/TodoElement.java
blob: f8eaeeca15cdb8d02b401b84af87407f889d84b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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");
	}
    }

}