FileDocCategorySizeDatePackage
SOAPFault.javaAPI DocApache Axis 1.416031Sat Apr 22 18:57:28 BST 2006org.apache.axis.message

SOAPFault

public class SOAPFault extends SOAPBodyElement implements SOAPFault
A Fault body element.
author
Sam Ruby (rubys@us.ibm.com)
author
Glen Daniels (gdaniels@apache.org)
author
Tom Jordahl (tomj@macromedia.com)

Fields Summary
protected org.apache.axis.AxisFault
fault
protected String
prefix
private Locale
locale
protected Detail
detail
Constructors Summary
public SOAPFault(String namespace, String localName, String prefix, Attributes attrs, org.apache.axis.encoding.DeserializationContext context)

    
          
                        
         
    
        super(namespace, localName, prefix, attrs, context);
    
public SOAPFault(org.apache.axis.AxisFault fault)

        this.fault = fault;
    
Methods Summary
public javax.xml.soap.DetailaddDetail()
Creates a Detail object and sets it as the Detail object for this SOAPFaultException object.

It is illegal to add a detail when the fault already contains a detail. Therefore, this method should be called only after the existing detail has been removed.

return
the new Detail object
throws
SOAPException if this SOAPFaultException object already contains a valid Detail object

        if(getDetail() != null){
            throw new SOAPException(Messages.getMessage("valuePresent"));
        }
        Detail detail = convertToDetail(fault);
        addChildElement(detail);
        return detail;
    
private DetailconvertToDetail(org.apache.axis.AxisFault fault)
Convert the details in an AxisFault to a Detail object

param
fault source of the fault details
return
a detail element contructed from the AxisFault details
throws
SOAPException

        detail = new Detail();
        Element[] darray = fault.getFaultDetails();
        fault.setFaultDetail(new Element[]{});
        for (int i = 0; i < darray.length; i++)
        {
            Element detailtEntryElem = darray[i];
            DetailEntry detailEntry = detail.addDetailEntry(
                    new PrefixedQName(detailtEntryElem.getNamespaceURI(),
                            detailtEntryElem.getLocalName(), detailtEntryElem.getPrefix()));
            copyChildren(detailEntry, detailtEntryElem);
        }
        return detail;
    
private static voidcopyChildren(javax.xml.soap.SOAPElement soapElement, org.w3c.dom.Element domElement)
Copy the children of a DOM element to a SOAPElement.

param
soapElement target of the copy
param
domElement source for the copy
throws
SOAPException

        org.w3c.dom.NodeList nl = domElement.getChildNodes();
        for (int j = 0; j < nl.getLength(); j++)
        {
            org.w3c.dom.Node childNode = nl.item(j);
            if (childNode.getNodeType() == Node.TEXT_NODE)
            {
                soapElement.addTextNode(childNode.getNodeValue());
                break; // only one text node assmed
            }
            if (childNode.getNodeType() == Node.ELEMENT_NODE)
            {
                String uri = childNode.getNamespaceURI();
                SOAPElement childSoapElement = null;
                if (uri == null)
                {
                    childSoapElement = soapElement.addChildElement(childNode.getLocalName
                            ());
                }
                else
                {
                    childSoapElement = soapElement.addChildElement(
                            childNode.getLocalName(),
                            childNode.getPrefix(), uri);
                }
                copyChildren(childSoapElement, (Element) childNode);
            }
        }
    
public javax.xml.soap.DetailgetDetail()
Returns the detail element for this SOAPFaultException object.

A Detail object carries application-specific error information related to SOAPBodyElement objects.

return
a Detail object with application-specific error information

        List children = this.getChildren();
        if(children==null || children.size()<=0)
            return null;

        // find detail element
        for (int i=0; i < children.size(); i++) {
            Object obj = children.get(i);
            if (obj instanceof javax.xml.soap.Detail) {
                return (javax.xml.soap.Detail) obj;
            }
        }
        return null;
    
