1 /*
   2  * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.xml.stream.util;
  27 
  28 import javax.xml.namespace.QName;
  29 import javax.xml.namespace.NamespaceContext;
  30 import javax.xml.stream.XMLStreamReader;
  31 import javax.xml.stream.Location;
  32 import javax.xml.stream.XMLStreamException;
  33 
  34 /**
  35  * This is the base class for deriving an XMLStreamReader filter
  36  *
  37  * This class is designed to sit between an XMLStreamReader and an
  38  * application's XMLStreamReader.   By default each method
  39  * does nothing but call the corresponding method on the
  40  * parent interface.
  41  *
  42  * @version 1.0
  43  * @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
  44  * @see javax.xml.stream.XMLStreamReader
  45  * @see EventReaderDelegate
  46  * @since 1.6
  47  */
  48 
  49 public class StreamReaderDelegate implements XMLStreamReader {
  50   private XMLStreamReader reader;
  51 
  52   /**
  53    * Construct an empty filter with no parent.
  54    */
  55   public StreamReaderDelegate(){}
  56 
  57   /**
  58    * Construct an filter with the specified parent.
  59    * @param reader the parent
  60    */
  61   public StreamReaderDelegate(XMLStreamReader reader) {
  62     this.reader = reader;
  63   }
  64 
  65   /**
  66    * Set the parent of this instance.
  67    * @param reader the new parent
  68    */
  69   public void setParent(XMLStreamReader reader) {
  70     this.reader = reader;
  71   }
  72 
  73   /**
  74    * Get the parent of this instance.
  75    * @return the parent or null if none is set
  76    */
  77   public XMLStreamReader getParent() {
  78     return reader;
  79   }
  80 
  81   public int next()
  82     throws XMLStreamException
  83   {
  84     return reader.next();
  85   }
  86 
  87   public int nextTag()
  88     throws XMLStreamException
  89   {
  90     return reader.nextTag();
  91   }
  92 
  93   public String getElementText()
  94     throws XMLStreamException
  95   {
  96     return reader.getElementText();
  97   }
  98 
  99   public void require(int type, String namespaceURI, String localName)
 100     throws XMLStreamException
 101   {
 102     reader.require(type,namespaceURI,localName);
 103   }
 104 
 105   public boolean hasNext()
 106     throws XMLStreamException
 107   {
 108     return reader.hasNext();
 109   }
 110 
 111   public void close()
 112     throws XMLStreamException
 113   {
 114     reader.close();
 115   }
 116 
 117   public String getNamespaceURI(String prefix)
 118   {
 119     return reader.getNamespaceURI(prefix);
 120   }
 121 
 122   public NamespaceContext getNamespaceContext() {
 123     return reader.getNamespaceContext();
 124   }
 125 
 126   public boolean isStartElement() {
 127     return reader.isStartElement();
 128   }
 129 
 130   public boolean isEndElement() {
 131     return reader.isEndElement();
 132   }
 133 
 134   public boolean isCharacters() {
 135     return reader.isCharacters();
 136   }
 137 
 138   public boolean isWhiteSpace() {
 139     return reader.isWhiteSpace();
 140   }
 141 
 142   public String getAttributeValue(String namespaceUri,
 143                                   String localName)
 144   {
 145     return reader.getAttributeValue(namespaceUri,localName);
 146   }
 147 
 148   public int getAttributeCount() {
 149     return reader.getAttributeCount();
 150   }
 151 
 152   public QName getAttributeName(int index) {
 153     return reader.getAttributeName(index);
 154   }
 155 
 156   public String getAttributePrefix(int index) {
 157     return reader.getAttributePrefix(index);
 158   }
 159 
 160   public String getAttributeNamespace(int index) {
 161     return reader.getAttributeNamespace(index);
 162   }
 163 
 164   public String getAttributeLocalName(int index) {
 165     return reader.getAttributeLocalName(index);
 166   }
 167 
 168   public String getAttributeType(int index) {
 169     return reader.getAttributeType(index);
 170   }
 171 
 172   public String getAttributeValue(int index) {
 173     return reader.getAttributeValue(index);
 174   }
 175 
 176   public boolean isAttributeSpecified(int index) {
 177     return reader.isAttributeSpecified(index);
 178   }
 179 
 180   public int getNamespaceCount() {
 181     return reader.getNamespaceCount();
 182   }
 183 
 184   public String getNamespacePrefix(int index) {
 185     return reader.getNamespacePrefix(index);
 186   }
 187 
 188   public String getNamespaceURI(int index) {
 189     return reader.getNamespaceURI(index);
 190   }
 191 
 192   public int getEventType() {
 193     return reader.getEventType();
 194   }
 195 
 196   public String getText() {
 197     return reader.getText();
 198   }
 199 
 200   public int getTextCharacters(int sourceStart,
 201                                char[] target,
 202                                int targetStart,
 203                                int length)
 204     throws XMLStreamException {
 205     return reader.getTextCharacters(sourceStart,
 206                                     target,
 207                                     targetStart,
 208                                     length);
 209   }
 210 
 211 
 212   public char[] getTextCharacters() {
 213     return reader.getTextCharacters();
 214   }
 215 
 216   public int getTextStart() {
 217     return reader.getTextStart();
 218   }
 219 
 220   public int getTextLength() {
 221     return reader.getTextLength();
 222   }
 223 
 224   public String getEncoding() {
 225     return reader.getEncoding();
 226   }
 227 
 228   public boolean hasText() {
 229     return reader.hasText();
 230   }
 231 
 232   public Location getLocation() {
 233     return reader.getLocation();
 234   }
 235 
 236   public QName getName() {
 237     return reader.getName();
 238   }
 239 
 240   public String getLocalName() {
 241     return reader.getLocalName();
 242   }
 243 
 244   public boolean hasName() {
 245     return reader.hasName();
 246   }
 247 
 248   public String getNamespaceURI() {
 249     return reader.getNamespaceURI();
 250   }
 251 
 252   public String getPrefix() {
 253     return reader.getPrefix();
 254   }
 255 
 256   public String getVersion() {
 257     return reader.getVersion();
 258   }
 259 
 260   public boolean isStandalone() {
 261     return reader.isStandalone();
 262   }
 263 
 264   public boolean standaloneSet() {
 265     return reader.standaloneSet();
 266   }
 267 
 268   public String getCharacterEncodingScheme() {
 269     return reader.getCharacterEncodingScheme();
 270   }
 271 
 272   public String getPITarget() {
 273     return reader.getPITarget();
 274   }
 275 
 276   public String getPIData() {
 277     return reader.getPIData();
 278   }
 279 
 280   public Object getProperty(String name) {
 281     return reader.getProperty(name);
 282   }
 283 }