325N/A/*
325N/A * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage com.sun.xml.internal.txw2;
325N/A
325N/Aimport com.sun.xml.internal.txw2.annotation.XmlElement;
325N/Aimport com.sun.xml.internal.txw2.output.XmlSerializer;
325N/A
325N/Aimport javax.xml.namespace.QName;
325N/A
325N/A/**
325N/A * Defines common operations for all typed XML writers.
325N/A * Root of all typed XML writer interfaces.
325N/A *
325N/A * <p>
325N/A * This interface defines a series of methods to allow client applications
325N/A * to write arbitrary well-formed documents.
325N/A *
325N/A * @author Kohsuke Kawaguchi
325N/A */
325N/Apublic interface TypedXmlWriter {
325N/A /**
325N/A * Commits this element (and all its descendants) to the output.
325N/A *
325N/A * <p>
325N/A * Short for <tt>_commit(true)</tt>.
325N/A */
325N/A void commit();
325N/A
325N/A /**
325N/A * Commits this element (and all its descendants) to the output.
325N/A *
325N/A * <p>
325N/A * Once a writer is committed, nothing can be added to it further.
325N/A * Committing allows TXW to output a part of the document even
325N/A * if the rest has not yet been written.
325N/A *
325N/A * @param includingAllPredecessors
325N/A * if false, this operation will _commit this writer and all its
325N/A * descendants writers. If true, in addition to those writers,
325N/A * this operation will close all the writers before this writer
325N/A * in the document order.
325N/A */
325N/A void commit(boolean includingAllPredecessors);
325N/A
325N/A /**
325N/A * Blocks the writing of the start tag so that
325N/A * new attributes can be added even after child
325N/A * elements are appended.
325N/A *
325N/A * <p>
325N/A * This blocks the output at the token before the start tag until
325N/A * the {@link #commit()} method is called to _commit this element.
325N/A *
325N/A * <p>
325N/A * For more information, see the TXW documentation.
325N/A */
325N/A void block();
325N/A
325N/A /**
325N/A * Gets the {@link Document} object that this writer is writing to.
325N/A *
325N/A * @return
325N/A * always non-null.
325N/A */
325N/A Document getDocument();
325N/A
325N/A /**
325N/A * Adds an attribute of the given name and the value.
325N/A *
325N/A * <p>
325N/A * Short for <pre>_attribute("",localName,value);</pre>
325N/A *
325N/A * @see #_attribute(String, String, Object)
325N/A */
325N/A void _attribute( String localName, Object value );
325N/A
325N/A /**
325N/A * Adds an attribute of the given name and the value.
325N/A *
325N/A * <p>
325N/A * Short for <pre>_attribute(new QName(nsUri,localName),value);</pre>
325N/A *
325N/A * @see #_attribute(QName, Object)
325N/A */
325N/A void _attribute( String nsUri, String localName, Object value );
325N/A
325N/A /**
325N/A * Adds an attribute of the given name and the value.
325N/A *
325N/A * @param attributeName
325N/A * must not be null.
325N/A * @param value
325N/A * value of the attribute.
325N/A * must not be null.
325N/A * See the documentation for the conversion rules.
325N/A */
325N/A void _attribute( QName attributeName, Object value );
325N/A
325N/A /**
325N/A * Declares a new namespace URI on this element.
325N/A *
325N/A * <p>
325N/A * The runtime system will assign an unique prefix for the URI.
325N/A *
325N/A * @param uri
325N/A * can be empty, but must not be null.
325N/A */
325N/A void _namespace( String uri );
325N/A
325N/A /**
325N/A * Declares a new namespace URI on this element to
325N/A * a specific prefix.
325N/A *
325N/A * @param uri
325N/A * can be empty, but must not be null.
325N/A * @param prefix
325N/A * If non-empty, this prefix is bound to the URI
325N/A * on this element. If empty, then the runtime will still try to
325N/A * use the URI as the default namespace, but it may fail to do so
325N/A * because of the constraints in the XML.
325N/A *
325N/A * @throws IllegalArgumentException
325N/A * if the same prefix is already declared on this element.
325N/A */
325N/A void _namespace( String uri, String prefix );
325N/A
325N/A /**
325N/A * Declares a new namespace URI on this element.
325N/A *
325N/A * <p>
325N/A * The runtime system will assign an unique prefix for the URI.
325N/A *
325N/A * @param uri
325N/A * can be empty, but must not be null.
325N/A * @param requirePrefix
325N/A * if false, this method behaves just like {@link #_namespace(String)}.
325N/A * if true, this guarantees that the URI is bound to a non empty prefix.
325N/A */
325N/A void _namespace( String uri, boolean requirePrefix );
325N/A
325N/A /**
325N/A * Appends text data.
325N/A *
325N/A * @param value
325N/A * must not be null.
325N/A * See the documentation for the conversion rules.
325N/A */
325N/A void _pcdata( Object value );
325N/A
325N/A /**
325N/A * Appends CDATA section.
325N/A *
325N/A * @param value
325N/A * must not be null.
325N/A * See the documentation for the conversion rules.
325N/A */
325N/A void _cdata( Object value );
325N/A
325N/A /**
325N/A * Appends a comment.
325N/A *
325N/A * @param value
325N/A * must not be null.
325N/A * See the documentation for the conversion rules.
325N/A *
325N/A * @throws UnsupportedOperationException
325N/A * if the underlying {@link XmlSerializer} does not support
325N/A * writing comments, this exception can be thrown.
325N/A */
325N/A void _comment( Object value ) throws UnsupportedOperationException;
325N/A
325N/A /**
325N/A * Appends a new child element.
325N/A *
325N/A * <p>
325N/A * Short for <pre>_element(<i>URI of this element</i>,localName,contentModel);</pre>
325N/A *
325N/A * <p>
325N/A * The namespace URI will be inherited from the parent element.
325N/A *
325N/A * @see #_element(String, String, Class)
325N/A */
325N/A <T extends TypedXmlWriter> T _element( String localName, Class<T> contentModel );
325N/A
325N/A /**
325N/A * Appends a new child element.
325N/A *
325N/A * <p>
325N/A * The newly created child element is appended at the end of the children.
325N/A *
325N/A * @param nsUri
325N/A * The namespace URI of the newly created element.
325N/A * @param localName
325N/A * The local name of the newly created element.
325N/A * @param contentModel
325N/A * The typed XML writer interface used to write the children of
325N/A * the new child element.
325N/A *
325N/A * @return
325N/A * always return non-null {@link TypedXmlWriter} that can be used
325N/A * to write the contents of the newly created child element.
325N/A */
325N/A <T extends TypedXmlWriter> T _element( String nsUri, String localName, Class<T> contentModel );
325N/A
325N/A /**
325N/A * Appends a new child element.
325N/A *
325N/A * <p>
325N/A * Short for <pre>_element(tagName.getNamespaceURI(),tagName.getLocalPart(),contentModel);</pre>
325N/A *
325N/A * @see #_element(String, String, Class)
325N/A */
325N/A <T extends TypedXmlWriter> T _element( QName tagName, Class<T> contentModel );
325N/A
325N/A /**
325N/A * Appends a new child element.
325N/A *
325N/A * <p>
325N/A * This version of the _element method requires the <i>T</i> class to be
325N/A * annotated with {@link XmlElement} annotation. The element name will be
325N/A * taken from there.
325N/A *
325N/A * @see #_element(String, String, Class)
325N/A */
325N/A <T extends TypedXmlWriter> T _element( Class<T> contentModel );
325N/A
325N/A /**
325N/A * Returns a different interface for this typed XML Writer.
325N/A *
325N/A * <p>
325N/A * Semantically, this operation is a 'cast' --- it returns the same underlying
325N/A * writer in a different interface. The returned new writer and the current writer
325N/A * will write to the same element.
325N/A *
325N/A * <p>
325N/A * But this is different from Java's ordinary cast because the returned object
325N/A * is not always the same as the current object.
325N/A *
325N/A * @return
325N/A * always return non-null.
325N/A */
325N/A <T extends TypedXmlWriter> T _cast( Class<T> targetInterface );
325N/A}