Search in sources :

Example 1 with MetadataSource

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);
            }
        }
    }
}
Also used : XmlBindings(org.eclipse.persistence.jaxb.xmlmodel.XmlBindings) InputSource(org.xml.sax.InputSource) DOMSource(javax.xml.transform.dom.DOMSource) XMLStreamReader(javax.xml.stream.XMLStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) Node(org.w3c.dom.Node) JAXBException(jakarta.xml.bind.JAXBException) XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLEventReader(javax.xml.stream.XMLEventReader) Reader(java.io.Reader) IOException(java.io.IOException) MetadataSource(org.eclipse.persistence.jaxb.metadata.MetadataSource) DOMSource(javax.xml.transform.dom.DOMSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) InputSource(org.xml.sax.InputSource) MetadataSource(org.eclipse.persistence.jaxb.metadata.MetadataSource) FileInputStream(java.io.FileInputStream) URL(java.net.URL) JAXBException(jakarta.xml.bind.JAXBException) XMLEventReader(javax.xml.stream.XMLEventReader) Unmarshaller(jakarta.xml.bind.Unmarshaller) DefaultValidationEventHandler(jakarta.xml.bind.helpers.DefaultValidationEventHandler) File(java.io.File)

Example 2 with MetadataSource

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;
}
Also used : LinkMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.LinkMetadataSource) ReportQueryResultCollectionMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.ReportQueryResultCollectionMetadataSource) ReadAllQueryResultCollectionMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.ReadAllQueryResultCollectionMetadataSource) ItemLinksMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.ItemLinksMetadataSource) ArrayList(java.util.ArrayList) LinkV2MetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.LinkV2MetadataSource) SingleResultQueryListMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.SingleResultQueryListMetadataSource) ReadAllQueryResultCollectionMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.ReadAllQueryResultCollectionMetadataSource) JavaMathMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.JavaMathMetadataSource) ReportQueryResultListMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.ReportQueryResultListMetadataSource) ErrorResponseMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.ErrorResponseMetadataSource) LinkMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.LinkMetadataSource) MetadataSource(org.eclipse.persistence.jaxb.metadata.MetadataSource) ReportQueryResultListItemMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.ReportQueryResultListItemMetadataSource) JavaUtilMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.JavaUtilMetadataSource) DynamicXMLMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.DynamicXMLMetadataSource) SimpleHomogeneousListMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.SimpleHomogeneousListMetadataSource) ReportQueryResultCollectionMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.ReportQueryResultCollectionMetadataSource) JavaLangMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.JavaLangMetadataSource) ItemLinksMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.ItemLinksMetadataSource) ReportQueryResultListItemMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.ReportQueryResultListItemMetadataSource) JavaMathMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.JavaMathMetadataSource) ReportQueryResultListMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.ReportQueryResultListMetadataSource) JavaLangMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.JavaLangMetadataSource) JavaUtilMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.JavaUtilMetadataSource) SingleResultQueryListMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.SingleResultQueryListMetadataSource) SimpleHomogeneousListMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.SimpleHomogeneousListMetadataSource) ErrorResponseMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.ErrorResponseMetadataSource) LinkV2MetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.LinkV2MetadataSource)

Example 3 with MetadataSource

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;
}
Also used : ReportQueryResultCollectionMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.ReportQueryResultCollectionMetadataSource) CollectionWrapperMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.CollectionWrapperMetadataSource) ReadAllQueryResultCollectionMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.ReadAllQueryResultCollectionMetadataSource) ItemLinksMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.ItemLinksMetadataSource) ArrayList(java.util.ArrayList) LinkV2MetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.LinkV2MetadataSource) SingleResultQueryListMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.SingleResultQueryListMetadataSource) ReadAllQueryResultCollectionMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.ReadAllQueryResultCollectionMetadataSource) JavaMathMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.JavaMathMetadataSource) ReportQueryResultListMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.ReportQueryResultListMetadataSource) ErrorResponseMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.ErrorResponseMetadataSource) MetadataSource(org.eclipse.persistence.jaxb.metadata.MetadataSource) ReportQueryResultListItemMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.ReportQueryResultListItemMetadataSource) JavaUtilMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.JavaUtilMetadataSource) CollectionWrapperMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.CollectionWrapperMetadataSource) SimpleHomogeneousListMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.SimpleHomogeneousListMetadataSource) DynamicXmlV2MetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.DynamicXmlV2MetadataSource) ReportQueryResultCollectionMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.ReportQueryResultCollectionMetadataSource) JavaLangMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.JavaLangMetadataSource) ItemLinksMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.ItemLinksMetadataSource) SingleResultQueryResultMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.SingleResultQueryResultMetadataSource) ReportQueryResultListItemMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.ReportQueryResultListItemMetadataSource) JavaMathMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.JavaMathMetadataSource) ReportQueryResultListMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.ReportQueryResultListMetadataSource) JavaLangMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.JavaLangMetadataSource) JavaUtilMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.JavaUtilMetadataSource) SingleResultQueryResultMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.SingleResultQueryResultMetadataSource) SingleResultQueryListMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.SingleResultQueryListMetadataSource) SimpleHomogeneousListMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.SimpleHomogeneousListMetadataSource) ErrorResponseMetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.ErrorResponseMetadataSource) LinkV2MetadataSource(org.eclipse.persistence.jpa.rs.util.metadatasources.LinkV2MetadataSource)

Aggregations

MetadataSource (org.eclipse.persistence.jaxb.metadata.MetadataSource)3 ArrayList (java.util.ArrayList)2 ErrorResponseMetadataSource (org.eclipse.persistence.jpa.rs.util.metadatasources.ErrorResponseMetadataSource)2 ItemLinksMetadataSource (org.eclipse.persistence.jpa.rs.util.metadatasources.ItemLinksMetadataSource)2 JavaLangMetadataSource (org.eclipse.persistence.jpa.rs.util.metadatasources.JavaLangMetadataSource)2 JavaMathMetadataSource (org.eclipse.persistence.jpa.rs.util.metadatasources.JavaMathMetadataSource)2 JavaUtilMetadataSource (org.eclipse.persistence.jpa.rs.util.metadatasources.JavaUtilMetadataSource)2 LinkV2MetadataSource (org.eclipse.persistence.jpa.rs.util.metadatasources.LinkV2MetadataSource)2 ReadAllQueryResultCollectionMetadataSource (org.eclipse.persistence.jpa.rs.util.metadatasources.ReadAllQueryResultCollectionMetadataSource)2 ReportQueryResultCollectionMetadataSource (org.eclipse.persistence.jpa.rs.util.metadatasources.ReportQueryResultCollectionMetadataSource)2 ReportQueryResultListItemMetadataSource (org.eclipse.persistence.jpa.rs.util.metadatasources.ReportQueryResultListItemMetadataSource)2 ReportQueryResultListMetadataSource (org.eclipse.persistence.jpa.rs.util.metadatasources.ReportQueryResultListMetadataSource)2 SimpleHomogeneousListMetadataSource (org.eclipse.persistence.jpa.rs.util.metadatasources.SimpleHomogeneousListMetadataSource)2 SingleResultQueryListMetadataSource (org.eclipse.persistence.jpa.rs.util.metadatasources.SingleResultQueryListMetadataSource)2 JAXBException (jakarta.xml.bind.JAXBException)1 Unmarshaller (jakarta.xml.bind.Unmarshaller)1 DefaultValidationEventHandler (jakarta.xml.bind.helpers.DefaultValidationEventHandler)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1