Example usage for javax.xml.bind Marshaller setProperty

List of usage examples for javax.xml.bind Marshaller setProperty

Introduction

In this page you can find the example usage for javax.xml.bind Marshaller setProperty.

Prototype

public void setProperty(String name, Object value) throws PropertyException;

Source Link

Document

Set the particular property in the underlying implementation of Marshaller .

Usage

From source file:com.mymita.vaadlets.JAXBUtils.java

private static final void marshal(final Writer aWriter, final Vaadlets vaadlets,
        final Resource theSchemaResource) {
    try {//from  w ww.  ja v  a 2s.  co  m
        final JAXBContext jc = JAXBContext.newInstance(CONTEXTPATH);
        final Marshaller marshaller = jc.createMarshaller();
        if (theSchemaResource != null) {
            final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            schemaFactory.setResourceResolver(new ClasspathResourceResolver());
            final Schema schema = schemaFactory.newSchema(new StreamSource(theSchemaResource.getInputStream()));
            marshaller.setSchema(schema);
        }
        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper",
                new com.sun.xml.internal.bind.marshaller.NamespacePrefixMapper() {

                    @Override
                    public String getPreferredPrefix(final String namespaceUri, final String suggestion,
                            final boolean requirePrefix) {
                        final String subpackage = namespaceUri.replaceFirst("http://www.mymita.com/vaadlets/",
                                "");
                        if (subpackage.equals("1.0.0")) {
                            return "";
                        }
                        return Iterables.getFirst(newArrayList(Splitter.on("/").split(subpackage).iterator()),
                                "");
                    }
                });
        marshaller.marshal(
                new JAXBElement<Vaadlets>(new QName("http://www.mymita.com/vaadlets/1.0.0", "vaadlets", ""),
                        Vaadlets.class, vaadlets),
                aWriter);
    } catch (final JAXBException | SAXException | FactoryConfigurationError | IOException e) {
        throw new RuntimeException("Can't marschal", e);
    }
}

From source file:com.jkoolcloud.tnt4j.streams.utils.StreamsCache.java

private static void persist(Map<String, CacheValue> cacheEntries) {
    try {/*  w w w.j av  a 2 s . co m*/
        JAXBContext jc = JAXBContext.newInstance(CacheRoot.class);
        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        CacheRoot root = new CacheRoot();
        root.setEntriesMap(cacheEntries);
        File persistedFile = new File(DEFAULT_FILE_NAME);
        LOGGER.log(OpLevel.DEBUG, StreamsResources.getBundle(StreamsResources.RESOURCE_BUNDLE_NAME),
                "StreamsCache.persisting.file", persistedFile.getAbsolutePath());
        marshaller.marshal(root, persistedFile);
        LOGGER.log(OpLevel.DEBUG, StreamsResources.getBundle(StreamsResources.RESOURCE_BUNDLE_NAME),
                "StreamsCache.persisting.done", cacheEntries.size(), persistedFile.getAbsolutePath());
    } catch (JAXBException exc) {
        Utils.logThrowable(LOGGER, OpLevel.ERROR,
                StreamsResources.getBundle(StreamsResources.RESOURCE_BUNDLE_NAME),
                "StreamsCache.persisting.failed", exc);
    }
}

From source file:labr_client.xml.ObjToXML.java

