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

SOAPFaultDetailsBuilder

public class SOAPFaultDetailsBuilder extends SOAPHandler implements org.apache.axis.encoding.Callback
Handle deserializing fault details.
author
Glen Daniels (gdaniels@apache.org)
author
Tom Jordahl (tomj@macromedia.com)

Fields Summary
protected SOAPFaultBuilder
builder
Constructors Summary
public SOAPFaultDetailsBuilder(SOAPFaultBuilder builder)

        this.builder = builder;
    
Methods Summary
public SOAPHandleronStartChild(java.lang.String namespace, java.lang.String name, java.lang.String prefix, org.xml.sax.Attributes attributes, org.apache.axis.encoding.DeserializationContext context)

        // Get QName of element
        QName qn = new QName(namespace, name); 
                        
        // Look for <exceptionName> element and create a class
        // with that name - this is Axis specific and is
        // replaced by the Exception map 
        if (name.equals("exceptionName")) {
            // Set up deser of exception name string
            Deserializer dser = context.getDeserializerForType(Constants.XSD_STRING);
            dser.registerValueTarget(new CallbackTarget(this, "exceptionName"));
            return (SOAPHandler)dser;
        }
                        
        // Look up this element in our faultMap
        // if we find a match, this element is the fault data
        MessageContext msgContext = context.getMessageContext();
        SOAPConstants soapConstants = Constants.DEFAULT_SOAP_VERSION;
        OperationDesc op = null;
        if (msgContext != null) {
            soapConstants = msgContext.getSOAPConstants();
            op = msgContext.getOperation();
        }
        Class faultClass = null;
        QName faultXmlType = null;
        if (op != null) {
            FaultDesc faultDesc = null;
            // allow fault type to be denoted in xsi:type
            faultXmlType = context.getTypeFromAttributes(namespace,
                                                         name,
                                                         attributes);
            if (faultXmlType != null) {
                faultDesc = op.getFaultByXmlType(faultXmlType);
            }

            // If we didn't get type information, look up QName of fault
            if (faultDesc == null) {
                faultDesc = op.getFaultByQName(qn);
                if ((faultXmlType == null) && (faultDesc != null)) {
                    faultXmlType = faultDesc.getXmlType();
                }
            }

            if (faultDesc == null && op.getFaults() != null) {
                Iterator i = op.getFaults().iterator();
                while(i.hasNext()) {
                    FaultDesc fdesc = (FaultDesc) i.next();
                    if(fdesc.getClassName().equals(name)) {
                        faultDesc = fdesc;  
                        faultXmlType = fdesc.getXmlType();
                        break;
                    }
                }
            }
            
            // Set the class if we found a description
            if (faultDesc != null) {
                try {
                    faultClass = ClassUtils.forName(faultDesc.getClassName());
                } catch (ClassNotFoundException e) {
                    // Just create an AxisFault, no custom exception
                }
            }
        } else {
            faultXmlType = context.getTypeFromAttributes(namespace,
                                                       name,
                                                       attributes); 
        }

        if (faultClass == null) {
            faultClass =
                    context.getTypeMapping().getClassForQName(faultXmlType);
        }
        
        if(faultClass != null && faultXmlType != null) {
            builder.setFaultClass(faultClass);
            builder.setWaiting(true);
            // register callback for the data, use the xmlType from fault info
            Deserializer dser = null;
            if (attributes.getValue(soapConstants.getAttrHref()) == null) {
                dser = context.getDeserializerForType(faultXmlType);
            } else {
                dser = new DeserializerImpl();
                dser.setDefaultType(faultXmlType);
            }
            if (dser != null) {
                dser.registerValueTarget(new CallbackTarget(this, "faultData"));
            }
            return (SOAPHandler)dser;
        }
        return null;
    
public voidsetValue(java.lang.Object value, java.lang.Object hint)

        if ("faultData".equals(hint)) {
            builder.setFaultData(value);
        } else if ("exceptionName".equals(hint)) {
            String faultClassName = (String) value;
            try {
                Class faultClass = ClassUtils.forName(faultClassName);
                builder.setFaultClass(faultClass);
            } catch (ClassNotFoundException e) {
                // Just create an AxisFault, no custom exception
            }
        }
        
    
public voidstartElement(java.lang.String namespace, java.lang.String localName, java.lang.String prefix, org.xml.sax.Attributes attributes, org.apache.axis.encoding.DeserializationContext context)

        SOAPConstants soapConstants = context.getSOAPConstants();

        if (soapConstants == SOAPConstants.SOAP12_CONSTANTS &&
            attributes.getValue(Constants.URI_SOAP12_ENV, Constants.ATTR_ENCODING_STYLE) != null) {

            AxisFault fault = new AxisFault(Constants.FAULT_SOAP12_SENDER,
                null, Messages.getMessage("noEncodingStyleAttrAppear", "Detail"), null, null, null);

            throw new SAXException(fault);
        }

        super.startElement(namespace, localName, prefix, attributes, context);