From 852ff66033951ea44a94c25d5eb9da418c87dac4 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Sat, 17 Apr 2010 13:32:16 +0200 Subject: Use ad hoc classes rather than hashes for context and options. --- org/madore/damlengine/DamlEngine.java | 23 +++++++++++------------ org/madore/damlengine/TodoAttr.java | 15 ++++++--------- org/madore/damlengine/TodoContext.java | 13 +++++++++++++ org/madore/damlengine/TodoDefaultElement.java | 22 +++++++++++----------- org/madore/damlengine/TodoElement.java | 17 ++++++++--------- org/madore/damlengine/TodoItem.java | 10 ++++++++++ org/madore/damlengine/TodoXemptyAttr.java | 10 +++++----- 7 files changed, 64 insertions(+), 46 deletions(-) create mode 100644 org/madore/damlengine/TodoContext.java (limited to 'org/madore') 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 options = new HashMap(); - options.put("isRoot", true); - todoDeque.registerAtEnd(TodoElement.getTodoElement(doc.getDocumentElement(), - new HashMap(), - 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 context, - Map options); + TodoContext context, + TodoItem.Options options); } protected static Map damlAttrFactories; @@ -22,20 +22,17 @@ public abstract class TodoAttr extends TodoItem { Attr attr; Element owner; - Map context; - Map options; public TodoAttr(Attr attr, Element owner, - Map context, Map 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 context, - Map 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 context, - Map options) { + TodoContext context, + TodoItem.Options options) { return new TodoDefaultElement(node, context, options); } } public TodoDefaultElement(Element node, - Map context, - Map 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 toProcess = new ArrayList(); for ( int i=0 ; (attr=attrs.item(i)) != null ; i++ ) { - TodoAttr it = TodoAttr.getTodoAttr((Attr)attr, this.node, this.context, - new HashMap()); + 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 toProcess = new ArrayList(); 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()); + 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 context, - Map options); + TodoContext context, + TodoItem.Options options); } protected static Map damlFactories; @@ -21,18 +21,17 @@ public abstract class TodoElement extends TodoItem { } Element node; - Map context; - Map options; - public TodoElement(Element node, Map context, Map 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 context, - Map 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 context, - Map options) { + TodoContext context, + TodoItem.Options options) { return new TodoXemptyAttr(attr, owner, context, options); } } public TodoXemptyAttr(Attr attr, Element owner, - Map context, Map 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 ")); } } -- cgit v1.2.3