01: package jimm.datavision;
02:
03: import jimm.util.XMLWriter;
04: import java.util.*;
05:
06: /**
07: * Writes the element of a list of {@link Writeable} objects as XML.
08: *
09: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
10: */
11: public class ListWriter {
12:
13: /**
14: * Writes the elements of a list of Writeable objects as XML. Each object's
15: * <code>writeXML</code> method is called.
16: *
17: * @param out the writer
18: * @param list the collection of objects to write
19: */
20: public static void writeList(XMLWriter out, Collection list) {
21: writeList(out, list, null);
22: }
23:
24: /**
25: * Writes the elements of a list of Writeable objects as XML. An open tag is
26: * written if <var>name</var> is not <code>null</code>, then each object's
27: * <code>writeXML</code> method is called, then a closing tag is written if
28: * needed. If the list is empty, nothing at all gets written.
29: *
30: * @param out the writer
31: * @param list the collection of objects to write
32: * @param name the XML tag name to use; if <code>null</code>, no begin/end
33: * element is written
34: */
35: public static void writeList(XMLWriter out, Collection list,
36: String name) {
37: if (list.isEmpty())
38: return;
39:
40: if (name != null)
41: out.startElement(name);
42: for (Iterator iter = list.iterator(); iter.hasNext();)
43: ((Writeable) iter.next()).writeXML(out);
44: if (name != null)
45: out.endElement();
46: }
47:
48: }
|