Search in sources :

Example 1 with OMMetaFactory

use of org.apache.axiom.om.OMMetaFactory in project webservices-axiom by apache.

the class ImplementationFactory method parseImplementation.

private static Implementation parseImplementation(Loader loader, Element implementation) {
    String name = implementation.getAttributeNS(null, "name");
    if (name.length() == 0) {
        log.error("Encountered " + QNAME_IMPLEMENTATION + " element without name attribute");
        return null;
    }
    String loaderClassName = implementation.getAttributeNS(null, "loader");
    if (loaderClassName.length() == 0) {
        log.error("Encountered " + QNAME_IMPLEMENTATION + " element without loader attribute");
        return null;
    }
    OMMetaFactory metaFactory = ((OMMetaFactoryLoader) load(loader, loaderClassName)).load(null);
    if (metaFactory == null) {
        return null;
    }
    List<Feature> features = new ArrayList<Feature>();
    Node child = implementation.getFirstChild();
    while (child != null) {
        if (child instanceof Element) {
            QName childQName = getQName(child);
            if (childQName.equals(QNAME_FEATURE)) {
                Feature feature = parseFeature(loader, (Element) child);
                if (feature != null) {
                    features.add(feature);
                }
            } else {
                log.warn("Skipping unexpected element " + childQName + "; only " + QNAME_FEATURE + " is expected");
            }
        }
        child = child.getNextSibling();
    }
    return new Implementation(name, metaFactory, features.toArray(new Feature[features.size()]));
}
Also used : OMMetaFactoryLoader(org.apache.axiom.locator.loader.OMMetaFactoryLoader) QName(javax.xml.namespace.QName) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) OMMetaFactory(org.apache.axiom.om.OMMetaFactory)

Example 2 with OMMetaFactory

use of org.apache.axiom.om.OMMetaFactory in project webservices-axiom by apache.

the class ValidateSample method validateUsingDOM.

// START SNIPPET: dom
public void validateUsingDOM(InputStream in, URL schemaUrl) throws Exception {
    OMMetaFactory mf = OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM);
    SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(mf, in, "UTF-8");
    SOAPEnvelope envelope = builder.getSOAPEnvelope();
    OMElement bodyContent = envelope.getBody().getFirstElement();
    SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = schemaFactory.newSchema(schemaUrl);
    Validator validator = schema.newValidator();
    validator.validate(new DOMSource((Element) bodyContent));
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) DOMSource(javax.xml.transform.dom.DOMSource) Schema(javax.xml.validation.Schema) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) OMElement(org.apache.axiom.om.OMElement) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) OMMetaFactory(org.apache.axiom.om.OMMetaFactory) Validator(javax.xml.validation.Validator)

Example 3 with OMMetaFactory

use of org.apache.axiom.om.OMMetaFactory in project webservices-axiom by apache.

the class DOMFeatureTest method test.

public void test() {
    OMMetaFactory metaFactory = OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM);
    assertTrue(metaFactory instanceof OMDOMMetaFactory);
}
Also used : OMMetaFactory(org.apache.axiom.om.OMMetaFactory)

Aggregations

OMMetaFactory (org.apache.axiom.om.OMMetaFactory)3 Element (org.w3c.dom.Element)2 ArrayList (java.util.ArrayList)1 QName (javax.xml.namespace.QName)1 DOMSource (javax.xml.transform.dom.DOMSource)1 Schema (javax.xml.validation.Schema)1 SchemaFactory (javax.xml.validation.SchemaFactory)1 Validator (javax.xml.validation.Validator)1 OMMetaFactoryLoader (org.apache.axiom.locator.loader.OMMetaFactoryLoader)1 OMElement (org.apache.axiom.om.OMElement)1 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)1 SOAPModelBuilder (org.apache.axiom.soap.SOAPModelBuilder)1 Node (org.w3c.dom.Node)1