View Javadoc

    1   package org.codehaus.xfire.util.stax;
    2
    3   import javax.xml.namespace.NamespaceContext;
    4   import javax.xml.namespace.QName;
    5   import javax.xml.stream.Location;
    6   import javax.xml.stream.XMLStreamConstants;
    7   import javax.xml.stream.XMLStreamException;
    8   import javax.xml.stream.XMLStreamReader;
    9
    10  /***
    11   * An XMLStreamReader which keeps track of the depth where we are.
    12   *
    13   * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse </a>
    14   * @since Nov 4, 2004
    15   */
    16  public class DepthXMLStreamReader
    17      implements XMLStreamReader
    18  {
    19      XMLStreamReader reader;
    20
    21      private int depth = 0;
    22
    23      public DepthXMLStreamReader(XMLStreamReader reader)
    24      {
    25          this.reader = reader;
    26      }
    27
    28      public int getDepth()
    29      {
    30          return depth;
    31      }
    32
    33      public void close() throws XMLStreamException
    34      {
    35          reader.close();
    36      }
    37
    38      public int getAttributeCount()
    39      {
    40          return reader.getAttributeCount();
    41      }
    42
    43      public String getAttributeLocalName(int arg0)
    44      {
    45          return reader.getAttributeLocalName(arg0);
    46      }
    47
    48      public QName getAttributeName(int arg0)
    49      {
    50          return reader.getAttributeName(arg0);
    51      }
    52
    53      public String getAttributeNamespace(int arg0)
    54      {
    55          return reader.getAttributeNamespace(arg0);
    56      }
    57
    58      public String getAttributePrefix(int arg0)
    59      {
    60          return reader.getAttributePrefix(arg0);
    61      }
    62
    63      public String getAttributeType(int arg0)
    64      {
    65          return reader.getAttributeType(arg0);
    66      }
    67
    68      public String getAttributeValue(int arg0)
    69      {
    70          return reader.getAttributeValue(arg0);
    71      }
    72
    73      public String getAttributeValue(String arg0, String arg1)
    74      {
    75          return reader.getAttributeValue(arg0, arg1);
    76      }
    77
    78      public String getCharacterEncodingScheme()
    79      {
    80          return reader.getCharacterEncodingScheme();
    81      }
    82
    83      public String getElementText() throws XMLStreamException
    84      {
    85          return reader.getElementText();
    86      }
    87
    88      public String getEncoding()
    89      {
    90          return reader.getEncoding();
    91      }
    92
    93      public int getEventType()
    94      {
    95          return reader.getEventType();
    96      }
    97
    98      public String getLocalName()
    99      {
    100         return reader.getLocalName();
    101     }
    102
    103     public Location getLocation()
    104     {
    105         return reader.getLocation();
    106     }
    107
    108     public QName getName()
    109     {
    110         return reader.getName();
    111     }
    112
    113     public NamespaceContext getNamespaceContext()
    114     {
    115         return reader.getNamespaceContext();
    116     }
    117
    118     public int getNamespaceCount()
    119     {
    120
    121         return reader.getNamespaceCount();
    122     }
    123
    124     public String getNamespacePrefix(int arg0)
    125     {
    126
    127         return reader.getNamespacePrefix(arg0);
    128     }
    129
    130     public String getNamespaceURI()
    131     {
    132
    133         return reader.getNamespaceURI();
    134     }
    135
    136     public String getNamespaceURI(int arg0)
    137     {
    138
    139         return reader.getNamespaceURI(arg0);
    140     }
    141
    142     public String getNamespaceURI(String arg0)
    143     {
    144
    145         return reader.getNamespaceURI(arg0);
    146     }
    147
    148     public String getPIData()
    149     {
    150
    151         return reader.getPIData();
    152     }
    153
    154     public String getPITarget()
    155     {
    156
    157         return reader.getPITarget();
    158     }
    159
    160     public String getPrefix()
    161     {
    162
    163         return reader.getPrefix();
    164     }
    165
    166     public Object getProperty(String arg0) throws IllegalArgumentException
    167     {
    168
    169         return reader.getProperty(arg0);
    170     }
    171
    172     public String getText()
    173     {
    174
    175         return reader.getText();
    176     }
    177
    178     public char[] getTextCharacters()
    179     {
    180         return reader.getTextCharacters();
    181     }
    182
    183     public int getTextCharacters(int arg0, char[] arg1, int arg2, int arg3)
    184             throws XMLStreamException
    185     {
    186         return reader.getTextCharacters(arg0, arg1, arg2, arg3);
    187     }
    188
    189     public int getTextLength()
    190     {
    191         return reader.getTextLength();
    192     }
    193
    194     public int getTextStart()
    195     {
    196
    197         return reader.getTextStart();
    198     }
    199
    200     public String getVersion()
    201     {
    202         return reader.getVersion();
    203     }
    204
    205     public boolean hasName()
    206     {
    207
    208         return reader.hasName();
    209     }
    210
    211     public boolean hasNext() throws XMLStreamException
    212     {
    213         return reader.hasNext();
    214     }
    215
    216     public boolean hasText()
    217     {
    218         return reader.hasText();
    219     }
    220
    221     public boolean isAttributeSpecified(int arg0)
    222     {
    223         return reader.isAttributeSpecified(arg0);
    224     }
    225
    226     public boolean isCharacters()
    227     {
    228
    229         return reader.isCharacters();
    230     }
    231
    232     public boolean isEndElement()
    233     {
    234
    235         return reader.isEndElement();
    236     }
    237
    238     public boolean isStandalone()
    239     {
    240
    241         return reader.isStandalone();
    242     }
    243
    244     public boolean isStartElement()
    245     {
    246
    247         return reader.isStartElement();
    248     }
    249
    250     public boolean isWhiteSpace()
    251     {
    252
    253         return reader.isWhiteSpace();
    254     }
    255
    256     public int next() throws XMLStreamException
    257     {
    258         int next = reader.next();
    259
    260         if ( next == START_ELEMENT )
    261         {
    262             depth++;
    263         }
    264         else if ( next == END_ELEMENT )
    265         {
    266             depth--;
    267         }
    268
    269         return next;
    270     }
    271
    272     public int nextTag()
    273         throws XMLStreamException
    274     {
    275         int eventType = next();
    276         while ((eventType == XMLStreamConstants.CHARACTERS && isWhiteSpace())
    277                 || (eventType == XMLStreamConstants.CDATA && isWhiteSpace())
    278                 // skip whitespace
    279                 || eventType == XMLStreamConstants.SPACE
    280                 || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
    281                 || eventType == XMLStreamConstants.COMMENT)
    282         {
    283             eventType = next();
    284         }
    285         if (eventType != XMLStreamConstants.START_ELEMENT
    286                 && eventType != XMLStreamConstants.END_ELEMENT)
    287         {
    288             throw new XMLStreamException("expected start or end tag", getLocation());
    289         }
    290         return eventType;
    291     }
    292
    293     public void require(int arg0, String arg1, String arg2)
    294             throws XMLStreamException
    295     {
    296         reader.require(arg0, arg1, arg2);
    297     }
    298
    299     public boolean standaloneSet()
    300     {
    301         return reader.standaloneSet();
    302     }
    303
    304     public int hashCode()
    305     {
    306         return reader.hashCode();
    307     }
    308
    309     public boolean equals(Object arg0)
    310     {
    311         return reader.equals(arg0);
    312     }
    313
    314     public String toString()
    315     {
    316         return reader.toString();
    317     }
    318
    319 }