Merge from mainline
[official-gcc.git] / libjava / classpath / gnu / java / beans / encoder / Writer.java
blob57203d23e8290182b9d5699a4e63295fecc532ec
1 /* Writer.java -- Writing interface for XML persistence.
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package gnu.java.beans.encoder;
41 /** A <code>Writer</code> represents a simplified interface to an XML
42 * writer that is used for the XML persistence mechanism.
44 * <p>Its sole purpose is to allow multiple backends which may remove
45 * the need to have certain APIs in the classpath. Eg. it is possible
46 * to write a stripped down XML Writer that does not rely on SAX, StAX
47 * or DOM APIs.</p>
49 * <p>The caller may assume that every action is done immediately. However
50 * it is possible that the underlying implementation uses buffering streams.
51 * To make sure the data is written call the {@link flush} method.</p>
53 * <p>The <code>Writer</code> implementation should care about the formatting
54 * of the XML stream making it possible to generate three types of formats using
55 * a special method invocation chain.</p>
57 * <p>Write
58 * <code>
59 * &lt;element/&gt;
60 * </code>
61 * by issuing <code>write("element", true)</code> (or any of the other
62 * write-variants that allows specifying the <code>isEmpty</code> argument)
63 * and <code>writeEnd(true)</code>.</p>
65 * <p>Write
66 * <code>
67 * &lt;element&gt;body&lt;/element&gt;
68 * </code>
69 * by issuing <code>writeNoChildren("element", "body")</code> and <code>writeNoChildrenEnd()</code>.</p>
71 * <p>
72 * Write
73 * <code>
74 * &lt;element&gt;
75 * &lt;child1/&gt;
76 * &lt;child2/&gt;
77 * ...
78 * &lt;element/&gt;
79 * </code>
80 * by issuing <code>write("element", false)</code> (or any of the other
81 * write-variants that allows specifying the <code>isEmpty</code> argument)
82 * and <code>writeEnd(false)</code>.</p>
84 * <p>Note: It is important that the values of <code>isEmpty</code> and
85 * <code>wasEmpty</code> match. Otherwise strange things might happen to
86 * the layout.</p>
88 * @author Robert Schuster (robertschuster@fsfe.org)
91 public interface Writer
93 // TODO: This interface's design is not the best. Feel free to
94 // improve it as you like.
96 /** Writes the XML preamble. */
97 void writePreamble();
99 /** Writes the end of an XML tag.
101 * <p>If your tag has not generated any body text or child
102 * elements provide <code>true</code> as the argument to generate
103 * more space efficient variant of the tag.>/p>
105 * @param wasEmpty Whether the tag was empty or not.
107 void writeEnd(boolean wasEmpty);
109 /** Writes an XML tag without any attributes.
111 * @param tagName The name of the tag to write.
112 * @param empty Whether the element has child elements.
114 void write(String tagName, boolean empty);
116 /** Writes an XML tag with one attribute name and value.
118 * @param tagName The name of the tag to write.
119 * @param attributeName The name of attribute.
120 * @param attributeValue The attribute's value.
121 * @param empty Whether the element has child elements.
123 void write(String tagName, String attributeName, String attributeValue, boolean empty);
125 /** Writes an XML tag with multiple attributes and a body text.
127 * @param tagName The name of the tag to write.
128 * @param value The element's body content.
129 * @param attributeNames A set of attribute names.
130 * @param attributeValues A set of attribute values.
131 * @param empty Whether the element has child elements.
133 void write(String tagName, String value, String[] attributeNames,
134 String[] attributeValues, boolean empty);
136 /** Writes an XML tag with multiple attributes without a body text.
138 * @param tagName The name of the tag to write.
139 * @param attributeNames A set of attribute names.
140 * @param attributeValues A set of attribute values.
141 * @param empty Whether the element has child elements.
143 void write(String tagName, String[] attributeNames, String[] attributeValues, boolean empty);
145 /** Writes an XML tag with no attributes but with a body text
146 * that may have child elements.
148 * @param tagName The name of the tag to write.
149 * @param value The element's body content.
151 void write(String tagName, String value);
153 /** Writes an XML tag with no attributes but with a body text
154 * that does not have child elements.
156 * @param tagName The name of the tag to write.
157 * @param value The element's body content.
159 void writeNoChildren(String tagName, String value);
161 /** Writes the end of an XML tag that has no child elements.
163 * <p>Must be used in combination with {@link writeNoChildren} only.</p>
165 void writeEndNoChildren();
167 /** Forces the implementation to write some data.
169 void flush();
171 /** Closes the writer.
173 void close();