public org.apache.axis.AxisFaultgetFault()

        return fault;
    
public java.lang.StringgetFaultActor()
Gets the fault actor for this SOAPFaultException object.

return
a String giving the actor in the message path that caused this SOAPFaultException object
see
#setFaultActor(java.lang.String) setFaultActor(java.lang.String)

        return fault.getFaultActor();
    
public java.lang.StringgetFaultCode()
Gets the fault code for this SOAPFaultException object.

return
a String with the fault code

        return fault.getFaultCode().getLocalPart();
    
public javax.xml.soap.NamegetFaultCodeAsName()

        QName qname = fault.getFaultCode();
        String uri = qname.getNamespaceURI();
        String local = qname.getLocalPart();
        return new PrefixedQName(uri, local, prefix);
    
private javax.xml.namespace.QNamegetFaultQName(java.lang.Class cls, org.apache.axis.encoding.SerializationContext context)

        QName qname = null;       
        if (! cls.equals(AxisFault.class)) {
            FaultDesc faultDesc = null;
            if (context.getMessageContext() != null) {
                OperationDesc op = context.getMessageContext().getOperation();
                if (op != null) {
                    faultDesc = op.getFaultByClass(cls);
                }
            }
                
            if (faultDesc != null) {
                qname = faultDesc.getQName();
            }
        }
        return qname;
    
public java.lang.StringgetFaultString()
Gets the fault string for this SOAPFaultException object.

return
a String giving an explanation of the fault

        return fault.getFaultString();
    
public java.util.LocalegetFaultStringLocale()

        return locale;
    
public voidoutputImpl(org.apache.axis.encoding.SerializationContext context)

        SOAPConstants soapConstants = context.getMessageContext() == null ?
                                        SOAPConstants.SOAP11_CONSTANTS :
                                        context.getMessageContext().getSOAPConstants();

        namespaceURI = soapConstants.getEnvelopeURI();
        name = Constants.ELEM_FAULT;
        
        context.registerPrefixForURI(prefix, soapConstants.getEnvelopeURI());
        context.startElement(new QName(this.getNamespaceURI(),
                                       this.getName()),
                             attributes);
        
        // XXX - Can fault be anything but an AxisFault here?
        if (fault instanceof AxisFault) {
            AxisFault axisFault = fault;
            if (axisFault.getFaultCode() != null) {
                // Do this BEFORE starting the element, so the prefix gets
                // registered if needed.
                if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) {
                    String faultCode = context.qName2String(axisFault.getFaultCode());
                    context.startElement(Constants.QNAME_FAULTCODE_SOAP12, null);
                    context.startElement(Constants.QNAME_FAULTVALUE_SOAP12, null);
                    context.writeSafeString(faultCode);
                    context.endElement();
                    QName[] subcodes = axisFault.getFaultSubCodes();
                    if (subcodes != null) {
                        for (int i = 0; i < subcodes.length; i++) {
                            faultCode = context.qName2String(subcodes[i]);
                            context.startElement(Constants.QNAME_FAULTSUBCODE_SOAP12, null);
                            context.startElement(Constants.QNAME_FAULTVALUE_SOAP12, null);
                            context.writeSafeString(faultCode);
                            context.endElement();
                        }

                        for (int i = 0; i < subcodes.length; i++)
                            context.endElement();

                    }
                    context.endElement();
                } else {
                    String faultCode = context.qName2String(axisFault.getFaultCode());
                    context.startElement(Constants.QNAME_FAULTCODE, null);
                    context.writeSafeString(faultCode);
                    context.endElement();
                }
            }
            
            if (axisFault.getFaultString() != null) {
                if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) {
                    context.startElement(Constants.QNAME_FAULTREASON_SOAP12, null);
                    AttributesImpl attrs = new AttributesImpl();
                    attrs.addAttribute("http://www.w3.org/XML/1998/namespace", "lang", "xml:lang", "CDATA", "en");
                    context.startElement(Constants.QNAME_TEXT_SOAP12, attrs);
                } else
                    context.startElement(Constants.QNAME_FAULTSTRING, null);
                context.writeSafeString(axisFault.getFaultString());
                context.endElement();
                if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) {
                    context.endElement();
                }
            }
            
            if (axisFault.getFaultActor() != null) {
                if (soapConstants == SOAPConstants.SOAP12_CONSTANTS)
                    context.startElement(Constants.QNAME_FAULTROLE_SOAP12, null);
                else
                    context.startElement(Constants.QNAME_FAULTACTOR, null);

                context.writeSafeString(axisFault.getFaultActor());
                context.endElement();
            }

            if (axisFault.getFaultNode() != null) {
                if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) {
                    context.startElement(Constants.QNAME_FAULTNODE_SOAP12, null);
                    context.writeSafeString(axisFault.getFaultNode());
                    context.endElement();
                }
            }
            
            // get the QName for this faults detail element
            QName qname = getFaultQName(fault.getClass(), context);
            if (qname == null && fault.detail != null) {
                qname = getFaultQName(fault.detail.getClass(), context);
            }
            if (qname == null) {
                // not the greatest, but...
                qname = new QName("", "faultData");
            }
            Element[] faultDetails = axisFault.getFaultDetails();
            if (faultDetails != null) {
                if (soapConstants == SOAPConstants.SOAP12_CONSTANTS)
                    context.startElement(Constants.QNAME_FAULTDETAIL_SOAP12, null);
                else
                    context.startElement(Constants.QNAME_FAULTDETAILS, null);

                // Allow the fault to write its data, if any
                axisFault.writeDetails(qname, context);
                // Then output any other elements
                for (int i = 0; i < faultDetails.length; i++) {
                    context.writeDOMElement(faultDetails[i]);
                }

                if (detail!= null) {
                    for (Iterator it = detail.getChildren().iterator(); it.hasNext();) {
                        ((NodeImpl)it.next()).output(context);
                    }
                }
        
                context.endElement();
            }
        }
        
        context.endElement();
    