public static void jaxbObjectToXML(KmehrMessage kmehrMessage) {
    try {//  w  w  w . j av  a 2s  .c o  m
        JAXBContext context = JAXBContext.newInstance(KmehrMessage.class);
        Marshaller m = context.createMarshaller();
        //for pretty-print XML in JAXB
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        //----------HEADER--------------------------
        kmehrMessage.header.id.setS("ID-KMEHR");
        kmehrMessage.header.id.setSV("1.15");
        kmehrMessage.header.id.setValue("0000000");
        kmehrMessage.header.setDate("20160519");
        kmehrMessage.header.setTime("09:40:31");
        kmehrMessage.header.standard.cd.setS("CD-STANDARD");
        kmehrMessage.header.standard.cd.setSV("1.15");
        kmehrMessage.header.standard.cd.setValue("20150901");
        //----------HEADER-ZENDER-------------------------
        kmehrMessage.header.sender.hcparty.id.setS("ID-HCPARTY");
        kmehrMessage.header.sender.hcparty.id.setSV("1.15");
        kmehrMessage.header.sender.hcparty.id.setValue("000000");
        kmehrMessage.header.sender.hcparty.cd.setS("CD-HCPARTY");
        kmehrMessage.header.sender.hcparty.cd.setSV("1.15");
        kmehrMessage.header.sender.hcparty.cd.setValue("persphysician");
        kmehrMessage.header.sender.hcparty.setFamilyname("Pieters");
        kmehrMessage.header.sender.hcparty.setFirstname("Piet");
        //----------HEADER-ONTVANGER(S)--------------------
        Hcparty receiver = new Hcparty();
        receiver.id.setS("ID-HCPARTY");
        receiver.id.setSV("1.15");
        receiver.id.setValue("000000");
        receiver.cd.setS("CD-HCPARTY");
        receiver.cd.setSV("1.15");
        receiver.cd.setValue("persphysician");
        receiver.setFamilyname("Pieters");
        receiver.setFirstname("Piet");
        kmehrMessage.header.receiver.getHcparty().add(receiver);
        //----------FOLDER-------------------------
        kmehrMessage.folder.id.setS("ID-HCPARTY");
        kmehrMessage.folder.id.setSV("1.15");
        kmehrMessage.folder.patient.setFamilyname("De Mey");
        kmehrMessage.folder.patient.setFirstname("Matthias");
        kmehrMessage.folder.patient.birthdate.setDate("1990/06/07");

        kmehrMessage.setXmlns("http://www.ehealth.fgov.be/standards/kmehr/schema/v1");

        m.marshal(kmehrMessage, new File("C:\\Users\\labbl\\Documents\\testKMEHR.xml"));
    } catch (JAXBException e) {
        e.printStackTrace();
    }
}

From source file:labr_client.xml.ObjToXML.java

public static void jaxbObjectToXML(LabrRequest request, HashMap<String, String> patient) {

    try {/*from   w w  w .ja v  a 2  s. co  m*/
        JAXBContext context = JAXBContext.newInstance(LabrRequest.class);
        Marshaller m = context.createMarshaller();
        //for pretty-print XML in JAXB
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        //----------PATIENT----------------------------
        request.patient.name.setValue("De Mey");
        request.patient.name.setX(20);
        request.patient.name.setY(50);
        request.patient.firstName.setValue("Matthias");
        request.patient.firstName.setX(150);
        request.patient.firstName.setY(50);
        request.patient.birthDate.setValue("07/06/1990");
        request.patient.birthDate.setX(20);
        request.patient.birthDate.setY(80);
        request.patient.gender.setValue("M");
        request.patient.gender.setX(150);
        request.patient.gender.setY(80);
        request.patient.straatAndNumber.setValue("Hemelbeekstraat 16");
        request.patient.straatAndNumber.setX(20);
        request.patient.straatAndNumber.setY(110);
        request.patient.zip.setValue("8000");
        request.patient.zip.setX(20);
        request.patient.zip.setY(140);
        request.patient.city.setValue("Brugge");
        request.patient.city.setX(120);
        request.patient.city.setY(140);

        request.patient.country.setValue("Belgie");
        request.patient.country.setX(20);
        request.patient.country.setY(170);
        request.patient.nationalNumber.setValue("001-12345-223");
        request.patient.nationalNumber.setX(120);
        request.patient.nationalNumber.setY(210);
        //----------ATTRIBUTEN-------------------------
        request.attributes.setAge(26);
        //----------LABELS-----------------------------
        LabrXMLLabel l = new LabrXMLLabel();
        l.setColor("#110000");
        l.setSize(12);
        l.setId("1");
        l.setValue("Hematologie");
        request.labels.getLabel().add(l);
        //---------KNOPPEN-----------------------------
        request.buttons.save.setX(300);
        request.buttons.save.setY(100);
        request.buttons.save.setColor(-65536);
        request.buttons.save.setWidth(100);
        request.buttons.save.setValue("Save");
        //----------AANVRAGEN--------------------------
        LabrXMLRequest r = new LabrXMLRequest();
        r.setComment("Dit is commentaar");
        r.setLoinc("Kalium");
        request.requests.getRequest().add(r);
        r.setLoinc("Natrium");
        request.requests.getRequest().add(r);
        //----------AANVRAGEN--------------------------
        // Write to System.out for debugging
        // m.marshal(emp, System.out);            
        // Write to File
        m.marshal(request, new File("C:\\Users\\labbl\\Documents\\test.xml"));
    } catch (JAXBException e) {
        e.printStackTrace();
    }

}

