Search in sources :

Example 1 with AxiomElement

use of org.apache.axiom.om.impl.intf.AxiomElement in project webservices-axiom by apache.

the class SOAP11BuilderHelper method handleEvent.

@Override
public Class<? extends AxiomElement> handleEvent(OMElement parent, int elementLevel, String namespaceURI, String localName) throws SOAPProcessingException {
    Class<? extends AxiomElement> elementType = null;
    if (elementLevel == 4) {
        if (SOAP_FAULT_CODE_LOCAL_NAME.equals(localName)) {
            elementType = AxiomSOAP11FaultCode.class;
            faultcodePresent = true;
        } else if (SOAP_FAULT_STRING_LOCAL_NAME.equals(localName)) {
            elementType = AxiomSOAP11FaultReason.class;
            faultstringPresent = true;
        } else if (SOAP_FAULT_ACTOR_LOCAL_NAME.equals(localName)) {
            elementType = AxiomSOAP11FaultRole.class;
        } else if (SOAP_FAULT_DETAIL_LOCAL_NAME.equals(localName)) {
            elementType = AxiomSOAP11FaultDetail.class;
        } else {
            elementType = AxiomElement.class;
        }
    } else if (elementLevel == 5) {
        String parentTagName = "";
        if (parent instanceof Element) {
            parentTagName = ((Element) parent).getTagName();
        } else {
            parentTagName = parent.getLocalName();
        }
        if (parentTagName.equals(SOAP_FAULT_CODE_LOCAL_NAME)) {
            throw new SOAPProcessingException("faultcode element should not have children");
        } else if (parentTagName.equals(SOAP_FAULT_STRING_LOCAL_NAME)) {
            throw new SOAPProcessingException("faultstring element should not have children");
        } else if (parentTagName.equals(SOAP_FAULT_ACTOR_LOCAL_NAME)) {
            throw new SOAPProcessingException("faultactor element should not have children");
        } else {
            elementType = AxiomElement.class;
        }
    } else if (elementLevel > 5) {
        elementType = AxiomElement.class;
    }
    return elementType;
}
Also used : AxiomSOAP11FaultDetail(org.apache.axiom.soap.impl.intf.AxiomSOAP11FaultDetail) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) AxiomElement(org.apache.axiom.om.impl.intf.AxiomElement) SOAPProcessingException(org.apache.axiom.soap.SOAPProcessingException) AxiomElement(org.apache.axiom.om.impl.intf.AxiomElement) AxiomSOAP11FaultReason(org.apache.axiom.soap.impl.intf.AxiomSOAP11FaultReason)

Example 2 with AxiomElement

use of org.apache.axiom.om.impl.intf.AxiomElement 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)

Example 3 with AxiomElement

use of org.apache.axiom.om.impl.intf.AxiomElement in project webservices-axiom by apache.

the class OMFactoryImpl method importChildNode.

