View Javadoc

    1   package org.codehaus.xfire.aegis.stax;
    2
    3   import javax.xml.namespace.QName;
    4   import javax.xml.stream.XMLStreamException;
    5   import javax.xml.stream.XMLStreamWriter;
    6
    7   import org.codehaus.xfire.XFireRuntimeException;
    8   import org.codehaus.xfire.aegis.AbstractMessageWriter;
    9   import org.codehaus.xfire.aegis.MessageWriter;
    10  import org.codehaus.xfire.util.NamespaceHelper;
    11
    12  public class AttributeWriter
    13      extends AbstractMessageWriter
    14  {
    15      private XMLStreamWriter writer;
    16      private String namespace;
    17      private String name;
    18      private String prefix;
    19
    20      public AttributeWriter(XMLStreamWriter writer,
    21                             String name,
    22                             String namespace)
    23      {
    24          this.writer = writer;
    25          this.name = name;
    26          this.namespace = namespace;
    27
    28          try
    29          {
    30              if (namespace != null && namespace.length() > 0)
    31                  prefix = NamespaceHelper.getUniquePrefix(writer, namespace, true);
    32              else
    33                  prefix = "";
    34          }
    35          catch (XMLStreamException e)
    36          {
    37              throw new XFireRuntimeException("Couldn't write to stream.");
    38          }
    39      }
    40
    41      public void writeValue(Object value)
    42      {
    43          try
    44          {
    45              writer.writeAttribute(prefix, namespace, name, value.toString());
    46          }
    47          catch (XMLStreamException e)
    48          {
    49              throw new XFireRuntimeException("Error writing document.", e);
    50          }
    51      }
    52
    53      public MessageWriter getAttributeWriter(String name)
    54      {
    55          throw new IllegalStateException();
    56      }
    57
    58      public MessageWriter getAttributeWriter(String name, String namespace)
    59      {
    60          throw new IllegalStateException();
    61      }
    62
    63      public MessageWriter getAttributeWriter(QName qname)
    64      {
    65          throw new IllegalStateException();
    66      }
    67
    68      public MessageWriter getElementWriter(String name)
    69      {
    70          throw new IllegalStateException();
    71      }
    72
    73      public MessageWriter getElementWriter(String name, String namespace)
    74      {
    75          throw new IllegalStateException();
    76      }
    77
    78      public MessageWriter getElementWriter(QName qname)
    79      {
    80          throw new IllegalStateException();
    81      }
    82
    83      public void close()
    84      {
    85      }
    86  }