summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2010-04-17 13:32:16 +0200
committerDavid A. Madore <david+git@madore.org>2010-04-17 13:32:16 +0200
commit852ff66033951ea44a94c25d5eb9da418c87dac4 (patch)
treeb0668308ac94ac8d66766e532943b7b47e47fc9e
parenta77ed7204b83823fac21175ecd5ee6565fd71ea7 (diff)
downloaddamlengine-852ff66033951ea44a94c25d5eb9da418c87dac4.tar.gz
damlengine-852ff66033951ea44a94c25d5eb9da418c87dac4.tar.bz2
damlengine-852ff66033951ea44a94c25d5eb9da418c87dac4.zip
Use ad hoc classes rather than hashes for context and options.
-rw-r--r--org/madore/damlengine/DamlEngine.java23
-rw-r--r--org/madore/damlengine/TodoAttr.java15
-rw-r--r--org/madore/damlengine/TodoContext.java13
-rw-r--r--org/madore/damlengine/TodoDefaultElement.java22
-rw-r--r--org/madore/damlengine/TodoElement.java17
-rw-r--r--org/madore/damlengine/TodoItem.java10
-rw-r--r--org/madore/damlengine/TodoXemptyAttr.java10
7 files changed, 64 insertions, 46 deletions
diff --git a/org/madore/damlengine/DamlEngine.java b/org/madore/damlengine/DamlEngine.java
index 712f7e3..03e089d 100644
--- a/org/madore/damlengine/DamlEngine.java
+++ b/org/madore/damlengine/DamlEngine.java
@@ -1,7 +1,5 @@
package org.madore.damlengine;
-import java.util.LinkedList;
-import java.util.HashMap;
import java.io.OutputStreamWriter;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
@@ -13,17 +11,18 @@ public final class DamlEngine {
public static final String DAML_NS = "http://www.madore.org/~david/NS/daml/";
- static Document doc;
-
private DamlEngine() { } // Forbid instantiation
- public static void processDocument() {
+ public static class RootOptions extends TodoItem.Options {
+ }
+
+ public static void processDocument(Document doc) {
TodoDeque todoDeque = new TodoDeque();
- HashMap<String,Object> options = new HashMap<String,Object>();
- options.put("isRoot", true);
- todoDeque.registerAtEnd(TodoElement.getTodoElement(doc.getDocumentElement(),
- new HashMap<String,Object>(),
- options));
+ TodoContext context = new TodoContext(doc);
+ TodoItem.Options options = new RootOptions();
+ todoDeque.
+ registerAtEnd(TodoElement.getTodoElement(doc.getDocumentElement(),
+ context, options));
todoDeque.dispatchLoop();
}
@@ -42,8 +41,8 @@ public final class DamlEngine {
}
for (String fname : args) {
- doc = db.parse(fname);
- processDocument();
+ Document doc = db.parse(fname);
+ processDocument(doc);
doc.normalizeDocument();
Unparser unparser
= new Unparser(doc, new OutputStreamWriter(System.out));
diff --git a/org/madore/damlengine/TodoAttr.java b/org/madore/damlengine/TodoAttr.java
index 721b4f6..0cc5389 100644
--- a/org/madore/damlengine/TodoAttr.java
+++ b/org/madore/damlengine/TodoAttr.java
@@ -9,8 +9,8 @@ public abstract class TodoAttr extends TodoItem {
public static abstract class Factory {
public abstract TodoAttr newItem(Attr attr, Element owner,
- Map<String,Object> context,
- Map<String,Object> options);
+ TodoContext context,
+ TodoItem.Options options);
}
protected static Map<String,Factory> damlAttrFactories;
@@ -22,20 +22,17 @@ public abstract class TodoAttr extends TodoItem {
Attr attr;
Element owner;
- Map<String,Object> context;
- Map<String,Object> options;
public TodoAttr(Attr attr, Element owner,
- Map<String,Object> context, Map<String,Object> options) {
+ TodoContext context, TodoItem.Options options) {
+ super(context, options);
this.attr = attr;
this.owner = owner;
- this.context = context;
- this.options = options;
}
public static TodoAttr getTodoAttr(Attr attr, Element owner,
- Map<String,Object> context,
- Map<String,Object> options) {
+ TodoContext context,
+ TodoItem.Options options) {
Factory factory = null;
String nsuri = attr.getNamespaceURI();
if ( nsuri != null && nsuri.equals(DamlEngine.DAML_NS) )
diff --git a/org/madore/damlengine/TodoContext.java b/org/madore/damlengine/TodoContext.java
new file mode 100644
index 0000000..65746b8
--- /dev/null
+++ b/org/madore/damlengine/TodoContext.java
@@ -0,0 +1,13 @@
+package org.madore.damlengine;
+
+import org.w3c.dom.Document;
+
+public class TodoContext {
+
+ public Document doc;
+
+ public TodoContext(Document doc) {
+ this.doc = doc;
+ }
+
+}
diff --git a/org/madore/damlengine/TodoDefaultElement.java b/org/madore/damlengine/TodoDefaultElement.java
index 942bca1..fd916e3 100644
--- a/org/madore/damlengine/TodoDefaultElement.java
+++ b/org/madore/damlengine/TodoDefaultElement.java
@@ -1,7 +1,5 @@
package org.madore.damlengine;
-import java.util.Map;
-import java.util.HashMap;
import java.util.ArrayList;
import org.w3c.dom.*;
@@ -9,16 +7,16 @@ 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) {
+ TodoContext context,
+ TodoItem.Options options) {
return new TodoDefaultElement(node, context, options);
}
}
public TodoDefaultElement(Element node,
- Map<String,Object> context,
- Map<String,Object> options) {
- super(node,context,options);
+ TodoContext context,
+ TodoItem.Options options) {
+ super(node, context, options);
}
public void handleAttributes() {
@@ -26,8 +24,9 @@ public class TodoDefaultElement extends TodoElement {
Node attr;
ArrayList<TodoAttr> toProcess = new ArrayList<TodoAttr>();
for ( int i=0 ; (attr=attrs.item(i)) != null ; i++ ) {
- TodoAttr it = TodoAttr.getTodoAttr((Attr)attr, this.node, this.context,
- new HashMap<String,Object>());
+ TodoAttr it
+ = TodoAttr.getTodoAttr((Attr)attr, this.node, this.context,
+ new TodoItem.Options());
if ( it != null )
toProcess.add(it);
}
@@ -41,8 +40,9 @@ public class TodoDefaultElement extends TodoElement {
ArrayList<TodoElement> toProcess = new ArrayList<TodoElement>();
for ( int i=0 ; (child=children.item(i)) != null ; i++ ) {
if ( child.getNodeType() == Node.ELEMENT_NODE ) {
- TodoElement it = TodoElement.getTodoElement((Element)child, this.context,
- new HashMap<String,Object>());
+ TodoElement it
+ = TodoElement.getTodoElement((Element)child, this.context,
+ new TodoItem.Options());
toProcess.add(it);
}
}
diff --git a/org/madore/damlengine/TodoElement.java b/org/madore/damlengine/TodoElement.java
index e2293ef..497b8f5 100644
--- a/org/madore/damlengine/TodoElement.java
+++ b/org/madore/damlengine/TodoElement.java
@@ -8,8 +8,8 @@ public abstract class TodoElement extends TodoItem {
public static abstract class Factory {
public abstract TodoElement newItem(Element node,
- Map<String,Object> context,
- Map<String,Object> options);
+ TodoContext context,
+ TodoItem.Options options);
}
protected static Map<String,Factory> damlFactories;
@@ -21,18 +21,17 @@ public abstract class TodoElement extends TodoItem {
}
Element node;
- Map<String,Object> context;
- Map<String,Object> options;
- public TodoElement(Element node, Map<String,Object> context, Map<String,Object> options) {
+ public TodoElement(Element node,
+ TodoContext context,
+ TodoItem.Options options) {
+ super(context, options);
this.node = node;
- this.context = context;
- this.options = options;
}
public static TodoElement getTodoElement(Element node,
- Map<String,Object> context,
- Map<String,Object> options) {
+ TodoContext context,
+ TodoItem.Options options) {
Factory factory = null;
String nsuri = node.getNamespaceURI();
if ( nsuri != null && nsuri.equals(DamlEngine.DAML_NS) )
diff --git a/org/madore/damlengine/TodoItem.java b/org/madore/damlengine/TodoItem.java
index 226b771..d956800 100644
--- a/org/madore/damlengine/TodoItem.java
+++ b/org/madore/damlengine/TodoItem.java
@@ -2,7 +2,17 @@ package org.madore.damlengine;
public abstract class TodoItem {
+ public static class Options {
+ }
+
public TodoDeque ownerDeque;
+ public TodoContext context;
+ public Options options;
+
+ public TodoItem(TodoContext context, Options options) {
+ this.context = context;
+ this.options = options;
+ }
public abstract void handle();
diff --git a/org/madore/damlengine/TodoXemptyAttr.java b/org/madore/damlengine/TodoXemptyAttr.java
index 7eaf636..2a233c4 100644
--- a/org/madore/damlengine/TodoXemptyAttr.java
+++ b/org/madore/damlengine/TodoXemptyAttr.java
@@ -1,26 +1,26 @@
package org.madore.damlengine;
-import java.util.Map;
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) {
+ TodoContext context,
+ TodoItem.Options options) {
return new TodoXemptyAttr(attr, owner, context, options);
}
}
public TodoXemptyAttr(Attr attr, Element owner,
- Map<String,Object> context, Map<String,Object> options) {
+ TodoContext context,
+ TodoItem.Options options) {
super(attr, owner, context, options);
}
public void handle() {
this.owner.removeAttribute(this.attr.getName());
- this.owner.appendChild(DamlEngine.doc.createComment(" EMPTY "));
+ this.owner.appendChild(context.doc.createComment(" EMPTY "));
}
}