private AxiomChildNode importChildNode(OMNode child) {
    int type = child.getType();
    switch(type) {
        case OMNode.ELEMENT_NODE:
            {
                OMElement element = (OMElement) child;
                AxiomElement importedElement = createNode(AxiomElement.class);
                copyName(element, importedElement);
                for (Iterator<OMAttribute> it = element.getAllAttributes(); it.hasNext(); ) {
                    importedElement.coreAppendAttribute(importAttribute(it.next()));
                }
                for (Iterator<OMNamespace> it = element.getAllDeclaredNamespaces(); it.hasNext(); ) {
                    OMNamespace ns = it.next();
                    AxiomNamespaceDeclaration nsDecl = createNode(AxiomNamespaceDeclaration.class);
                    nsDecl.coreSetDeclaredNamespace(ns.getPrefix(), ns.getNamespaceURI());
                    importedElement.coreAppendAttribute(nsDecl);
                }
                importChildren(element, importedElement);
                return importedElement;
            }
        case OMNode.TEXT_NODE:
        case OMNode.SPACE_NODE:
        case OMNode.CDATA_SECTION_NODE:
            {
                OMText text = (OMText) child;
                Object content;
                if (text.isBinary()) {
                    content = new TextContent(text.getContentID(), text.getDataHandler(), text.isOptimized());
                } else {
                    content = text.getText();
                }
                return createAxiomText(null, content, type);
            }
        case OMNode.PI_NODE:
            {
                OMProcessingInstruction pi = (OMProcessingInstruction) child;
                AxiomProcessingInstruction importedPI = createNode(AxiomProcessingInstruction.class);
                importedPI.setTarget(pi.getTarget());
                importedPI.setValue(pi.getValue());
                return importedPI;
            }
        case OMNode.COMMENT_NODE:
            {
                OMComment comment = (OMComment) child;
                AxiomComment importedComment = createNode(AxiomComment.class);
                importedComment.setValue(comment.getValue());
                return importedComment;
            }
        case OMNode.DTD_NODE:
            {
                OMDocType docType = (OMDocType) child;
                AxiomDocType importedDocType = createNode(AxiomDocType.class);
                importedDocType.coreSetRootName(docType.getRootName());
                importedDocType.coreSetPublicId(docType.getPublicId());
                importedDocType.coreSetSystemId(docType.getSystemId());
                importedDocType.coreSetInternalSubset(docType.getInternalSubset());
                return importedDocType;
            }
        case OMNode.ENTITY_REFERENCE_NODE:
            AxiomEntityReference importedEntityRef = createNode(AxiomEntityReference.class);
            importedEntityRef.coreSetName(((OMEntityReference) child).getName());
            return importedEntityRef;
        default:
            throw new IllegalArgumentException("Unsupported node type");
    }
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) AxiomDocType(org.apache.axiom.om.impl.intf.AxiomDocType) AxiomProcessingInstruction(org.apache.axiom.om.impl.intf.AxiomProcessingInstruction) AxiomEntityReference(org.apache.axiom.om.impl.intf.AxiomEntityReference) OMElement(org.apache.axiom.om.OMElement) AxiomNamespaceDeclaration(org.apache.axiom.om.impl.intf.AxiomNamespaceDeclaration) OMProcessingInstruction(org.apache.axiom.om.OMProcessingInstruction) OMDocType(org.apache.axiom.om.OMDocType) OMComment(org.apache.axiom.om.OMComment) AxiomComment(org.apache.axiom.om.impl.intf.AxiomComment) Iterator(java.util.Iterator) OMText(org.apache.axiom.om.OMText) AxiomElement(org.apache.axiom.om.impl.intf.AxiomElement) TextContent(org.apache.axiom.om.impl.intf.TextContent)

Example 4 with AxiomElement

use of org.apache.axiom.om.impl.intf.AxiomElement in project webservices-axiom by apache.

the class OMFactoryImpl method createOMElement.

@Override
public final OMElement createOMElement(QName qname, OMContainer parent) {
    AxiomElement element = createNode(AxiomElement.class);
    if (parent != null) {
        parent.addChild(element);
    }
    element.internalSetLocalName(qname.getLocalPart());
    String prefix = qname.getPrefix();
    String namespaceURI = qname.getNamespaceURI();
    if (namespaceURI.length() > 0) {
        // The goal here is twofold:
        //  * check if the namespace needs to be declared;
        //  * locate an existing OMNamespace object, so that we can avoid creating a new one.
        OMNamespace ns = element.findNamespace(namespaceURI, prefix.length() == 0 ? null : prefix);
        if (ns == null) {
            if ("".equals(prefix)) {
                prefix = generatePrefix(namespaceURI);
            }
            ns = element.declareNamespace(namespaceURI, prefix);
        }
        element.internalSetNamespace(ns);
    } else if (prefix.length() > 0) {
        throw new IllegalArgumentException("Cannot create a prefixed element with an empty namespace name");
    } else {
        if (element.getDefaultNamespace() != null) {
            element.declareDefaultNamespace("");
        }
        element.internalSetNamespace(null);
    }
    return element;
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) AxiomElement(org.apache.axiom.om.impl.intf.AxiomElement)

Example 5 with AxiomElement

use of org.apache.axiom.om.impl.intf.AxiomElement in project webservices-axiom by apache.

the class SOAP12BuilderHelper method handleEvent.

