use of jakarta.xml.bind.helpers.DefaultValidationEventHandler in project jargyle by jh3nd3rs0n.
the class UsersXml method newInstanceFromXml.
public static UsersXml newInstanceFromXml(final InputStream in) throws JAXBException {
JAXBContext jaxbContext = JAXBContext.newInstance(UsersXml.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
unmarshaller.setEventHandler(new DefaultValidationEventHandler());
return (UsersXml) unmarshaller.unmarshal(in);
}
use of jakarta.xml.bind.helpers.DefaultValidationEventHandler in project eclipselink by eclipse-ee4j.
the class JAXBContextFactory method getXmlBindings.
/**
* Convenience method for creating an XmlBindings object based on a given Object. The method
* will load the eclipselink metadata model and unmarshal the Object. This assumes that the
* Object represents the eclipselink-oxm.xml metadata file to be unmarshalled.
*
* @param metadata assumed to be one of: File, InputSource, InputStream, Reader, Source
*/
private static XmlBindings getXmlBindings(Object metadata, ClassLoader classLoader, Map<String, Object> properties) {
JAXBContext jaxbContext = CompilerHelper.getXmlBindingsModelContext();
InputStream openedStream = null;
try {
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_XML);
unmarshaller.setProperty(UnmarshallerProperties.AUTO_DETECT_MEDIA_TYPE, true);
unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
unmarshaller.setEventHandler(new DefaultValidationEventHandler());
if (metadata instanceof MetadataSource) {
return ((MetadataSource) metadata).getXmlBindings(properties, classLoader);
}
JAXBElement<XmlBindings> bindingsJaxbElement = null;
if (metadata instanceof XMLEventReader) {
bindingsJaxbElement = unmarshaller.unmarshal((XMLEventReader) metadata, XmlBindings.class);
} else if (metadata instanceof XMLStreamReader) {
bindingsJaxbElement = unmarshaller.unmarshal((XMLStreamReader) metadata, XmlBindings.class);
} else {
Source source = null;
if (metadata instanceof File) {
source = new StreamSource(new FileInputStream((File) metadata));
} else if (metadata instanceof InputSource) {
if (((InputSource) metadata).getByteStream() != null) {
source = new StreamSource(((InputSource) metadata).getByteStream());
} else if (((InputSource) metadata).getCharacterStream() != null) {
source = new StreamSource(((InputSource) metadata).getCharacterStream());
}
} else if (metadata instanceof InputStream) {
source = new StreamSource((InputStream) metadata);
} else if (metadata instanceof Node) {
source = new DOMSource((Node) metadata);
} else if (metadata instanceof Reader) {
source = new StreamSource((Reader) metadata);
} else if (metadata instanceof Source) {
source = (Source) metadata;
} else if (metadata instanceof URL) {
openedStream = ((URL) metadata).openStream();
source = new StreamSource(openedStream);
} else if (metadata instanceof String) {
StreamSource streamSource = new StreamSource((String) metadata);
try {
bindingsJaxbElement = unmarshaller.unmarshal(streamSource, XmlBindings.class);
} catch (JAXBException e) {
openedStream = classLoader.getResourceAsStream((String) metadata);
if (openedStream != null) {
bindingsJaxbElement = unmarshaller.unmarshal(new StreamSource(openedStream), XmlBindings.class);
} else {
throw org.eclipse.persistence.exceptions.JAXBException.couldNotUnmarshalMetadata(e);
}
}
} else {
throw org.eclipse.persistence.exceptions.JAXBException.incorrectValueParameterTypeForOxmXmlKey();
}
if (bindingsJaxbElement == null) {
if (source == null) {
throw org.eclipse.persistence.exceptions.JAXBException.incorrectValueParameterTypeForOxmXmlKey();
} else {
bindingsJaxbElement = unmarshaller.unmarshal(source, XmlBindings.class);
}
}
}
if (bindingsJaxbElement != null) {
return bindingsJaxbElement.getValue();
}
throw org.eclipse.persistence.exceptions.JAXBException.incorrectValueParameterTypeForOxmXmlKey();
} catch (jakarta.xml.bind.JAXBException ex) {
throw org.eclipse.persistence.exceptions.JAXBException.couldNotUnmarshalMetadata(ex);
} catch (IOException ioException) {
throw org.eclipse.persistence.exceptions.JAXBException.couldNotUnmarshalMetadata(ioException);
} finally {
if (openedStream != null) {
try {
openedStream.close();
} catch (IOException e) {
throw org.eclipse.persistence.exceptions.JAXBException.couldNotUnmarshalMetadata(e);
}
}
}
}
use of jakarta.xml.bind.helpers.DefaultValidationEventHandler in project jargyle by jh3nd3rs0n.
the class ConfigurationXml method newInstanceFromXml.
public static ConfigurationXml newInstanceFromXml(final InputStream in) throws JAXBException {
JAXBContext jaxbContext = JAXBContext.newInstance(ConfigurationXml.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
unmarshaller.setEventHandler(new DefaultValidationEventHandler());
return (ConfigurationXml) unmarshaller.unmarshal(in);
}
Aggregations