Search in sources :

Example 46 with ObjectFactory

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory in project webcert by sklintyg.

the class FKAnswerConverterTest method jaxbToXml.

private String jaxbToXml(AnswerToFkType object) throws JAXBException {
    ObjectFactory objectFactory = new ObjectFactory();
    Writer writer = new StringWriter();
    // Init JAXB context
    JAXBContext jaxbContext = JAXBContext.newInstance(AnswerToFkType.class);
    Marshaller marshaller = jaxbContext.createMarshaller();
    // Create a string representation from JAXB element
    marshaller.marshal(objectFactory.createAnswer(object), writer);
    return writer.toString();
}
Also used : Marshaller(javax.xml.bind.Marshaller) ObjectFactory(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificateanswerresponder.v1.ObjectFactory) StringWriter(java.io.StringWriter) JAXBContext(javax.xml.bind.JAXBContext) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 47 with ObjectFactory

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory in project webcert by sklintyg.

the class FKQuestionConverterTest method jaxbToXml.

private String jaxbToXml(QuestionToFkType object) throws JAXBException {
    ObjectFactory objectFactory = new ObjectFactory();
    Writer writer = new StringWriter();
    // Init JAXB context
    JAXBContext jaxbContext = JAXBContext.newInstance(QuestionToFkType.class);
    Marshaller marshaller = jaxbContext.createMarshaller();
    // Create a string representation from JAXB element
    marshaller.marshal(objectFactory.createQuestion(object), writer);
    return writer.toString();
}
Also used : Marshaller(javax.xml.bind.Marshaller) ObjectFactory(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.ObjectFactory) StringWriter(java.io.StringWriter) JAXBContext(javax.xml.bind.JAXBContext) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 48 with ObjectFactory

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory in project mapstruct by mapstruct.

the class JaxbBasedMapperTest method shouldMapJaxb.

@Test
public void shouldMapJaxb() throws ParseException, JAXBException {
    SourceTargetMapper mapper = SourceTargetMapper.INSTANCE;
    OrderDto source1 = new OrderDto();
    source1.setOrderDetails(new OrderDetailsDto());
    source1.setOrderNumber(11L);
    source1.setOrderDate(createDate("31-08-1982 10:20:56"));
    source1.setShippingAddress(new ShippingAddressDto());
    source1.getShippingAddress().setCity("SmallTown");
    source1.getShippingAddress().setHouseNumber("11a");
    source1.getShippingAddress().setStreet("Awesome rd");
    source1.getShippingAddress().setCountry("USA");
    source1.getOrderDetails().setDescription(new ArrayList<String>());
    source1.getOrderDetails().setName("Shopping list for a Mapper");
    source1.getOrderDetails().getDescription().add("1 MapStruct");
    source1.getOrderDetails().getDescription().add("3 Lines of Code");
    source1.getOrderDetails().getDescription().add("1 Dose of Luck");
    source1.getOrderDetails().setStatus(OrderStatusDto.ORDERED);
    // map to JAXB
    OrderType target = mapper.targetToSource(source1);
    // do a pretty print
    ObjectFactory of = new ObjectFactory();
    System.out.println(toXml(of.createOrder(target)));
    // map back from JAXB
    OrderDto source2 = mapper.sourceToTarget(target);
    // verify that source1 and source 2 are equal
    assertThat(source2.getOrderNumber()).isEqualTo(source1.getOrderNumber());
    assertThat(source2.getOrderDate()).isEqualTo(source1.getOrderDate());
    assertThat(source2.getOrderDetails().getDescription().size()).isEqualTo(source1.getOrderDetails().getDescription().size());
    assertThat(source2.getOrderDetails().getDescription().get(0)).isEqualTo(source1.getOrderDetails().getDescription().get(0));
    assertThat(source2.getOrderDetails().getDescription().get(1)).isEqualTo(source1.getOrderDetails().getDescription().get(1));
    assertThat(source2.getOrderDetails().getDescription().get(2)).isEqualTo(source1.getOrderDetails().getDescription().get(2));
    assertThat(source2.getOrderDetails().getName()).isEqualTo(source1.getOrderDetails().getName());
    assertThat(source2.getOrderDetails().getStatus()).isEqualTo(source1.getOrderDetails().getStatus());
}
Also used : OrderType(org.mapstruct.itest.jaxb.xsd.test1.OrderType) ObjectFactory(org.mapstruct.itest.jaxb.xsd.test1.ObjectFactory) Test(org.junit.Test)

Example 49 with ObjectFactory

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory in project BibleMultiConverter by schierlm.

the class ZefaniaXML method createXMLBible.