@Override
public Class<? extends AxiomElement> handleEvent(OMElement parent, int elementLevel, String namespaceURI, String localName) throws SOAPProcessingException {
    Class<? extends AxiomElement> elementType = null;
    if (elementLevel == 4) {
        if (localName.equals(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME)) {
            if (codePresent) {
                throw new SOAPProcessingException("Multiple Code element encountered");
            } else {
                elementType = AxiomSOAP12FaultCode.class;
                codePresent = true;
                codeprocessing = true;
            }
        } else if (localName.equals(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME)) {
            if (!codeprocessing && !subCodeProcessing) {
                if (codePresent) {
                    if (reasonPresent) {
                        throw new SOAPProcessingException("Multiple Reason Element encountered");
                    } else {
                        elementType = AxiomSOAP12FaultReason.class;
                        reasonPresent = true;
                        reasonProcessing = true;
                    }
                } else {
                    throw new SOAPProcessingException("Wrong element order encountred at " + localName);
                }
            } else {
                if (codeprocessing) {
                    throw new SOAPProcessingException("Code doesn't have a value");
                } else {
                    throw new SOAPProcessingException("A subcode doesn't have a Value");
                }
            }
        } else if (localName.equals(SOAP12Constants.SOAP_FAULT_NODE_LOCAL_NAME)) {
            if (!reasonProcessing) {
                if (reasonPresent && !rolePresent && !detailPresent) {
                    if (nodePresent) {
                        throw new SOAPProcessingException("Multiple Node element encountered");
                    } else {
                        elementType = AxiomSOAP12FaultNode.class;
                        nodePresent = true;
                    }
                } else {
                    throw new SOAPProcessingException("wrong element order encountered at " + localName);
                }
            } else {
                throw new SOAPProcessingException("Reason element Should have a text");
            }
        } else if (localName.equals(SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME)) {
            if (!reasonProcessing) {
                if (reasonPresent && !detailPresent) {
                    if (rolePresent) {
                        throw new SOAPProcessingException("Multiple Role element encountered");
                    } else {
                        elementType = AxiomSOAP12FaultRole.class;
                        rolePresent = true;
                    }
                } else {
                    throw new SOAPProcessingException("Wrong element order encountered at " + localName);
                }
            } else {
                throw new SOAPProcessingException("Reason element should have a text");
            }
        } else if (localName.equals(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME)) {
            if (!reasonProcessing) {
                if (reasonPresent) {
                    if (detailPresent) {
                        throw new SOAPProcessingException("Multiple detail element encountered");
                    } else {
                        elementType = AxiomSOAP12FaultDetail.class;
                        detailPresent = true;
                    }
                } else {
                    throw new SOAPProcessingException("wrong element order encountered at " + localName);
                }
            } else {
                throw new SOAPProcessingException("Reason element should have a text");
            }
        } else {
            throw new SOAPProcessingException(localName + " unsupported element in SOAPFault element");
        }
    } else if (elementLevel == 5) {
        if (parent.getLocalName().equals(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME)) {
            if (localName.equals(SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME)) {
                if (!valuePresent) {
                    elementType = AxiomSOAP12FaultValue.class;
                    valuePresent = true;
                    codeprocessing = false;
                } else {
                    throw new SOAPProcessingException("Multiple value Encountered in code element");
                }
            } else if (localName.equals(SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME)) {
                if (!subcodePresent) {
                    if (valuePresent) {
                        elementType = AxiomSOAP12FaultSubCode.class;
                        subcodePresent = true;
                        subCodeProcessing = true;
                    } else {
                        throw new SOAPProcessingException("Value should present before the subcode");
                    }
                } else {
                    throw new SOAPProcessingException("multiple subcode Encountered in code element");
                }
            } else {
                throw new SOAPProcessingException(localName + " is not supported inside the code element");
            }
        } else if (parent.getLocalName().equals(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME)) {
            if (localName.equals(SOAP12Constants.SOAP_FAULT_TEXT_LOCAL_NAME)) {
                elementType = AxiomSOAP12FaultText.class;
                reasonProcessing = false;
            } else {
                throw new SOAPProcessingException(localName + " is not supported inside the reason");
            }
        } else if (parent.getLocalName().equals(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME)) {
            elementType = AxiomElement.class;
            processingDetailElements = true;
            detailElementNames = new Vector<String>();
            detailElementNames.add(localName);
        } else {
            throw new SOAPProcessingException(parent.getLocalName() + " should not have child element");
        }
    } else if (elementLevel > 5) {
        if (parent.getLocalName().equals(SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME)) {
            if (localName.equals(SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME)) {
                if (subcodeValuePresent) {
                    throw new SOAPProcessingException("multiple subCode value encountered");
                } else {
                    elementType = AxiomSOAP12FaultValue.class;
                    subcodeValuePresent = true;
                    subSubcodePresent = false;
                    subCodeProcessing = false;
                }
            } else if (localName.equals(SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME)) {
                if (subcodeValuePresent) {
                    if (!subSubcodePresent) {
                        elementType = AxiomSOAP12FaultSubCode.class;
                        subcodeValuePresent = false;
                        subSubcodePresent = true;
                        subCodeProcessing = true;
                    } else {
                        throw new SOAPProcessingException("multiple subcode encountered");
                    }
                } else {
                    throw new SOAPProcessingException("Value should present before the subcode");
                }
            } else {
                throw new SOAPProcessingException(localName + " is not supported inside the subCode element");
            }
        } else if (processingDetailElements) {
            int detailElementLevel = 0;
            boolean localNameExist = false;
            for (int i = 0; i < detailElementNames.size(); i++) {
                if (parent.getLocalName().equals(detailElementNames.get(i))) {
                    localNameExist = true;
                    detailElementLevel = i + 1;
                }
            }
            if (localNameExist) {
                detailElementNames.setSize(detailElementLevel);
                elementType = AxiomElement.class;
                detailElementNames.add(localName);
            }
        } else {
            throw new SOAPProcessingException(parent.getLocalName() + " should not have child at element level " + elementLevel);
        }
    }
    return elementType;
}
Also used : AxiomSOAP12FaultRole(org.apache.axiom.soap.impl.intf.AxiomSOAP12FaultRole) SOAPProcessingException(org.apache.axiom.soap.SOAPProcessingException) AxiomSOAP12FaultValue(org.apache.axiom.soap.impl.intf.AxiomSOAP12FaultValue) AxiomElement(org.apache.axiom.om.impl.intf.AxiomElement) AxiomSOAP12FaultSubCode(org.apache.axiom.soap.impl.intf.AxiomSOAP12FaultSubCode) AxiomSOAP12FaultReason(org.apache.axiom.soap.impl.intf.AxiomSOAP12FaultReason) Vector(java.util.Vector)

