private DeferredAction getAction()

in mixins/om-mixins/src/main/java/org/apache/axiom/om/impl/common/builder/CustomBuilderManager.java [79:144]


    private DeferredAction getAction(CoreNode node, int depth, int firstCustomBuilder) {
        lastCandidateElement = null;
        lastCandidateDepth = -1;
        if (node instanceof AxiomElement
                && (node instanceof AxiomSOAPHeaderBlock || !(node instanceof AxiomSOAPElement))) {
            AxiomElement element = (AxiomElement) node;
            if (registrations != null) {
                for (int i = firstCustomBuilder; i < registrations.size(); i++) {
                    CustomBuilderRegistration registration = registrations.get(i);
                    String namespaceURI = element.coreGetNamespaceURI();
                    String localName = element.coreGetLocalName();
                    if (registration
                            .getSelector()
                            .accepts(element.getParent(), depth, namespaceURI, localName)) {
                        CustomBuilder customBuilder = registration.getCustomBuilder();
                        if (log.isDebugEnabled()) {
                            log.debug(
                                    "Custom builder "
                                            + customBuilder
                                            + " accepted element {"
                                            + namespaceURI
                                            + "}"
                                            + localName
                                            + " at depth "
                                            + depth);
                        }
                        return () -> {
                            if (log.isDebugEnabled()) {
                                log.debug("Invoking custom builder " + customBuilder);
                            }
                            OMDataSource dataSource = customBuilder.create(element);
                            AxiomElementType<? extends AxiomSourcedElement> type;
                            if (element instanceof AxiomSOAP11HeaderBlock) {
                                type = AxiomNodeFactory::createSOAP11HeaderBlock;
                            } else if (element instanceof AxiomSOAP12HeaderBlock) {
                                type = AxiomNodeFactory::createSOAP12HeaderBlock;
                            } else {
                                type = AxiomNodeFactory::createSourcedElement;
                            }
                            AxiomSourcedElement newElement =
                                    type.create(
                                            (AxiomNodeFactory)
                                                    element.coreGetNodeFactory().getFactory2());
                            if (log.isDebugEnabled()) {
                                log.debug(
                                        "Replacing element with new sourced element of type "
                                                + newElement.getClass().getName());
                            }
                            newElement.init(
                                    localName, new OMNamespaceImpl(namespaceURI, null), dataSource);
                            try {
                                element.coreReplaceWith(newElement, AxiomSemantics.INSTANCE);
                            } catch (CoreModelException ex) {
                                throw AxiomExceptionTranslator.translate(ex);
                            }
                        };
                    }
                }
            }
            // Save a reference to the element so that we can process it when another custom builder
            // is registered
            lastCandidateElement = element;
            lastCandidateDepth = depth;
        }
        return null;
    }