summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine
diff options
context:
space:
mode:
Diffstat (limited to 'org/madore/damlengine')
-rw-r--r--org/madore/damlengine/TodoAttr.java37
-rw-r--r--org/madore/damlengine/TodoDefaultElement.java11
-rw-r--r--org/madore/damlengine/TodoElement.java32
-rw-r--r--org/madore/damlengine/TodoXemptyAttr.java8
4 files changed, 47 insertions, 41 deletions
diff --git a/org/madore/damlengine/TodoAttr.java b/org/madore/damlengine/TodoAttr.java
index 2b3df23..721b4f6 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.Constructor;
-import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.HashMap;
import org.w3c.dom.Element;
@@ -9,16 +7,17 @@ import org.w3c.dom.Attr;
public abstract class TodoAttr extends TodoItem {
- protected static Map<String,Constructor<? extends TodoAttr>> damlAttrConstructors;
+ public static abstract class Factory {
+ public abstract TodoAttr newItem(Attr attr, Element owner,
+ Map<String,Object> context,
+ Map<String,Object> options);
+ }
+
+ protected static Map<String,Factory> damlAttrFactories;
static {
- 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!
- }
+ damlAttrFactories = new HashMap<String,Factory>();
+ damlAttrFactories.put("xempty", new TodoXemptyAttr.Factory());
}
Attr attr;
@@ -37,21 +36,13 @@ public abstract class TodoAttr extends TodoItem {
public static TodoAttr getTodoAttr(Attr attr, Element owner,
Map<String,Object> context,
Map<String,Object> options) {
- Constructor<? extends TodoAttr> constructor = null;
+ Factory factory = null;
String nsuri = attr.getNamespaceURI();
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;
+ factory = damlAttrFactories.get(attr.getLocalName());
+ if ( factory == null )
+ return null;
+ return factory.newItem(attr, owner, context, options);
}
}
diff --git a/org/madore/damlengine/TodoDefaultElement.java b/org/madore/damlengine/TodoDefaultElement.java
index 3329696..4041f82 100644
--- a/org/madore/damlengine/TodoDefaultElement.java
+++ b/org/madore/damlengine/TodoDefaultElement.java
@@ -7,8 +7,17 @@ import org.w3c.dom.*;
public class TodoDefaultElement extends TodoElement {
+ public static class Factory extends TodoElement.Factory {
+ public TodoDefaultElement newItem(Element node,
+ Map<String,Object> context,
+ Map<String,Object> options) {
+ return new TodoDefaultElement(node, context, options);
+ }
+ }
+
public TodoDefaultElement(Element node,
- Map<String,Object> context, Map<String,Object> options) {
+ Map<String,Object> context,
+ Map<String,Object> options) {
super(node,context,options);
}
diff --git a/org/madore/damlengine/TodoElement.java b/org/madore/damlengine/TodoElement.java
index a069b36..e2293ef 100644
--- a/org/madore/damlengine/TodoElement.java
+++ b/org/madore/damlengine/TodoElement.java
@@ -1,17 +1,23 @@
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;
+ public static abstract class Factory {
+ public abstract TodoElement newItem(Element node,
+ Map<String,Object> context,
+ Map<String,Object> options);
+ }
+
+ protected static Map<String,Factory> damlFactories;
+ protected static Factory damlDefaultFactory;
static {
- damlConstructors = new HashMap<String,Constructor<? extends TodoElement>>();
+ damlFactories = new HashMap<String,Factory>();
+ damlDefaultFactory = new TodoDefaultElement.Factory();
}
Element node;
@@ -27,21 +33,13 @@ public abstract class TodoElement extends TodoItem {
public static TodoElement getTodoElement(Element node,
Map<String,Object> context,
Map<String,Object> options) {
- Constructor<? extends TodoElement> constructor = null;
+ Factory factory = null;
String nsuri = node.getNamespaceURI();
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);
+ factory = damlFactories.get(node.getLocalName());
+ if ( factory == null )
+ factory = damlDefaultFactory;
+ return factory.newItem(node, context, options);
}
}
diff --git a/org/madore/damlengine/TodoXemptyAttr.java b/org/madore/damlengine/TodoXemptyAttr.java
index e2cbe61..7eaf636 100644
--- a/org/madore/damlengine/TodoXemptyAttr.java
+++ b/org/madore/damlengine/TodoXemptyAttr.java
@@ -5,6 +5,14 @@ import org.w3c.dom.*;
public class TodoXemptyAttr extends TodoAttr {
+ public static class Factory extends TodoAttr.Factory {
+ public TodoXemptyAttr newItem(Attr attr, Element owner,
+ Map<String,Object> context,
+ Map<String,Object> options) {
+ return new TodoXemptyAttr(attr, owner, context, options);
+ }
+ }
+
public TodoXemptyAttr(Attr attr, Element owner,
Map<String,Object> context, Map<String,Object> options) {
super(attr, owner, context, options);