Frames | No Frames |
1: /* Writer.java -- Writing interface for XML persistence. 2: Copyright (C) 2005 Free Software Foundation, Inc. 3: 4: This file is part of GNU Classpath. 5: 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. 10: 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. 15: 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. 20: 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. 25: 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. */ 37: 38: 39: package gnu.java.beans.encoder; 40: 41: /** A <code>Writer</code> represents a simplified interface to an XML 42: * writer that is used for the XML persistence mechanism. 43: * 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> 48: * 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> 52: * 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> 56: * 57: * <p>Write 58: * <code> 59: * <element/> 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> 64: * 65: * <p>Write 66: * <code> 67: * <element>body</element> 68: * </code> 69: * by issuing <code>writeNoChildren("element", "body")</code> and <code>writeNoChildrenEnd()</code>.</p> 70: * 71: * <p> 72: * Write 73: * <code> 74: * <element> 75: * <child1/> 76: * <child2/> 77: * ... 78: * <element/> 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> 83: * 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> 87: * 88: * @author Robert Schuster (robertschuster@fsfe.org) 89: * 90: */ 91: public interface Writer 92: { 93: // TODO: This interface's design is not the best. Feel free to 94: // improve it as you like. 95: 96: /** Writes the XML preamble. */ 97: void writePreamble(); 98: 99: /** Writes the end of an XML tag. 100: * 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> 104: * 105: * @param wasEmpty Whether the tag was empty or not. 106: */ 107: void writeEnd(boolean wasEmpty); 108: 109: /** Writes an XML tag without any attributes. 110: * 111: * @param tagName The name of the tag to write. 112: * @param empty Whether the element has child elements. 113: */ 114: void write(String tagName, boolean empty); 115: 116: /** Writes an XML tag with one attribute name and value. 117: * 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. 122: */ 123: void write(String tagName, String attributeName, String attributeValue, boolean empty); 124: 125: /** Writes an XML tag with multiple attributes and a body text. 126: * 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. 132: */ 133: void write(String tagName, String value, String[] attributeNames, 134: String[] attributeValues, boolean empty); 135: 136: /** Writes an XML tag with multiple attributes without a body text. 137: * 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. 142: */ 143: void write(String tagName, String[] attributeNames, String[] attributeValues, boolean empty); 144: 145: /** Writes an XML tag with no attributes but with a body text 146: * that may have child elements. 147: * 148: * @param tagName The name of the tag to write. 149: * @param value The element's body content. 150: */ 151: void write(String tagName, String value); 152: 153: /** Writes an XML tag with no attributes but with a body text 154: * that does not have child elements. 155: * 156: * @param tagName The name of the tag to write. 157: * @param value The element's body content. 158: */ 159: void writeNoChildren(String tagName, String value); 160: 161: /** Writes the end of an XML tag that has no child elements. 162: * 163: * <p>Must be used in combination with {@link writeNoChildren} only.</p> 164: */ 165: void writeEndNoChildren(); 166: 167: /** Forces the implementation to write some data. 168: */ 169: void flush(); 170: 171: /** Closes the writer. 172: */ 173: void close(); 174: }