From source file:com.intuit.tank.transform.scriptGenerator.ConverterUtil.java

public static String getWorkloadXML(HDWorkload hdWorkload) {
    StringWriter sw;/*from w w  w .  j a  v  a  2  s . c om*/
    try {
        JAXBContext context = JAXBContext.newInstance(HDWorkload.class.getPackage().getName());
        Marshaller createMarshaller = context.createMarshaller();
        createMarshaller.setProperty("jaxb.formatted.output", Boolean.TRUE);
        sw = new StringWriter();
        createMarshaller.marshal(hdWorkload, sw);
        sw.flush();
        sw.close();
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    return sw.toString();

}

From source file:com.virtualparadigm.packman.processor.JPackageManagerBU.java

private static void marshallToFile(Collection<Package> installPackages, String filePath) {
    try {// ww  w . j  a  va 2 s. co m
        Marshaller marshaller = jaxbContext.createMarshaller();

        // removes the xml header:
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
        StringWriter stringWriter = new StringWriter();
        for (Package installPackage : installPackages) {
            marshaller.marshal(
                    new JAXBElement<Package>(new QName(null, "installPackage"), Package.class, installPackage),
                    stringWriter);

            stringWriter.append("\n");
        }

        FileUtils.writeStringToFile(new File(filePath), stringWriter.toString(), "UTF-8");
    } catch (Exception e) {
        logger.error("", e);
        //            e.printStackTrace();
    }
}

From source file:cz.lbenda.dataman.db.ExportTableData.java

/** Write rows from sql query to output stream
 * @param sqlQueryRows rows/*from  w w w  .j av a  2  s  . co m*/
 * @param outputStream stream to which are data write */
public static void writeSqlQueryRowsToXMLv1(SQLQueryRows sqlQueryRows, OutputStream outputStream) {
    ObjectFactory of = new ObjectFactory();
    ExportType export = of.createExportType();
    export.setSql(sqlQueryRows.getSQL());
    export.setVersion("1");
    ColumnsType columnsType = of.createColumnsType();
    export.setColumns(columnsType);
    Map<ColumnDesc, ColumnType> ctsMap = new HashMap<>();

    sqlQueryRows.getMetaData().getColumns().forEach(cd -> {
        ColumnType ct = of.createColumnType();
        ctsMap.put(cd, ct);
        ct.setId(columnId(cd));
        ct.setCatalog(cd.getCatalog());
        ct.setSchema(cd.getSchema());
        ct.setTable(cd.getTable());
        ct.setColumn(cd.getName());
        ct.setDataType(DbStructureFactory.columnTypeToDataTypeType(cd.getDataType()));
        ct.setLength(cd.getSize());
        ct.setScale(cd.getScale());
        ct.setValue(cd.getLabel());
        columnsType.getColumn().add(ct);
    });

    sqlQueryRows.getRows().forEach(row -> {
        RowType rowType = of.createRowType();
        sqlQueryRows.getMetaData().getColumns().forEach(cd -> {
            FieldType field = of.createFieldType();
            field.setColumn(ctsMap.get(cd));
            if (row.isColumnNull(cd)) {
                field.setNull(true);
            } else {
                field.setValue(row.getColumnValueStr(cd));
            }
            rowType.getField().add(field);
        });
        export.getRow().add(rowType);
    });

    try {
        JAXBContext jc = JAXBContext.newInstance(cz.lbenda.dataman.schema.export.ObjectFactory.class);
        Marshaller m = jc.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE);
        m.marshal(of.createExport(export), outputStream);
    } catch (JAXBException e) {
        LOG.error("Problem with write exporting data: " + e.toString(), e);
        throw new RuntimeException("Problem with write exporting data: " + e.toString(), e);
    }
}

From source file:labr_client.xml.ObjToXML.java