protected XMLBIBLE createXMLBible(Bible bible) throws Exception {
    ObjectFactory of = new ObjectFactory();
    XMLBIBLE doc = of.createXMLBIBLE();
    doc.setBiblename(bible.getName());
    doc.setType(EnumModtyp.X_BIBLE);
    doc.setINFORMATION(of.createINFORMATION());
    MetadataBook metadata = bible.getMetadataBook();
    if (metadata != null) {
        for (String key : metadata.getKeys()) {
            String value = metadata.getValue(key);
            if (key.equals(MetadataBookKey.status.toString())) {
                doc.setStatus(EnumStatus.fromValue(value));
            } else if (key.equals(MetadataBookKey.version.toString())) {
                doc.setVersion(value);
            } else if (key.equals(MetadataBookKey.revision.toString())) {
                doc.setRevision(new BigInteger(value));
            } else if (!key.contains("@")) {
                Pattern regex = INFORMATION_FIELDS.get(MetadataBookKey.valueOf(key));
                if (regex != null && regex.matcher(value).matches())
                    doc.getINFORMATION().getTitleOrCreatorOrDescription().add(new JAXBElement<String>(new QName(key), String.class, value));
            }
        }
    }
    doc.getINFORMATION().getTitleOrCreatorOrDescription().add(new JAXBElement<String>(new QName("format"), String.class, "Zefania XML Bible Markup Language"));
    for (Book bk : bible.getBooks()) {
        if (bk.getId().equals(BookID.METADATA))
            continue;
        if (bk.getId().getZefID() <= 0) {
            System.out.println("WARNING: Unable to export book " + bk.getAbbr());
            continue;
        }
        BIBLEBOOK bb = of.createBIBLEBOOK();
        bb.setBnumber(BigInteger.valueOf(bk.getId().getZefID()));
        bb.setBsname(bk.getShortName());
        bb.setBname(bk.getLongName());
        int cnumber = 0;
        for (Chapter ccc : bk.getChapters()) {
            cnumber++;
            if (ccc.getVerses().size() == 0)
                continue;
            CHAPTER cc = of.createCHAPTER();
            cc.setCnumber(BigInteger.valueOf(cnumber));
            bb.getCHAPTER().add(cc);
            if (ccc.getProlog() != null) {
                PROLOG prolog = of.createPROLOG();
                prolog.setVref(BigInteger.ONE);
                ccc.getProlog().accept(new CreateContentVisitor(of, prolog.getContent(), null));
                cc.getPROLOGOrCAPTIONOrVERS().add(prolog);
            }
            for (VirtualVerse vv : ccc.createVirtualVerses()) {
                for (Headline h : vv.getHeadlines()) {
                    CAPTION caption = of.createCAPTION();
                    caption.setVref(BigInteger.valueOf(vv.getNumber()));
                    h.accept(new CreateContentVisitor(of, caption.getContent(), null));
                    EnumCaptionType[] types = new EnumCaptionType[] { null, EnumCaptionType.X_H_1, EnumCaptionType.X_H_2, EnumCaptionType.X_H_3, EnumCaptionType.X_H_4, EnumCaptionType.X_H_5, EnumCaptionType.X_H_6, null, null, null };
                    caption.setType(types[h.getDepth()]);
                    cc.getPROLOGOrCAPTIONOrVERS().add(caption);
                }
                VERS vers = of.createVERS();
                vers.setVnumber(BigInteger.valueOf(vv.getNumber()));
                for (Verse v : vv.getVerses()) {
                    if (!v.getNumber().equals("" + vv.getNumber())) {
                        STYLE verseNum = of.createSTYLE();
                        verseNum.setCss("font-weight: bold");
                        verseNum.getContent().add("(" + v.getNumber() + ")");
                        vers.getContent().add(new JAXBElement<STYLE>(new QName("STYLE"), STYLE.class, verseNum));
                        vers.getContent().add(" ");
                    }
                    v.accept(new CreateContentVisitor(of, vers.getContent(), vers));
                }
                cc.getPROLOGOrCAPTIONOrVERS().add(vers);
            }
        }
        doc.getBIBLEBOOK().add(bb);
    }
    return doc;
}
Also used : MetadataBook(biblemulticonverter.data.MetadataBook) Pattern(java.util.regex.Pattern) VirtualVerse(biblemulticonverter.data.VirtualVerse) XMLBIBLE(biblemulticonverter.schema.zef2005.XMLBIBLE) QName(javax.xml.namespace.QName) Chapter(biblemulticonverter.data.Chapter) STYLE(biblemulticonverter.schema.zef2005.STYLE) BIBLEBOOK(biblemulticonverter.schema.zef2005.BIBLEBOOK) ObjectFactory(biblemulticonverter.schema.zef2005.ObjectFactory) EnumCaptionType(biblemulticonverter.schema.zef2005.EnumCaptionType) CHAPTER(biblemulticonverter.schema.zef2005.CHAPTER) Book(biblemulticonverter.data.Book) MetadataBook(biblemulticonverter.data.MetadataBook) Headline(biblemulticonverter.data.FormattedText.Headline) VERS(biblemulticonverter.schema.zef2005.VERS) BigInteger(java.math.BigInteger) PROLOG(biblemulticonverter.schema.zef2005.PROLOG) CAPTION(biblemulticonverter.schema.zef2005.CAPTION) VirtualVerse(biblemulticonverter.data.VirtualVerse) Verse(biblemulticonverter.data.Verse)

