View Javadoc

    1   package org.codehaus.xfire.aegis.yom;
    2
    3   import javax.xml.namespace.QName;
    4   import javax.xml.stream.XMLStreamReader;
    5
    6   import org.codehaus.xfire.aegis.AbstractMessageReader;
    7   import org.codehaus.xfire.aegis.MessageReader;
    8   import org.codehaus.xfire.aegis.stax.AttributeReader;
    9   import org.codehaus.yom.Attribute;
    10  import org.codehaus.yom.Element;
    11  import org.codehaus.yom.Elements;
    12
    13  public class YOMReader
    14      extends AbstractMessageReader
    15      implements MessageReader
    16  {
    17      private Element element;
    18      private int currentChild = 0;
    19      private int currentAttribute = 0;
    20      private Elements elements;
    21      private QName qname;
    22
    23      public YOMReader(Element element)
    24      {
    25          this.element = element;
    26          this.elements = element.getChildElements();
    27      }
    28
    29      public String getValue()
    30      {
    31          return element.getValue();
    32      }
    33
    34      public String getValue(String ns, String attr)
    35      {
    36          return element.getAttributeValue(attr, ns);
    37      }
    38
    39      public boolean hasMoreElementReaders()
    40      {
    41          return (currentChild < elements.size());
    42      }
    43
    44      public MessageReader getNextElementReader()
    45      {
    46          currentChild++;
    47          return new YOMReader(elements.get(currentChild-1));
    48      }
    49
    50      public QName getName()
    51      {
    52          if (qname == null)
    53          {
    54              qname = new QName(element.getNamespaceURI(),
    55                                element.getLocalName(),
    56                                element.getNamespacePrefix());
    57          }
    58          return qname;
    59      }
    60
    61      public String getLocalName()
    62      {
    63          return element.getLocalName();
    64      }
    65
    66      public String getNamespace()
    67      {
    68          return element.getNamespaceURI();
    69      }
    70
    71      public XMLStreamReader getXMLStreamReader()
    72      {
    73          throw new UnsupportedOperationException("Stream reading not supported from a YOMWriter.");
    74      }
    75
    76      public boolean hasMoreAttributeReaders()
    77      {
    78          return (currentAttribute < element.getAttributeCount());
    79      }
    80
    81      public MessageReader getNextAttributeReader()
    82      {
    83          currentAttribute++;
    84          Attribute att = element.getAttribute(currentAttribute);
    85
    86          return new AttributeReader(new QName(att.getNamespaceURI(), att.getLocalName()), att.getValue());
    87      }
    88  }