View Javadoc

    1   package org.codehaus.xfire.xmlbeans;
    2
    3   import javax.xml.stream.XMLStreamException;
    4
    5   import org.apache.xmlbeans.XmlCursor;
    6   import org.apache.xmlbeans.XmlObject;
    7   import org.codehaus.xfire.fault.XFireFault;
    8   import org.codehaus.xfire.soap.Soap11;
    9   import org.codehaus.yom.stax.StaxBuilder;
    10
    11  /***
    12   * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
    13   * @since Nov 17, 2004
    14   */
    15  public class XmlBeansFault
    16      extends XFireFault
    17  {
    18      private static final long serialVersionUID = 1L;
    19
    20      private XmlObject fault;
    21
    22      /***
    23       * @param fault The XmlObject representing the fault.
    24       */
    25      public XmlBeansFault(XmlObject fault)
    26      {
    27          super();
    28          this.fault = fault;
    29
    30          XmlCursor cursor = fault.newCursor();
    31          cursor.toFirstChild();
    32
    33          if (cursor.getName().getNamespaceURI().equals(Soap11.getInstance().getNamespace()))
    34              createSoap11Fault(cursor);
    35          else
    36              createSoap12Fault(cursor);
    37      }
    38
    39      /***
    40       * Fill in the fault information from the XmlCursor.
    41       * @param cursor
    42       */
    43      protected void createSoap11Fault(XmlCursor cursor)
    44      {
    45          cursor.toFirstChild();
    46
    47          do
    48          {
    49              if ( cursor.getName().getLocalPart().equals("faultcode") )
    50              {
    51                  setFaultCode( cursor.getTextValue() );
    52              }
    53              if ( cursor.getName().getLocalPart().equals("faultstring") )
    54              {
    55                  setMessage( cursor.getTextValue() );
    56              }
    57              if ( cursor.getName().getLocalPart().equals("faultactor") )
    58              {
    59                  setRole( cursor.getTextValue() );
    60              }
    61              if ( cursor.getName().getLocalPart().equals("detail") )
    62              {
    63                  StaxBuilder builder = new StaxBuilder();
    64                  try
    65                  {
    66                      setDetail( builder.buildElement(null, cursor.newXMLStreamReader()) );
    67                  }
    68                  catch (XMLStreamException e)
    69                  {
    70                      e.printStackTrace();
    71                  }
    72              }
    73          }
    74          while( cursor.toNextSibling() );
    75      }
    76
    77
    78      /***
    79       * Fill in the fault information from the XmlCursor.
    80       * @param cursor
    81       */
    82      protected void createSoap12Fault(XmlCursor cursor)
    83      {
    84          // TODO
    85      }
    86
    87      /***
    88       * @return Returns the fault.
    89       */
    90      public XmlObject getFault()
    91      {
    92          return fault;
    93      }
    94
    95      /***
    96       * @param fault The fault to set.
    97       */
    98      public void setFault(XmlObject fault)
    99      {
    100         this.fault = fault;
    101     }
    102 }