aoqi@0: /* aoqi@0: * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.xml.internal.txw2; aoqi@0: aoqi@0: import com.sun.xml.internal.txw2.annotation.XmlElement; aoqi@0: import com.sun.xml.internal.txw2.output.XmlSerializer; aoqi@0: aoqi@0: import javax.xml.namespace.QName; aoqi@0: aoqi@0: /** aoqi@0: * Defines common operations for all typed XML writers. aoqi@0: * Root of all typed XML writer interfaces. aoqi@0: * aoqi@0: *

aoqi@0: * This interface defines a series of methods to allow client applications aoqi@0: * to write arbitrary well-formed documents. aoqi@0: * aoqi@0: * @author Kohsuke Kawaguchi aoqi@0: */ aoqi@0: public interface TypedXmlWriter { aoqi@0: /** aoqi@0: * Commits this element (and all its descendants) to the output. aoqi@0: * aoqi@0: *

aoqi@0: * Short for _commit(true). aoqi@0: */ aoqi@0: void commit(); aoqi@0: aoqi@0: /** aoqi@0: * Commits this element (and all its descendants) to the output. aoqi@0: * aoqi@0: *

aoqi@0: * Once a writer is committed, nothing can be added to it further. aoqi@0: * Committing allows TXW to output a part of the document even aoqi@0: * if the rest has not yet been written. aoqi@0: * aoqi@0: * @param includingAllPredecessors aoqi@0: * if false, this operation will _commit this writer and all its aoqi@0: * descendants writers. If true, in addition to those writers, aoqi@0: * this operation will close all the writers before this writer aoqi@0: * in the document order. aoqi@0: */ aoqi@0: void commit(boolean includingAllPredecessors); aoqi@0: aoqi@0: /** aoqi@0: * Blocks the writing of the start tag so that aoqi@0: * new attributes can be added even after child aoqi@0: * elements are appended. aoqi@0: * aoqi@0: *

aoqi@0: * This blocks the output at the token before the start tag until aoqi@0: * the {@link #commit()} method is called to _commit this element. aoqi@0: * aoqi@0: *

aoqi@0: * For more information, see the TXW documentation. aoqi@0: */ aoqi@0: void block(); aoqi@0: aoqi@0: /** aoqi@0: * Gets the {@link Document} object that this writer is writing to. aoqi@0: * aoqi@0: * @return aoqi@0: * always non-null. aoqi@0: */ aoqi@0: Document getDocument(); aoqi@0: aoqi@0: /** aoqi@0: * Adds an attribute of the given name and the value. aoqi@0: * aoqi@0: *

aoqi@0: * Short for

_attribute("",localName,value);
aoqi@0: * aoqi@0: * @see #_attribute(String, String, Object) aoqi@0: */ aoqi@0: void _attribute( String localName, Object value ); aoqi@0: aoqi@0: /** aoqi@0: * Adds an attribute of the given name and the value. aoqi@0: * aoqi@0: *

aoqi@0: * Short for

_attribute(new QName(nsUri,localName),value);
aoqi@0: * aoqi@0: * @see #_attribute(QName, Object) aoqi@0: */ aoqi@0: void _attribute( String nsUri, String localName, Object value ); aoqi@0: aoqi@0: /** aoqi@0: * Adds an attribute of the given name and the value. aoqi@0: * aoqi@0: * @param attributeName aoqi@0: * must not be null. aoqi@0: * @param value aoqi@0: * value of the attribute. aoqi@0: * must not be null. aoqi@0: * See the documentation for the conversion rules. aoqi@0: */ aoqi@0: void _attribute( QName attributeName, Object value ); aoqi@0: aoqi@0: /** aoqi@0: * Declares a new namespace URI on this element. aoqi@0: * aoqi@0: *

aoqi@0: * The runtime system will assign an unique prefix for the URI. aoqi@0: * aoqi@0: * @param uri aoqi@0: * can be empty, but must not be null. aoqi@0: */ aoqi@0: void _namespace( String uri ); aoqi@0: aoqi@0: /** aoqi@0: * Declares a new namespace URI on this element to aoqi@0: * a specific prefix. aoqi@0: * aoqi@0: * @param uri aoqi@0: * can be empty, but must not be null. aoqi@0: * @param prefix aoqi@0: * If non-empty, this prefix is bound to the URI aoqi@0: * on this element. If empty, then the runtime will still try to aoqi@0: * use the URI as the default namespace, but it may fail to do so aoqi@0: * because of the constraints in the XML. aoqi@0: * aoqi@0: * @throws IllegalArgumentException aoqi@0: * if the same prefix is already declared on this element. aoqi@0: */ aoqi@0: void _namespace( String uri, String prefix ); aoqi@0: aoqi@0: /** aoqi@0: * Declares a new namespace URI on this element. aoqi@0: * aoqi@0: *

aoqi@0: * The runtime system will assign an unique prefix for the URI. aoqi@0: * aoqi@0: * @param uri aoqi@0: * can be empty, but must not be null. aoqi@0: * @param requirePrefix aoqi@0: * if false, this method behaves just like {@link #_namespace(String)}. aoqi@0: * if true, this guarantees that the URI is bound to a non empty prefix. aoqi@0: */ aoqi@0: void _namespace( String uri, boolean requirePrefix ); aoqi@0: aoqi@0: /** aoqi@0: * Appends text data. aoqi@0: * aoqi@0: * @param value aoqi@0: * must not be null. aoqi@0: * See the documentation for the conversion rules. aoqi@0: */ aoqi@0: void _pcdata( Object value ); aoqi@0: aoqi@0: /** aoqi@0: * Appends CDATA section. aoqi@0: * aoqi@0: * @param value aoqi@0: * must not be null. aoqi@0: * See the documentation for the conversion rules. aoqi@0: */ aoqi@0: void _cdata( Object value ); aoqi@0: aoqi@0: /** aoqi@0: * Appends a comment. aoqi@0: * aoqi@0: * @param value aoqi@0: * must not be null. aoqi@0: * See the documentation for the conversion rules. aoqi@0: * aoqi@0: * @throws UnsupportedOperationException aoqi@0: * if the underlying {@link XmlSerializer} does not support aoqi@0: * writing comments, this exception can be thrown. aoqi@0: */ aoqi@0: void _comment( Object value ) throws UnsupportedOperationException; aoqi@0: aoqi@0: /** aoqi@0: * Appends a new child element. aoqi@0: * aoqi@0: *

aoqi@0: * Short for

_element(URI of this element,localName,contentModel);
aoqi@0: * aoqi@0: *

aoqi@0: * The namespace URI will be inherited from the parent element. aoqi@0: * aoqi@0: * @see #_element(String, String, Class) aoqi@0: */ aoqi@0: T _element( String localName, Class contentModel ); aoqi@0: aoqi@0: /** aoqi@0: * Appends a new child element. aoqi@0: * aoqi@0: *

aoqi@0: * The newly created child element is appended at the end of the children. aoqi@0: * aoqi@0: * @param nsUri aoqi@0: * The namespace URI of the newly created element. aoqi@0: * @param localName aoqi@0: * The local name of the newly created element. aoqi@0: * @param contentModel aoqi@0: * The typed XML writer interface used to write the children of aoqi@0: * the new child element. aoqi@0: * aoqi@0: * @return aoqi@0: * always return non-null {@link TypedXmlWriter} that can be used aoqi@0: * to write the contents of the newly created child element. aoqi@0: */ aoqi@0: T _element( String nsUri, String localName, Class contentModel ); aoqi@0: aoqi@0: /** aoqi@0: * Appends a new child element. aoqi@0: * aoqi@0: *

aoqi@0: * Short for

_element(tagName.getNamespaceURI(),tagName.getLocalPart(),contentModel);
aoqi@0: * aoqi@0: * @see #_element(String, String, Class) aoqi@0: */ aoqi@0: T _element( QName tagName, Class contentModel ); aoqi@0: aoqi@0: /** aoqi@0: * Appends a new child element. aoqi@0: * aoqi@0: *

aoqi@0: * This version of the _element method requires the T class to be aoqi@0: * annotated with {@link XmlElement} annotation. The element name will be aoqi@0: * taken from there. aoqi@0: * aoqi@0: * @see #_element(String, String, Class) aoqi@0: */ aoqi@0: T _element( Class contentModel ); aoqi@0: aoqi@0: /** aoqi@0: * Returns a different interface for this typed XML Writer. aoqi@0: * aoqi@0: *

aoqi@0: * Semantically, this operation is a 'cast' --- it returns the same underlying aoqi@0: * writer in a different interface. The returned new writer and the current writer aoqi@0: * will write to the same element. aoqi@0: * aoqi@0: *

aoqi@0: * But this is different from Java's ordinary cast because the returned object aoqi@0: * is not always the same as the current object. aoqi@0: * aoqi@0: * @return aoqi@0: * always return non-null. aoqi@0: */ aoqi@0: T _cast( Class targetInterface ); aoqi@0: }