Example 50 with ObjectFactory

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory in project ddf by codice.

the class GetRecordsResponseConverterTest method testMarshalRecordCollectionGetFull.

@Ignore
@Test
public void testMarshalRecordCollectionGetFull() throws UnsupportedEncodingException, JAXBException {
    final int totalResults = 5;
    XStream xstream = createXStream(CswConstants.GET_RECORDS_RESPONSE);
    GetRecordsType getRecords = new GetRecordsType();
    QueryType query = new QueryType();
    ElementSetNameType set = new ElementSetNameType();
    set.setValue(ElementSetType.FULL);
    query.setElementSetName(set);
    ObjectFactory objectFactory = new ObjectFactory();
    getRecords.setAbstractQuery(objectFactory.createAbstractQuery(query));
    CswRecordCollection collection = createCswRecordCollection(getRecords, totalResults);
    collection.setElementSetType(ElementSetType.FULL);
    ArgumentCaptor<MarshallingContext> captor = ArgumentCaptor.forClass(MarshallingContext.class);
    String xml = xstream.toXML(collection);
    // Verify the context arguments were set correctly
    verify(mockProvider, times(totalResults)).marshal(any(Object.class), any(HierarchicalStreamWriter.class), captor.capture());
    MarshallingContext context = captor.getValue();
    assertThat(context, not(nullValue()));
    assertThat(context.get(CswConstants.OUTPUT_SCHEMA_PARAMETER), is(CswConstants.CSW_OUTPUT_SCHEMA));
    assertThat(context.get(CswConstants.ELEMENT_SET_TYPE), is(ElementSetType.FULL));
    JAXBElement<GetRecordsResponseType> jaxb = (JAXBElement<GetRecordsResponseType>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
    GetRecordsResponseType response = jaxb.getValue();
    // Assert the GetRecordsResponse elements and attributes
    assertThat(response, not(nullValue()));
    SearchResultsType resultsType = response.getSearchResults();
    assertThat(resultsType, not(nullValue()));
    assertThat(resultsType.getElementSet(), is(ElementSetType.FULL));
    assertThat(resultsType.getNumberOfRecordsMatched().intValue(), is(totalResults));
    assertThat(resultsType.getNumberOfRecordsReturned().intValue(), is(totalResults));
    assertThat(resultsType.getRecordSchema(), is(CswConstants.CSW_OUTPUT_SCHEMA));
}
Also used : HierarchicalStreamWriter(com.thoughtworks.xstream.io.HierarchicalStreamWriter) XStream(com.thoughtworks.xstream.XStream) SearchResultsType(net.opengis.cat.csw.v_2_0_2.SearchResultsType) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) JAXBElement(javax.xml.bind.JAXBElement) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) ElementSetNameType(net.opengis.cat.csw.v_2_0_2.ElementSetNameType) GetRecordsResponseType(net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType) MarshallingContext(com.thoughtworks.xstream.converters.MarshallingContext) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)23 JAXBElement (javax.xml.bind.JAXBElement)22 ObjectFactory (net.opengis.cat.csw.v_2_0_2.ObjectFactory)20 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)18 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)17 QName (javax.xml.namespace.QName)13 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)13 XStream (com.thoughtworks.xstream.XStream)12 ByteArrayInputStream (java.io.ByteArrayInputStream)12 GetRecordsResponseType (net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType)12 SearchResultsType (net.opengis.cat.csw.v_2_0_2.SearchResultsType)12 ArrayList (java.util.ArrayList)11 Marshaller (javax.xml.bind.Marshaller)11 ElementSetNameType (net.opengis.cat.csw.v_2_0_2.ElementSetNameType)11 MarshallingContext (com.thoughtworks.xstream.converters.MarshallingContext)10 HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)10 StringWriter (java.io.StringWriter)10 BigInteger (java.math.BigInteger)10 JAXBContext (javax.xml.bind.JAXBContext)10 ObjectFactory (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory)8