public voidsetFault(org.apache.axis.AxisFault fault)

        this.fault = fault;
    
public voidsetFaultActor(java.lang.String faultActor)
Sets this SOAPFaultException object with the given fault actor.

The fault actor is the recipient in the message path who caused the fault to happen.

param
faultActor a String identifying the actor that caused this SOAPFaultException object
throws
SOAPException if there was an error in adding the faultActor to the underlying XML tree.

        fault.setFaultActor(faultActor);
    
public voidsetFaultCode(javax.xml.soap.Name faultCodeQName)

        String uri = faultCodeQName.getURI();
        String local = faultCodeQName.getLocalName();
        String prefix = faultCodeQName.getPrefix();

        this.prefix = prefix;
        QName qname = new QName(uri,local);
        fault.setFaultCode(qname);
    
public voidsetFaultCode(java.lang.String faultCode)
Sets this SOAPFaultException object with the given fault code.

Fault codes, which given information about the fault, are defined in the SOAP 1.1 specification.

param
faultCode a String giving the fault code to be set; must be one of the fault codes defined in the SOAP 1.1 specification
throws
SOAPException if there was an error in adding the faultCode to the underlying XML tree.

        fault.setFaultCodeAsString(faultCode);
    
public voidsetFaultString(java.lang.String faultString)
Sets the fault string for this SOAPFaultException object to the given string.

param
faultString a String giving an explanation of the fault
throws
SOAPException if there was an error in adding the faultString to the underlying XML tree.
see
#getFaultString() getFaultString()

        fault.setFaultString(faultString);
    
public voidsetFaultString(java.lang.String faultString, java.util.Locale locale)

        fault.setFaultString(faultString);
        this.locale = locale;