Search in sources :

Example 1 with AxiomSOAPElement

use of org.apache.axiom.soap.impl.intf.AxiomSOAPElement in project webservices-axiom by apache.

the class CustomBuilderManager method getAction.

private Runnable getAction(CoreNode node, int depth, int firstCustomBuilder) {
    lastCandidateElement = null;
    lastCandidateDepth = -1;
    if (node instanceof AxiomElement && (node instanceof AxiomSOAPHeaderBlock || !(node instanceof AxiomSOAPElement))) {
        final AxiomElement element = (AxiomElement) node;
        if (registrations != null) {
            for (int i = firstCustomBuilder; i < registrations.size(); i++) {
                CustomBuilderRegistration registration = registrations.get(i);
                final String namespaceURI = element.coreGetNamespaceURI();
                final String localName = element.coreGetLocalName();
                if (registration.getSelector().accepts(element.getParent(), depth, namespaceURI, localName)) {
                    final CustomBuilder customBuilder = registration.getCustomBuilder();
                    if (log.isDebugEnabled()) {
                        log.debug("Custom builder " + customBuilder + " accepted element {" + namespaceURI + "}" + localName + " at depth " + depth);
                    }
                    return new Runnable() {

                        @Override
                        public void run() {
                            if (log.isDebugEnabled()) {
                                log.debug("Invoking custom builder " + customBuilder);
                            }
                            OMDataSource dataSource = customBuilder.create(element);
                            Class<? extends AxiomSourcedElement> type;
                            if (element instanceof AxiomSOAP11HeaderBlock) {
                                type = AxiomSOAP11HeaderBlock.class;
                            } else if (element instanceof AxiomSOAP12HeaderBlock) {
                                type = AxiomSOAP12HeaderBlock.class;
                            } else {
                                type = AxiomSourcedElement.class;
                            }
                            if (log.isDebugEnabled()) {
                                log.debug("Replacing element with new sourced element of type " + type);
                            }
                            AxiomSourcedElement newElement = element.coreCreateNode(type);
                            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;
}
Also used : OMDataSource(org.apache.axiom.om.OMDataSource) AxiomSOAPHeaderBlock(org.apache.axiom.soap.impl.intf.AxiomSOAPHeaderBlock) CustomBuilder(org.apache.axiom.om.ds.custombuilder.CustomBuilder) AxiomSOAP12HeaderBlock(org.apache.axiom.soap.impl.intf.AxiomSOAP12HeaderBlock) AxiomSOAPElement(org.apache.axiom.soap.impl.intf.AxiomSOAPElement) AxiomSourcedElement(org.apache.axiom.om.impl.intf.AxiomSourcedElement) CoreModelException(org.apache.axiom.core.CoreModelException) AxiomElement(org.apache.axiom.om.impl.intf.AxiomElement) AxiomSOAP11HeaderBlock(org.apache.axiom.soap.impl.intf.AxiomSOAP11HeaderBlock) OMNamespaceImpl(org.apache.axiom.om.impl.common.OMNamespaceImpl)

Aggregations

CoreModelException (org.apache.axiom.core.CoreModelException)1 OMDataSource (org.apache.axiom.om.OMDataSource)1 CustomBuilder (org.apache.axiom.om.ds.custombuilder.CustomBuilder)1 OMNamespaceImpl (org.apache.axiom.om.impl.common.OMNamespaceImpl)1 AxiomElement (org.apache.axiom.om.impl.intf.AxiomElement)1 AxiomSourcedElement (org.apache.axiom.om.impl.intf.AxiomSourcedElement)1 AxiomSOAP11HeaderBlock (org.apache.axiom.soap.impl.intf.AxiomSOAP11HeaderBlock)1 AxiomSOAP12HeaderBlock (org.apache.axiom.soap.impl.intf.AxiomSOAP12HeaderBlock)1 AxiomSOAPElement (org.apache.axiom.soap.impl.intf.AxiomSOAPElement)1 AxiomSOAPHeaderBlock (org.apache.axiom.soap.impl.intf.AxiomSOAPHeaderBlock)1