1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/staxex/XMLStreamReaderEx.java Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,185 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.xml.internal.org.jvnet.staxex; 1.30 + 1.31 +import javax.xml.stream.XMLStreamReader; 1.32 +import javax.xml.stream.XMLStreamException; 1.33 + 1.34 +/** 1.35 + * {@link XMLStreamReader} extended for reading binary data. 1.36 + * 1.37 + * <p> 1.38 + * Some producer of infoset (in particular, such as FastInfoset, 1.39 + * XOP decoder), uses a native format that enables efficient 1.40 + * treatment of binary data. For ordinary infoset consumer 1.41 + * (that just uses {@link XMLStreamReader}, those binary data 1.42 + * will just look like base64-encoded string, but this interface 1.43 + * allows consumers of such infoset to access this raw binary data. 1.44 + * Such infoset producer may choose to implement this additoinal 1.45 + * interface, to expose this functionality. 1.46 + * 1.47 + * <p> 1.48 + * Consumers that are capable of using this interface can query 1.49 + * {@link XMLStreamReader} if it supports this by simply downcasting 1.50 + * it to this interface like this: 1.51 + * 1.52 + * <pre> 1.53 + * XMLStreamReader reader = ...; 1.54 + * if( reader instanceof XMLStreamReaderEx ) { 1.55 + * // this reader supports binary data exchange 1.56 + * ... 1.57 + * } else { 1.58 + * // noop 1.59 + * ... 1.60 + * } 1.61 + * </pre> 1.62 + * 1.63 + * <p> 1.64 + * Also note that it is also allowed for the infoset producer 1.65 + * to implement this interface in such a way that {@link #getPCDATA()} 1.66 + * always delegate to {@link #getText()}, although it's not desirable. 1.67 + * 1.68 + * <p> 1.69 + * This interface is a private contract between such producers 1.70 + * and consumers to allow them to exchange binary data without 1.71 + * converting it to base64. 1.72 + * 1.73 + * @see XMLStreamWriterEx 1.74 + * @author Kohsuke Kawaguchi 1.75 + * @author Paul Sandoz 1.76 + */ 1.77 +public interface XMLStreamReaderEx extends XMLStreamReader { 1.78 + ///** 1.79 + // * Works like {@link XMLStreamReader#getText()} 1.80 + // * but returns text as {@link DataSource}. 1.81 + // * 1.82 + // * <p> 1.83 + // * This method can be invoked whenever {@link XMLStreamReader#getText()} 1.84 + // * can be invoked. Invoking this method means the caller is assuming 1.85 + // * that the text is (conceptually) base64-encoded binary data. 1.86 + // * 1.87 + // * <p> 1.88 + // * This abstraction is necessary to treat XOP as infoset encoding. 1.89 + // * That is, you can either access the XOP-attached binary through 1.90 + // * {@link XMLStreamReader#getText()} (in which case you'll see the 1.91 + // * base64 encoded string), or you can access it as a binary data 1.92 + // * directly by using this method. 1.93 + // * 1.94 + // * <p> 1.95 + // * Note that even if you are reading from non XOP-aware {@link XMLStreamReader}, 1.96 + // * this method must be still supported; if the reader is pointing 1.97 + // * to a text, this method is responsible for decoding base64 and 1.98 + // * producing a {@link DataHandler} with "application/octet-stream" 1.99 + // * as the content type. 1.100 + // * 1.101 + // * @return 1.102 + // * always non-null valid object. 1.103 + // * Invocations of this method may return the same object as long 1.104 + // * as the {@link XMLStreamReader#next()} method is not used, 1.105 + // * but otherwise {@link DataSource} object returned from this method 1.106 + // * is considered to be owned by the client, and therefore it shouldn't 1.107 + // * be reused by the implementation of this method. 1.108 + // * 1.109 + // * <p> 1.110 + // * The returned {@link DataSource} is read-only, and the caller 1.111 + // * must not invoke {@link DataSource#getOutputStream()}. 1.112 + // * 1.113 + // * @throws IllegalStateException 1.114 + // * if the parser is not pointing at characters infoset item. 1.115 + // * @throws XMLStreamException 1.116 + // * if the parser points to text but text is not base64-encoded text, 1.117 + // * or if some other parsing error occurs (such as if the <xop:Include> 1.118 + // * points to a non-existing attachment.) 1.119 + // * 1.120 + // * <p> 1.121 + // * It is also OK for this method to return successfully, only to fail 1.122 + // * during an {@link InputStream} is read from {@link DataSource}. 1.123 + // */ 1.124 + //DataSource getTextAsDataHandler() throws XMLStreamException; 1.125 + 1.126 + ///** 1.127 + // * Works like {@link XMLStreamReader#getText()} 1.128 + // * but returns text as {@link byte[]}. 1.129 + // * 1.130 + // * <p> 1.131 + // * The contract of this method is mostly the same as 1.132 + // * {@link #getTextAsDataHandler()}, except that this 1.133 + // * method returns the binary datas as an exact-size byte[]. 1.134 + // * 1.135 + // * <p> 1.136 + // * This method is also not capable of reporting the content type 1.137 + // * of this binary data, even if it is available to the parser. 1.138 + // * 1.139 + // * @see #getTextAsDataHandler() 1.140 + // */ 1.141 + //byte[] getTextAsByteArray() throws XMLStreamException; 1.142 + 1.143 + /** 1.144 + * Works like {@link #getText()} 1.145 + * but hides the actual data representation. 1.146 + * 1.147 + * @return 1.148 + * The {@link CharSequence} that represents the 1.149 + * character infoset items at the current position. 1.150 + * 1.151 + * <p> 1.152 + * The {@link CharSequence} is normally a {@link String}, 1.153 + * but can be any other {@link CharSequence} implementation. 1.154 + * For binary data, however, use of {@link Base64Data} is 1.155 + * recommended (so that the consumer interested in seeing it 1.156 + * as binary data may take advantage of mor efficient 1.157 + * data representation.) 1.158 + * 1.159 + * <p> 1.160 + * The object returned from this method belongs to the parser, 1.161 + * and its content is guaranteed to be the same only until 1.162 + * the {@link #next()} method is invoked. 1.163 + * 1.164 + * @throws IllegalStateException 1.165 + * if the parser is not pointing at characters infoset item. 1.166 + * 1.167 + * TODO: 1.168 + * fix the dependency to JAXB internal class. 1.169 + */ 1.170 + CharSequence getPCDATA() throws XMLStreamException; 1.171 + 1.172 + /** 1.173 + * {@inheritDoc} 1.174 + */ 1.175 + NamespaceContextEx getNamespaceContext(); 1.176 + 1.177 + /** 1.178 + * Works like {@link #getElementText()} but trims the leading 1.179 + * and trailing whitespace. 1.180 + * 1.181 + * <p> 1.182 + * The parser can often do this more efficiently than 1.183 + * {@code getElementText().trim()}. 1.184 + * 1.185 + * @see #getElementText() 1.186 + */ 1.187 + String getElementTextTrim() throws XMLStreamException; 1.188 +}