Search in sources :

Example 1 with XMLPlatform

use of org.eclipse.persistence.platform.xml.XMLPlatform in project eclipselink by eclipse-ee4j.

the class DefaultNamespaceTestCases method getControlObject.

@Override
protected Root getControlObject() {
    Root root = new Root();
    XMLPlatform xmlPlatform = XMLPlatformFactory.getInstance().getXMLPlatform();
    Document document = xmlPlatform.createDocument();
    Element element = document.createElement("child");
    root.setChild(element);
    return root;
}
Also used : XMLPlatform(org.eclipse.persistence.platform.xml.XMLPlatform) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 2 with XMLPlatform

use of org.eclipse.persistence.platform.xml.XMLPlatform in project eclipselink by eclipse-ee4j.

the class DefaultNamespace2TestCases method getControlObject.

@Override
protected Root getControlObject() {
    Root root = new Root();
    XMLPlatform xmlPlatform = XMLPlatformFactory.getInstance().getXMLPlatform();
    Document document = xmlPlatform.createDocument();
    Element element = document.createElementNS("namespace1", "childelem");
    root.setChild(element);
    return root;
}
Also used : XMLRoot(org.eclipse.persistence.oxm.XMLRoot) XMLPlatform(org.eclipse.persistence.platform.xml.XMLPlatform) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 3 with XMLPlatform

use of org.eclipse.persistence.platform.xml.XMLPlatform in project eclipselink by eclipse-ee4j.

the class UnmarshalSchemaValidationTestCases method testFailOnSecondErrorNode.

public void testFailOnSecondErrorNode() throws Exception {
    CustomErrorValidationEventHandler eventHandler = new CustomErrorValidationEventHandler();
    unmarshaller.setEventHandler(eventHandler);
    InputStream stream = ClassLoader.getSystemResourceAsStream(DOUBLE_ERROR_XML);
    XMLPlatform xmlPlatform = XMLPlatformFactory.getInstance().getXMLPlatform();
    XMLParser xmlParser = xmlPlatform.newXMLParser();
    xmlParser.setNamespaceAware(true);
    Node node = xmlParser.parse(stream);
    try {
        unmarshaller.setSchema(this.schema);
        unmarshaller.unmarshal(node);
    } catch (UnmarshalException ex) {
        assertEquals(2, eventHandler.getErrorCount());
        return;
    }
    fail("No Exceptions thrown.");
}
Also used : InputStream(java.io.InputStream) UnmarshalException(jakarta.xml.bind.UnmarshalException) XMLPlatform(org.eclipse.persistence.platform.xml.XMLPlatform) Node(org.w3c.dom.Node) XMLParser(org.eclipse.persistence.platform.xml.XMLParser)

Example 4 with XMLPlatform

use of org.eclipse.persistence.platform.xml.XMLPlatform in project eclipselink by eclipse-ee4j.

the class UnmarshallerNullTestCases method testFailNodeWithNullClass.

public void testFailNodeWithNullClass() throws Exception {
    try {
        InputStream stream = ClassLoader.getSystemResourceAsStream(DOUBLE_ERROR_XML);
        XMLPlatform xmlPlatform = XMLPlatformFactory.getInstance().getXMLPlatform();
        XMLParser xmlParser = xmlPlatform.newXMLParser();
        xmlParser.setNamespaceAware(true);
        Node node = xmlParser.parse(stream);
        unmarshaller.unmarshal(node, null);
    } catch (IllegalArgumentException e) {
        return;
    }
    fail("IllegalArgumentException not thrown.");
}
Also used : InputStream(java.io.InputStream) XMLPlatform(org.eclipse.persistence.platform.xml.XMLPlatform) Node(org.w3c.dom.Node) XMLParser(org.eclipse.persistence.platform.xml.XMLParser)

Example 5 with XMLPlatform

use of org.eclipse.persistence.platform.xml.XMLPlatform in project eclipselink by eclipse-ee4j.

the class SAXUnmarshaller method unmarshal.

@Override
public Object unmarshal(Source source, Class<?> clazz) {
    if (source instanceof SAXSource) {
        SAXSource saxSource = (SAXSource) source;
        XMLReader xmlReader = null;
        if (saxSource.getXMLReader() != null) {
            if (saxSource.getXMLReader() instanceof XMLReader) {
                xmlReader = (XMLReader) saxSource.getXMLReader();
            } else {
                xmlReader = new XMLReader(saxSource.getXMLReader());
            }
            setValidatorHandler(xmlReader);
        }
        if (null == saxSource.getXMLReader()) {
            return unmarshal(saxSource.getInputSource(), clazz);
        } else {
            return unmarshal(saxSource.getInputSource(), clazz, xmlReader);
        }
    } else if (source instanceof DOMSource) {
        DOMSource domSource = (DOMSource) source;
        return unmarshal(domSource.getNode(), clazz);
    } else if (source instanceof StreamSource) {
        StreamSource streamSource = (StreamSource) source;
        if (null != streamSource.getReader()) {
            return unmarshal(streamSource.getReader(), clazz);
        } else if (null != streamSource.getInputStream()) {
            return unmarshal(streamSource.getInputStream(), clazz);
        } else {
            return unmarshal(streamSource.getSystemId(), clazz);
        }
    } else if (source instanceof ExtendedSource) {
        ExtendedSource extendedSource = (ExtendedSource) source;
        return unmarshal(null, clazz, extendedSource.createReader(xmlUnmarshaller, clazz));
    } else {
        DOMResult result = new DOMResult();
        XMLPlatform xmlPlat = XMLPlatformFactory.getInstance().getXMLPlatform();
        xmlPlat.setDisableSecureProcessing(isSecureProcessingDisabled());
        XMLTransformer transformer = xmlPLatform.newXMLTransformer();
        transformer.transform(source, result);
        return unmarshal(result.getNode(), clazz);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) SAXSource(javax.xml.transform.sax.SAXSource) DOMResult(javax.xml.transform.dom.DOMResult) StreamSource(javax.xml.transform.stream.StreamSource) XMLPlatform(org.eclipse.persistence.platform.xml.XMLPlatform) XMLTransformer(org.eclipse.persistence.platform.xml.XMLTransformer)

Aggregations

XMLPlatform (org.eclipse.persistence.platform.xml.XMLPlatform)43 Document (org.w3c.dom.Document)17 XMLParser (org.eclipse.persistence.platform.xml.XMLParser)7 XMLPlatformException (org.eclipse.persistence.platform.xml.XMLPlatformException)7 XMLRoot (org.eclipse.persistence.oxm.XMLRoot)6 Node (org.w3c.dom.Node)6 InputStream (java.io.InputStream)5 Element (org.w3c.dom.Element)5 XMLTransformer (org.eclipse.persistence.platform.xml.XMLTransformer)4 DocumentType (org.w3c.dom.DocumentType)4 Text (org.w3c.dom.Text)4 URL (java.net.URL)3 QName (javax.xml.namespace.QName)3 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)3 XMLMarshalException (org.eclipse.persistence.exceptions.XMLMarshalException)3 EclipseLinkObjectPersistenceRuntimeXMLProject (org.eclipse.persistence.internal.sessions.factories.EclipseLinkObjectPersistenceRuntimeXMLProject)3 XMLContext (org.eclipse.persistence.oxm.XMLContext)3 UnmarshalException (jakarta.xml.bind.UnmarshalException)2 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2