summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/TodoElement.java
blob: f8dcca1393ada6469575e877d3b1821d8d93cc21 (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
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 abstract class TodoElement extends TodoItem {

    protected static Map<String,Constructor<? extends TodoElement>> damlConstructors;

    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;
    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 static TodoElement getTodoElement(Element node,
					     Map<String,Object> context,
					     Map<String,Object> options) {
	Constructor<? extends TodoElement> constructor = null;
	String nsuri = node.getNamespaceURI();
	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);
    }

}