Aggregations

AxiomElement (org.apache.axiom.om.impl.intf.AxiomElement)5 OMElement (org.apache.axiom.om.OMElement)2 OMNamespace (org.apache.axiom.om.OMNamespace)2 SOAPProcessingException (org.apache.axiom.soap.SOAPProcessingException)2 Iterator (java.util.Iterator)1 Vector (java.util.Vector)1 CoreModelException (org.apache.axiom.core.CoreModelException)1 OMComment (org.apache.axiom.om.OMComment)1 OMDataSource (org.apache.axiom.om.OMDataSource)1 OMDocType (org.apache.axiom.om.OMDocType)1 OMProcessingInstruction (org.apache.axiom.om.OMProcessingInstruction)1 OMText (org.apache.axiom.om.OMText)1 CustomBuilder (org.apache.axiom.om.ds.custombuilder.CustomBuilder)1 OMNamespaceImpl (org.apache.axiom.om.impl.common.OMNamespaceImpl)1 AxiomComment (org.apache.axiom.om.impl.intf.AxiomComment)1 AxiomDocType (org.apache.axiom.om.impl.intf.AxiomDocType)1 AxiomEntityReference (org.apache.axiom.om.impl.intf.AxiomEntityReference)1 AxiomNamespaceDeclaration (org.apache.axiom.om.impl.intf.AxiomNamespaceDeclaration)1 AxiomProcessingInstruction (org.apache.axiom.om.impl.intf.AxiomProcessingInstruction)1 AxiomSourcedElement (org.apache.axiom.om.impl.intf.AxiomSourcedElement)1