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;
}
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;
}
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.");
}
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.");
}
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);
}
}
Aggregations