use of org.eclipse.persistence.jaxb.metadata.MetadataSource 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 org.eclipse.persistence.jaxb.metadata.MetadataSource in project eclipselink by eclipse-ee4j.
the class FeatureSetPreV2 method getMetadataSources.
@Override
public List<MetadataSource> getMetadataSources() {
final List<MetadataSource> metadataSources = new ArrayList<>();
metadataSources.add(new LinkMetadataSource());
metadataSources.add(new ReportQueryResultListMetadataSource());
metadataSources.add(new ReportQueryResultListItemMetadataSource());
metadataSources.add(new SingleResultQueryListMetadataSource());
metadataSources.add(new SimpleHomogeneousListMetadataSource());
metadataSources.add(new ReportQueryResultCollectionMetadataSource());
metadataSources.add(new ReadAllQueryResultCollectionMetadataSource());
metadataSources.add(new JavaLangMetadataSource());
metadataSources.add(new JavaMathMetadataSource());
metadataSources.add(new JavaUtilMetadataSource());
metadataSources.add(new LinkV2MetadataSource());
metadataSources.add(new ItemLinksMetadataSource());
metadataSources.add(new ErrorResponseMetadataSource());
return metadataSources;
}
use of org.eclipse.persistence.jaxb.metadata.MetadataSource in project eclipselink by eclipse-ee4j.
the class FeatureSetV2 method getMetadataSources.
@Override
public List<MetadataSource> getMetadataSources() {
final List<MetadataSource> metadataSources = new ArrayList<>();
metadataSources.add(new ReportQueryResultListMetadataSource());
metadataSources.add(new ReportQueryResultListItemMetadataSource());
metadataSources.add(new SingleResultQueryListMetadataSource());
metadataSources.add(new SimpleHomogeneousListMetadataSource());
metadataSources.add(new ReportQueryResultCollectionMetadataSource());
metadataSources.add(new ReadAllQueryResultCollectionMetadataSource());
metadataSources.add(new SingleResultQueryResultMetadataSource());
metadataSources.add(new JavaLangMetadataSource());
metadataSources.add(new JavaMathMetadataSource());
metadataSources.add(new JavaUtilMetadataSource());
metadataSources.add(new ErrorResponseMetadataSource());
// metadataSources.add(new LinkMetadataSource());
metadataSources.add(new ItemLinksMetadataSource());
metadataSources.add(new LinkV2MetadataSource());
metadataSources.add(new CollectionWrapperMetadataSource());
return metadataSources;
}
Aggregations