Search in sources :

Example 71 with JAXBContext

use of javax.xml.bind.JAXBContext in project opennms by OpenNMS.

the class MarshallTest method setUp.

@Before
public void setUp() throws JAXBException {
    // Create a Marshaller
    JAXBContext context = JAXBContext.newInstance(ServiceAlarmNotification.class);
    m_marshaller = context.createMarshaller();
    m_marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    m_unmarshaller = context.createUnmarshaller();
}
Also used : JAXBContext(javax.xml.bind.JAXBContext) Before(org.junit.Before)

Example 72 with JAXBContext

use of javax.xml.bind.JAXBContext in project ORCID-Source by ORCID.

the class JpaJaxbOtherNameAdapterTest method getOtherName.

private OtherName getOtherName() throws JAXBException {
    JAXBContext context = JAXBContext.newInstance(new Class[] { OtherName.class });
    Unmarshaller unmarshaller = context.createUnmarshaller();
    String name = "/record_2.0/samples/read_samples/other-name-2.0.xml";
    InputStream inputStream = getClass().getResourceAsStream(name);
    return (OtherName) unmarshaller.unmarshal(inputStream);
}
Also used : InputStream(java.io.InputStream) OtherName(org.orcid.jaxb.model.record_v2.OtherName) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 73 with JAXBContext

use of javax.xml.bind.JAXBContext in project ORCID-Source by ORCID.

the class JpaJaxbExternalIdentifierAdapterTest method getExternalIdentifier.

private PersonExternalIdentifier getExternalIdentifier() throws JAXBException {
    JAXBContext context = JAXBContext.newInstance(new Class[] { PersonExternalIdentifier.class });
    Unmarshaller unmarshaller = context.createUnmarshaller();
    String name = "/record_2.0/samples/read_samples/external-identifier-2.0.xml";
    InputStream inputStream = getClass().getResourceAsStream(name);
    return (PersonExternalIdentifier) unmarshaller.unmarshal(inputStream);
}
Also used : InputStream(java.io.InputStream) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) PersonExternalIdentifier(org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)

Example 74 with JAXBContext

use of javax.xml.bind.JAXBContext in project ORCID-Source by ORCID.

the class JpaJaxbEmploymentAdapterTest method getEmployment.

private Employment getEmployment(boolean full) throws JAXBException {
    JAXBContext context = JAXBContext.newInstance(new Class[] { Employment.class });
    Unmarshaller unmarshaller = context.createUnmarshaller();
    String name = "/record_2.0/samples/read_samples/employment-2.0.xml";
    if (full) {
        name = "/record_2.0/samples/read_samples/employment-full-2.0.xml";
    }
    InputStream inputStream = getClass().getResourceAsStream(name);
    return (Employment) unmarshaller.unmarshal(inputStream);
}
Also used : Employment(org.orcid.jaxb.model.record_v2.Employment) InputStream(java.io.InputStream) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 75 with JAXBContext

use of javax.xml.bind.JAXBContext in project ORCID-Source by ORCID.

the class ConvertV2ToV2_1Test method upgradePeerReviewsToV21Test.

@Test
public void upgradePeerReviewsToV21Test() throws JAXBException {
    JAXBContext jaxbContext1 = JAXBContext.newInstance(PeerReviews.class);
    JAXBContext jaxbContext2 = JAXBContext.newInstance(PeerReviews.class);
    Unmarshaller jaxbUnmarshaller = jaxbContext1.createUnmarshaller();
    InputStream v20Stream = ConvertV2ToV2_1Test.class.getClassLoader().getResourceAsStream("test-peer-reviews-2.0.xml");
    InputStream v21Stream = ConvertV2ToV2_1Test.class.getClassLoader().getResourceAsStream("test-peer-reviews-2.1.xml");
    PeerReviews v20PeerReviews = (PeerReviews) jaxbUnmarshaller.unmarshal(v20Stream);
    jaxbUnmarshaller = jaxbContext2.createUnmarshaller();
    PeerReviews v21PeerReviews1 = (PeerReviews) jaxbUnmarshaller.unmarshal(v21Stream);
    V2Convertible result = versionConverterV2_0ToV2_1.upgrade(new V2Convertible(v20PeerReviews, "v2.1"));
    PeerReviews v21PeerReviews2 = (PeerReviews) result.getObjectToConvert();
    assertEquals(v21PeerReviews1, v21PeerReviews2);
}
Also used : V2Convertible(org.orcid.core.version.V2Convertible) InputStream(java.io.InputStream) PeerReviews(org.orcid.jaxb.model.record.summary_v2.PeerReviews) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Aggregations

JAXBContext (javax.xml.bind.JAXBContext)1150 Unmarshaller (javax.xml.bind.Unmarshaller)558 Marshaller (javax.xml.bind.Marshaller)371 JAXBException (javax.xml.bind.JAXBException)330 Test (org.junit.Test)226 File (java.io.File)161 InputStream (java.io.InputStream)150 StringWriter (java.io.StringWriter)138 IOException (java.io.IOException)105 ByteArrayOutputStream (java.io.ByteArrayOutputStream)76 StringReader (java.io.StringReader)74 StreamSource (javax.xml.transform.stream.StreamSource)73 JAXBElement (javax.xml.bind.JAXBElement)72 ArrayList (java.util.ArrayList)58 URL (java.net.URL)55 ByteArrayInputStream (java.io.ByteArrayInputStream)50 Schema (javax.xml.validation.Schema)48 SchemaFactory (javax.xml.validation.SchemaFactory)48 OutputStream (java.io.OutputStream)42 BaseTest (org.orcid.core.BaseTest)39