public SOAPHandler onStartChild()

in axis-rt-core/src/main/java/org/apache/axis/message/BodyBuilder.java [100:225]


    public SOAPHandler onStartChild(String namespace,
                                     String localName,
                                     String prefix,
                                     Attributes attributes,
                                     DeserializationContext context)
        throws SAXException
    {
        SOAPBodyElement element = null;
        if (log.isDebugEnabled()) {
            log.debug("Enter: BodyBuilder::onStartChild()");
        }

        QName qname = new QName(namespace, localName);
        SOAPHandler handler = null;

        /** We're about to create a body element.  So we really need
         * to know at this point if this is an RPC service or not.  It's
         * possible that no one has set the service up until this point,
         * so if that's the case we should attempt to set it based on the
         * namespace of the first root body element.  Setting the
         * service may (should?) result in setting the service
         * description, which can then tell us what to create.
         */
        boolean isRoot = true;
        String root = attributes.getValue(Constants.URI_DEFAULT_SOAP_ENC,
                                          Constants.ATTR_ROOT);
        if ((root != null) && root.equals("0")) isRoot = false;

        MessageContext msgContext = context.getMessageContext();
        OperationDesc [] operations = null;
        try {
            if(msgContext != null) {
                 operations = msgContext.getPossibleOperationsByQName(qname);
            }

            // If there's only one match, set it in the MC now
            if ((operations != null) && (operations.length == 1))
                msgContext.setOperation(operations[0]);
        } catch (org.apache.axis.AxisFault e) {
            // SAXException is already known to this method, so I
            // don't have an exception-handling propogation explosion.
            throw new SAXException(e);
        }

        Style style = operations == null ? Style.RPC : operations[0].getStyle();
        SOAPConstants soapConstants = context.getSOAPConstants();

        /** Now we make a plain SOAPBodyElement IF we either:
         * a) have an non-root element, or
         * b) have a non-RPC service
         */
        if (localName.equals(Constants.ELEM_FAULT) &&
            namespace.equals(soapConstants.getEnvelopeURI())) {
            try {
                element = new SOAPFault(namespace, localName, prefix,
                                               attributes, context);
            } catch (AxisFault axisFault) {
                throw new SAXException(axisFault);
            }
            element.setEnvelope(context.getEnvelope());
            handler = new SOAPFaultBuilder((SOAPFault)element,
                                           context);
        } else if (!gotRPCElement) {
            if (isRoot && (style != Style.MESSAGE)) {
                gotRPCElement = true;

                try {

                    element = new RPCElement(namespace, localName, prefix,
                            attributes, context, operations);

                } catch (org.apache.axis.AxisFault e) {
                    // SAXException is already known to this method, so I
                    // don't have an exception-handling propogation explosion.
                    //
                    throw new SAXException(e);
                }

                // Only deserialize this way if there is a unique operation
                // for this QName.  If there are overloads,
                // we'll need to start recording.  If we're making a high-
                // fidelity recording anyway, don't bother (for now).
                if (msgContext != null && !msgContext.isHighFidelity() &&
                        (operations == null || operations.length == 1)) {
                    ((RPCElement)element).setNeedDeser(false);
                    boolean isResponse = false;
                    if (msgContext.getCurrentMessage() != null &&
                                Message.RESPONSE.equals(msgContext.getCurrentMessage().getMessageType()))
                        isResponse = true;
                    handler = new RPCHandler((RPCElement)element,
                                             isResponse);
                    if (operations != null) {
                        ((RPCHandler)handler).setOperation(operations[0]);
                        msgContext.setOperation(operations[0]);
                    }
                }
            }
        }

        if (element == null) {
            if ((style == Style.RPC) &&
                soapConstants == SOAPConstants.SOAP12_CONSTANTS) {
                throw new SAXException(Messages.getMessage("onlyOneBodyFor12"));
            }
            try {
                element = new SOAPBodyElement(namespace, localName, prefix,
                                          attributes, context);
            } catch (AxisFault axisFault) {
                throw new SAXException(axisFault);
            }
            if (element.getFixupDeserializer() != null)
                handler = (SOAPHandler)element.getFixupDeserializer();
        }

        if (handler == null)
            handler = new SOAPHandler();

        handler.myElement = element;

        //context.pushNewElement(element);

        if (log.isDebugEnabled()) {
            log.debug("Exit: BodyBuilder::onStartChild()");
        }
        return handler;
    }