KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jimm > datavision > ListWriter


1 package jimm.datavision;
2 import jimm.util.XMLWriter;
3 import java.util.*;
4
5 /**
6  * Writes the element of a list of {@link Writeable} objects as XML.
7  *
8  * @author Jim Menard, <a HREF="mailto:jimm@io.com">jimm@io.com</a>
9  */

10 public class ListWriter {
11
12 /**
13  * Writes the elements of a list of Writeable objects as XML. Each object's
14  * <code>writeXML</code> method is called.
15  *
16  * @param out the writer
17  * @param list the collection of objects to write
18  */

19 public static void writeList(XMLWriter out, Collection list) {
20   writeList(out, list, null);
21 }
22
23 /**
24  * Writes the elements of a list of Writeable objects as XML. An open tag is
25  * written if <var>name</var> is not <code>null</code>, then each object's
26  * <code>writeXML</code> method is called, then a closing tag is written if
27  * needed. If the list is empty, nothing at all gets written.
28  *
29  * @param out the writer
30  * @param list the collection of objects to write
31  * @param name the XML tag name to use; if <code>null</code>, no begin/end
32  * element is written
33  */

34 public static void writeList(XMLWriter out, Collection list, String JavaDoc name) {
35     if (list.isEmpty())
36     return;
37
38     if (name != null)
39       out.startElement(name);
40     for (Iterator iter = list.iterator(); iter.hasNext(); )
41     ((Writeable)iter.next()).writeXML(out);
42     if (name != null)
43       out.endElement();
44 }
45
46 }
47
Popular Tags