public static void saveKmehrRequest(LabrRequest request) {
    String date = String.format("%1$tY%1$tm%1$td", new Date());
    String time = String.format("%1$tH%1$tM%1$tS", new Date());
    try {//from w w w. j  ava2 s. com
        KmehrMessage kmehrMessage = new KmehrMessage();
        JAXBContext context = JAXBContext.newInstance(KmehrMessage.class);
        Marshaller m = context.createMarshaller();
        //for pretty-print XML in JAXB
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        //----------HEADER--------------------------
        kmehrMessage.header.id.setS("ID-KMEHR");
        kmehrMessage.header.id.setSV("1.15");
        kmehrMessage.header.id.setValue(request.attributes.getTitle());
        kmehrMessage.header.setDate(date);
        kmehrMessage.header.setTime(time);
        kmehrMessage.header.standard.cd.setS("CD-STANDARD");
        kmehrMessage.header.standard.cd.setSV("1.15");
        kmehrMessage.header.standard.cd.setValue("20150901");
        //----------HEADER-ZENDER-------------------------
        kmehrMessage.header.sender.hcparty.id.setS("ID-HCPARTY");
        kmehrMessage.header.sender.hcparty.id.setSV("1.15");
        kmehrMessage.header.sender.hcparty.id.setValue(request.attributes.getSenderID());
        kmehrMessage.header.sender.hcparty.cd.setS("CD-HCPARTY");
        kmehrMessage.header.sender.hcparty.cd.setSV("1.15");
        kmehrMessage.header.sender.hcparty.cd.setValue("persphysician");
        kmehrMessage.header.sender.hcparty.setFamilyname("Pieters");
        kmehrMessage.header.sender.hcparty.setFirstname("Piet");
        //----------HEADER-ONTVANGER(S)--------------------
        Hcparty receiver = new Hcparty();
        receiver.id.setS("ID-HCPARTY");
        receiver.id.setSV("1.15");
        receiver.id.setValue(request.attributes.receiver1ID);
        receiver.cd.setS("CD-HCPARTY");
        receiver.cd.setSV("1.15");
        receiver.cd.setValue("persphysician");
        receiver.setFamilyname("Pieters");
        receiver.setFirstname("Piet");
        kmehrMessage.header.receiver.getHcparty().add(receiver);
        //----------FOLDER-PATIENT-------------------------
        kmehrMessage.folder.id.setS("ID-HCPARTY");
        kmehrMessage.folder.id.setSV("1.15");
        kmehrMessage.folder.id.setValue(request.patient.nationalNumber.getValue());
        kmehrMessage.folder.patient.setFamilyname(request.patient.name.getValue());
        kmehrMessage.folder.patient.setFirstname(request.patient.firstName.getValue());
        kmehrMessage.folder.patient.birthdate.setDate(request.patient.birthDate.getValue());
        kmehrMessage.folder.patient.sex.cd.setS("CD-SEX");
        kmehrMessage.folder.patient.sex.cd.setSV("1.15");
        kmehrMessage.folder.patient.sex.cd.setValue("M");
        kmehrMessage.folder.patient.address.cd.setS("CD-ADDRESS");
        kmehrMessage.folder.patient.address.cd.setSV("1.15");
        kmehrMessage.folder.patient.address.country.cd.setS("CD-COUNTRY");
        kmehrMessage.folder.patient.address.country.cd.setSV("1.15");
        kmehrMessage.folder.patient.address.country.cd.setValue(request.patient.country.getValue());
        kmehrMessage.folder.patient.address.setCity(request.patient.city.getValue());
        kmehrMessage.folder.patient.address.setStreetandnumber(request.patient.straatAndNumber.getValue());
        kmehrMessage.folder.patient.address.setZip(request.patient.zip.getValue());
        Transaction t = new Transaction();
        t.id.setS("ID-KMEHR");
        t.id.setSV("1.15");
        t.id.setValue("1");
        t.cd.setS("CD-TRANSACTION");
        t.cd.setSV("1.15");
        t.cd.setValue("request");
        t.setDate(date);
        t.setTime(time);
        t.author.hcparty.id.setS("ID-HCPARTY");
        t.author.hcparty.id.setSV("1.15");
        t.author.hcparty.id.setValue(request.attributes.getSenderID());
        t.author.hcparty.cd.setS("CD-HCPARTY");
        t.author.hcparty.cd.setSV("1.15");
        t.author.hcparty.cd.setValue("persphysician");
        t.author.hcparty.setFamilyname("Pieters");
        t.author.hcparty.setFirstname("Piet");
        Item i = new Item();
        i.id.setS("ID-KMEHR");
        i.id.setSV("1.15");
        i.id.setValue("1");
        i.cd.setS("CD-ITEM");
        i.cd.setSV("1.15");
        i.cd.setValue("lab");
        List<LabrXMLRequest> requests = request.requests.getRequest();
        for (LabrXMLRequest req : requests) {
            if (req.isSelected() & req.getLoinc() != null) {
                Cd cd = new Cd();
                cd.setS("CD-LAB");
                cd.setSV("1.15");
                cd.setValue(req.getLoinc());
                i.content.getCd().add(cd);
            }

        }
        t.getItem().add(i);
        kmehrMessage.folder.getTransaction().add(t);
        kmehrMessage.setXmlns("http://www.ehealth.fgov.be/standards/kmehr/schema/v1");

        //START------ZOEK DE PATIENT OP EN BEWAAR AANVRAAG IN DATABASE-------------------------      
        File KmehrRequest = new File("data/tmp/" + date + time + ".xml");
        m.marshal(kmehrMessage, KmehrRequest);
        List<String[]> patientID = PublicVars.getQueries().selectPatient(request.patient.firstName.getValue(),
                request.patient.name.getValue(), request.patient.birthDate.getValue());
        if (patientID.size() == 0) {
            PublicVars.getQueries().insertPatient(request);
            patientID = PublicVars.getQueries().selectPatient(request.patient.firstName.getValue(),
                    request.patient.name.getValue(), request.patient.birthDate.getValue());
            PublicVars.getQueries().insertLabRequest(marshallRequest(request),
                    FileUtils.readFileToString(KmehrRequest), Integer.parseInt(patientID.get(0)[0]),
                    Integer.parseInt(PublicVars.getUserData()[1]), kmehrMessage.header.id.getValue());
        } else {
            PublicVars.getQueries().insertLabRequest(marshallRequest(request),
                    FileUtils.readFileToString(KmehrRequest), Integer.parseInt(patientID.get(0)[0]),
                    Integer.parseInt(PublicVars.getUserData()[1]), kmehrMessage.header.id.getValue());
        }
        //EIND---------------------------------------------------------------------------------

    } catch (JAXBException e) {
        e.printStackTrace();
    } catch (IOException ex) {
        Logger.getLogger(ObjToXML.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:labr_client.xml.ObjToXML.java

public static void saveProfile(Component[] comps, String profile) {

    try {//from ww  w  .j  av a  2 s.  c o  m
        if (comps != null) {
            JAXBContext context = JAXBContext.newInstance(LabrRequest.class);
            Marshaller m = context.createMarshaller();
            //for pretty-print XML in JAXB
            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
            LabrRequest request = new LabrRequest();
            for (Component comp : comps) {

                if (comp.getName() != null) {

                    if (comp.getName().equals("name")) {
                        request.patient.name.setValue(((JTextField) comp).getText());
                        request.patient.name.setX(comp.getX());
                        request.patient.name.setY(comp.getY());
                        request.patient.name.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("firstName")) {
                        request.patient.firstName.setValue(((JTextField) comp).getText());
                        request.patient.firstName.setX(comp.getX());
                        request.patient.firstName.setY(comp.getY());
                        request.patient.firstName.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("birthDate")) {
                        request.patient.birthDate.setValue(((JFormattedTextField) comp).getText());
                        request.patient.birthDate.setX(comp.getX());
                        request.patient.birthDate.setY(comp.getY());
                        request.patient.birthDate.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("gender")) {
                        request.patient.gender.setValue((String) (((JComboBox) comp).getSelectedItem()));
                        request.patient.gender.setX(comp.getX());
                        request.patient.gender.setY(comp.getY());
                    } else if (comp.getName().equals("straatAndNumber")) {
                        request.patient.straatAndNumber.setValue(((JTextField) comp).getText());
                        request.patient.straatAndNumber.setX(comp.getX());
                        request.patient.straatAndNumber.setY(comp.getY());
                        request.patient.straatAndNumber.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("zip")) {
                        request.patient.zip.setValue(((JTextField) comp).getText());
                        request.patient.zip.setX(comp.getX());
                        request.patient.zip.setY(comp.getY());
                        request.patient.zip.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("city")) {
                        request.patient.city.setValue(((JTextField) comp).getText());
                        request.patient.city.setX(comp.getX());
                        request.patient.city.setY(comp.getY());
                        request.patient.city.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("country")) {
                        request.patient.country.setValue((String) (((JComboBox) comp).getSelectedItem()));
                        request.patient.country.setX(comp.getX());
                        request.patient.country.setY(comp.getY());
                    } else if (comp.getName().equals("nationalNumber")) {
                        request.patient.nationalNumber.setValue(((JTextField) comp).getText());
                        request.patient.nationalNumber.setX(comp.getX());
                        request.patient.nationalNumber.setY(comp.getY());
                        request.patient.nationalNumber.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("Save")) {
                        JButton jbut = (JButton) comp;
                        ImageIcon icon = (ImageIcon) jbut.getIcon();
                        request.buttons.save.setX(comp.getX());
                        request.buttons.save.setY(comp.getY());
                        request.buttons.save.setValue("Save");
                        if (icon != null) {
                            request.buttons.save.setIcon(icon.getDescription());
                        }
                    } else if (comp.getName().equals("Search")) {
                    } else if (comp.getName().equals("saveAndSend")) {
                        request.patient.nationalNumber.setValue(((JTextField) comp).getText());
                        request.patient.nationalNumber.setX(comp.getX());
                        request.patient.nationalNumber.setY(comp.getY());
                        request.patient.nationalNumber.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("print")) {
                        request.patient.nationalNumber.setValue(((JTextField) comp).getText());
                        request.patient.nationalNumber.setX(comp.getX());
                        request.patient.nationalNumber.setY(comp.getY());
                        request.patient.nationalNumber.setWidth(comp.getWidth());
                    } else {
                        Class<? extends Component> c = comp.getClass();
                        if (c.getSimpleName().equals("JLabel")) {
                            JLabel lbl = (JLabel) comp;
                            LabrXMLLabel l = new LabrXMLLabel();
                            l.setColor(String.valueOf(lbl.getForeground().getRGB()));
                            l.setSize(lbl.getFont().getSize());
                            l.setId(lbl.getName());
                            l.setValue(lbl.getText());
                            l.setX(lbl.getX());
                            l.setY(lbl.getY());
                            request.labels.getLabel().add(l);
                        }
                        ;
                        if (c.getSimpleName().equals("JCheckBox")) {
                            JCheckBox chbx = (JCheckBox) comp;
                            LabrXMLRequest req = new LabrXMLRequest();
                            req.setX(chbx.getX());
                            req.setY(chbx.getY());
                            req.setLoinc(chbx.getName());
                            req.setValue(chbx.getText());
                            req.setSelected(chbx.isSelected());
                            request.requests.getRequest().add(req);
                        }
                        ;
                        if (c.getSimpleName().equals("JTextBox")) {

                        }
                        ;
                    }
                }

            }
            m.marshal(request, new File(PublicVars.getUserData()[9] + "\\" + profile + ".xml"));
        }
    } catch (JAXBException e) {
        e.printStackTrace();
    }
}

From source file:labr_client.xml.ObjToXML.java

public static LabrRequest saveLabrRequest(Component[] comps) {

    try {/*  www.  j  a va 2s .c o m*/
        if (comps != null) {
            JAXBContext context = JAXBContext.newInstance(LabrRequest.class);
            Marshaller m = context.createMarshaller();
            //for pretty-print XML in JAXB
            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
            LabrRequest request = new LabrRequest();
            for (Component comp : comps) {

                if (comp.getName() != null) {

                    if (comp.getName().equals("name")) {
                        request.patient.name.setValue(((JTextField) comp).getText());
                        request.patient.name.setX(comp.getX());
                        request.patient.name.setY(comp.getY());
                        request.patient.name.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("firstName")) {
                        request.patient.firstName.setValue(((JTextField) comp).getText());
                        request.patient.firstName.setX(comp.getX());
                        request.patient.firstName.setY(comp.getY());
                        request.patient.firstName.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("birthDate")) {
                        request.patient.birthDate.setValue(((JFormattedTextField) comp).getText());
                        request.patient.birthDate.setX(comp.getX());
                        request.patient.birthDate.setY(comp.getY());
                        request.patient.birthDate.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("gender")) {
                        request.patient.gender.setValue((String) (((JComboBox) comp).getSelectedItem()));
                        request.patient.gender.setX(comp.getX());
                        request.patient.gender.setY(comp.getY());
                    } else if (comp.getName().equals("straatAndNumber")) {
                        request.patient.straatAndNumber.setValue(((JTextField) comp).getText());
                        request.patient.straatAndNumber.setX(comp.getX());
                        request.patient.straatAndNumber.setY(comp.getY());
                        request.patient.straatAndNumber.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("zip")) {
                        request.patient.zip.setValue(((JTextField) comp).getText());
                        request.patient.zip.setX(comp.getX());
                        request.patient.zip.setY(comp.getY());
                        request.patient.zip.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("city")) {
                        request.patient.city.setValue(((JTextField) comp).getText());
                        request.patient.city.setX(comp.getX());
                        request.patient.city.setY(comp.getY());
                        request.patient.city.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("country")) {
                        request.patient.country.setValue((String) (((JComboBox) comp).getSelectedItem()));
                        request.patient.country.setX(comp.getX());
                        request.patient.country.setY(comp.getY());
                    } else if (comp.getName().equals("nationalNumber")) {
                        request.patient.nationalNumber.setValue(((JTextField) comp).getText());
                        request.patient.nationalNumber.setX(comp.getX());
                        request.patient.nationalNumber.setY(comp.getY());
                        request.patient.nationalNumber.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("Save")) {
                        JButton jbut = (JButton) comp;
                        ImageIcon icon = (ImageIcon) jbut.getIcon();
                        request.buttons.save.setX(comp.getX());
                        request.buttons.save.setY(comp.getY());
                        request.buttons.save.setValue("Save");
                        if (icon != null) {
                            request.buttons.save.setIcon(icon.getDescription());
                        }
                    } else if (comp.getName().equals("Search")) {
                    } else if (comp.getName().equals("saveAndSend")) {
                        request.patient.nationalNumber.setValue(((JTextField) comp).getText());
                        request.patient.nationalNumber.setX(comp.getX());
                        request.patient.nationalNumber.setY(comp.getY());
                        request.patient.nationalNumber.setWidth(comp.getWidth());
                    } else if (comp.getName().equals("print")) {
                        request.patient.nationalNumber.setValue(((JTextField) comp).getText());
                        request.patient.nationalNumber.setX(comp.getX());
                        request.patient.nationalNumber.setY(comp.getY());
                        request.patient.nationalNumber.setWidth(comp.getWidth());
                    } else {
                        Class<? extends Component> c = comp.getClass();
                        if (c.getSimpleName().equals("JLabel")) {
                            JLabel lbl = (JLabel) comp;
                            LabrXMLLabel l = new LabrXMLLabel();
                            l.setColor(String.valueOf(lbl.getForeground().getRGB()));
                            l.setSize(lbl.getFont().getSize());
                            l.setId(lbl.getName());
                            l.setValue(lbl.getText());
                            l.setX(lbl.getX());
                            l.setY(lbl.getY());
                            request.labels.getLabel().add(l);
                        }
                        ;
                        if (c.getSimpleName().equals("JCheckBox")) {
                            JCheckBox chbx = (JCheckBox) comp;
                            LabrXMLRequest req = new LabrXMLRequest();
                            req.setX(chbx.getX());
                            req.setY(chbx.getY());
                            req.setLoinc(chbx.getName());
                            req.setValue(chbx.getText());
                            req.setSelected(chbx.isSelected());
                            request.requests.getRequest().add(req);
                        }
                        ;
                        if (c.getSimpleName().equals("JTextBox")) {

                        }
                        ;
                    }
                }
            }
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddhhmm");
            String date = dateFormat.format(Calendar.getInstance().getTime());
            request.attributes.setTitle("LABR-" + PublicVars.getUserData()[5] + "-" + date);
            return request;
        }
        return null;
    } catch (JAXBException e) {
        e.printStackTrace();
        return null;
    }
}