Example usage for javax.xml.bind JAXBIntrospector getElementName

List of usage examples for javax.xml.bind JAXBIntrospector getElementName

Introduction

In this page you can find the example usage for javax.xml.bind JAXBIntrospector getElementName.

Prototype

public abstract QName getElementName(Object jaxbElement);

Source Link

Document

Get xml element qname for jaxbElement.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Object value = "Hello World";

    JAXBContext jc = JAXBContext.newInstance(String.class, Bar.class);
    JAXBIntrospector introspector = jc.createJAXBIntrospector();
    Marshaller marshaller = jc.createMarshaller();
    if (null == introspector.getElementName(value)) {
        JAXBElement jaxbElement = new JAXBElement(new QName("ROOT"), Object.class, value);
        marshaller.marshal(jaxbElement, System.out);
    } else {/*from   ww  w  .  j  a  v a  2  s  . c  o m*/
        marshaller.marshal(value, System.out);
    }
}

From source file:example.Main.java

public static void main(String[] args) throws Exception {
    Class[] classes = new Class[3];
    classes[0] = A.class;
    classes[1] = B.class;
    classes[2] = C.class;

    JAXBContext jc = JAXBContext.newInstance(classes);

    JAXBIntrospector ji = jc.createJAXBIntrospector();
    Map<QName, Class> classByQName = new HashMap<QName, Class>(classes.length);
    for (Class clazz : classes) {
        QName qName = ji.getElementName(clazz.newInstance());
        if (null != qName) {
            classByQName.put(qName, clazz);
        }/*from  w  w  w  .  j av  a  2  s. c o  m*/
    }

    QName qName = new QName("http://www.example.com", "EH");
    System.out.println(classByQName.get(qName));
}

From source file:com.autentia.xml.namespace.QNameBuilder.java

private QName discoverQNameFromJaxb(Class<?> classType) {
    QName qName = null;/* w w  w. j av  a  2  s. com*/
    try {
        final JAXBIntrospector jaxbIntrospector = JAXBContext.newInstance(classType).createJAXBIntrospector();
        qName = jaxbIntrospector.getElementName(classType.getConstructor().newInstance());

    } catch (Exception e) {
        // Add e to the logger message because JAXB Exceptions has a lot of information in the toString().
        // and some loggers implementations just print the getMessage();
        logger.warn("Cannot discover QName from JAXB annotations for class: " + classType.getName()
                + ". Preparing generic QName." + e, e);
    }

    if (qName == null) {
        // Could be null if getElementName returned null, or a exception was thrown.
        return EMPTY_Q_NAME;
    }
    return qName;
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.action.BiospecimenMetaDataProcessor.java

private void getDrugMetaData(final Patient patient, final BiospecimenMetaData patientMetaData,
        final Map<String, BiospecimenMetaData> biospecimenMetaDataByUUIDORBarcode,
        final JAXBIntrospector jaxbIntrospector, final Archive archive)
        throws ProcessorException, UUIDException {
    if (patient.getDrugs() != null) {
        List<Drug> drugs = patient.getDrugs().getDrug();
        if (drugs != null) {
            // Get drug meta-data for the patient
            for (final Drug drug : drugs) {
                BiospecimenMetaData drugMetaData = BiospecimenMetaData.newInstance(patientMetaData);
                final String uuid = JAXBUtil.getJAXBObjectValue(drug.getBcrDrugUuid());
                drugMetaData.setBarcode(drug.getBcrDrugBarcode().getValue());
                setUUID(drugMetaData, uuid, archive);
                drugMetaData.setUuidType(jaxbIntrospector.getElementName(drug).getLocalPart());
                biospecimenMetaDataByUUIDORBarcode.put(
                        (uuid == null || uuid.isEmpty()) ? drugMetaData.getBarcode() : drugMetaData.getUuid(),
                        drugMetaData);//  w w  w  .j  a va 2s.c  om
            }
        }
    }
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.action.BiospecimenMetaDataProcessor.java

private void getSampleMetaData(final Patient patient, final BiospecimenMetaData patientMetaData,
        final Map<String, BiospecimenMetaData> biospecimenMetaDataByUUIDORBarcode,
        final JAXBIntrospector jaxbIntrospector, final Archive archive)
        throws UUIDException, ProcessorException {
    if (patient.getSamples() != null) {
        List<Sample> samples = patient.getSamples().getSample();
        if (samples != null) {
            // Get sample meta-data for the patient
            for (final Sample sample : samples) {
                BiospecimenMetaData sampleMetaData = BiospecimenMetaData.newInstance(patientMetaData);
                final String uuid = JAXBUtil.getJAXBObjectValue(sample.getBcrSampleUuid());
                sampleMetaData.setBarcode(sample.getBcrSampleBarcode().getValue());
                setUUID(sampleMetaData, uuid, archive);
                sampleMetaData.setUuidType(jaxbIntrospector.getElementName(sample).getLocalPart());
                sampleMetaData.setSampleType(sample.getSampleTypeId().getValue());
                sampleMetaData.setVialId(sample.getVialNumber().getValue());
                biospecimenMetaDataByUUIDORBarcode
                        .put((uuid == null || uuid.isEmpty()) ? sampleMetaData.getBarcode()
                                : sampleMetaData.getUuid(), sampleMetaData);

                getPortionMetaData(sample, sampleMetaData, biospecimenMetaDataByUUIDORBarcode, jaxbIntrospector,
                        archive);/*from w w  w  . j  ava  2  s.c o m*/
                logger.debug("Portion metadata done");
                getShipmentPortionMetaData(sample, sampleMetaData, biospecimenMetaDataByUUIDORBarcode,
                        jaxbIntrospector, archive);
                logger.debug("Shipment Portion metadata done");
            }
        }
    }
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.action.BiospecimenMetaDataProcessor.java

private void getPortionMetaData(final Sample sample, final BiospecimenMetaData sampleMetaData,
        final Map<String, BiospecimenMetaData> biospecimenMetaDataByUUIDORBarcode,
        final JAXBIntrospector jaxbIntrospector, final Archive archive)
        throws UUIDException, ProcessorException {
    if (sample.getPortions() != null) {
        List<Portion> portions = sample.getPortions().getPortion();
        if (portions != null) {
            // Get portion meta-data for the sample
            for (final Portion portion : portions) {
                BiospecimenMetaData portionMetaData = BiospecimenMetaData.newInstance(sampleMetaData);
                final String uuid = JAXBUtil.getJAXBObjectValue(portion.getBcrPortionUuid());
                portionMetaData.setBarcode(portion.getBcrPortionBarcode().getValue());
                setUUID(portionMetaData, uuid, archive);
                portionMetaData.setUuidType(jaxbIntrospector.getElementName(portion).getLocalPart());
                portionMetaData.setPortionId(portion.getPortionNumber().getValue());
                biospecimenMetaDataByUUIDORBarcode
                        .put((uuid == null || uuid.isEmpty()) ? portionMetaData.getBarcode()
                                : portionMetaData.getUuid(), portionMetaData);
                getAnalyteMetaData(portion, portionMetaData, biospecimenMetaDataByUUIDORBarcode,
                        jaxbIntrospector, archive);
                logger.debug("Analyte metadata done");
                getSlideMetaData(portion, portionMetaData, biospecimenMetaDataByUUIDORBarcode, jaxbIntrospector,
                        archive);/*  ww w .j a v  a 2s  .c  o  m*/
                logger.debug("Slide metadata done");
            }
        }
    }
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.action.BiospecimenMetaDataProcessor.java

private void getAliquotMetaData(final Analyte analyte, final BiospecimenMetaData analyteMetaData,
        final Map<String, BiospecimenMetaData> biospecimenMetaDataByUUIDORBarcode,
        final JAXBIntrospector jaxbIntrospector, final Archive archive)
        throws ProcessorException, UUIDException {
    if (analyte.getAliquots() != null) {
        List<Aliquot> aliquots = analyte.getAliquots().getAliquot();
        if (aliquots != null) {
            // Get aliquot meta-data for the analyte
            for (final Aliquot aliquot : aliquots) {
                BiospecimenMetaData aliquotMetaData = BiospecimenMetaData.newInstance(analyteMetaData);
                final String uuid = JAXBUtil.getJAXBObjectValue(aliquot.getBcrAliquotUuid());
                aliquotMetaData.setBarcode(aliquot.getBcrAliquotBarcode().getValue());
                setUUID(aliquotMetaData, uuid, archive);
                aliquotMetaData.setUuidType(jaxbIntrospector.getElementName(aliquot).getLocalPart());
                aliquotMetaData.setPlateId(aliquot.getPlateId().getValue());
                aliquotMetaData.setReceivingCenter(aliquot.getCenterId().getValue());
                aliquotMetaData.setCenterCode(aliquot.getCenterId().getValue());
                biospecimenMetaDataByUUIDORBarcode
                        .put((uuid == null || uuid.isEmpty()) ? aliquotMetaData.getBarcode()
                                : aliquotMetaData.getUuid(), aliquotMetaData);
            }//from  ww  w .  j av a  2  s.  co  m
        }
    }
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.action.BiospecimenMetaDataProcessor.java

private void getSurgeryMetaData(final Patient patient, final BiospecimenMetaData patientMetaData,
        final Map<String, BiospecimenMetaData> biospecimenMetaDataByUUIDORBarcode,
        final JAXBIntrospector jaxbIntrospector, final Archive archive)
        throws ProcessorException, UUIDException {
    if (patient.getSurgeries() != null) {
        List<Surgery> surgeries = patient.getSurgeries().getSurgery();
        if (surgeries != null) {
            // Get surgery meta-data for the patient
            for (final Surgery surgery : surgeries) {
                BiospecimenMetaData surgeryMetaData = BiospecimenMetaData.newInstance(patientMetaData);
                final String uuid = JAXBUtil.getJAXBObjectValue(surgery.getBcrSurgeryUuid());
                surgeryMetaData.setBarcode(surgery.getBcrSurgeryBarcode().getValue());
                setUUID(surgeryMetaData, uuid, archive);
                surgeryMetaData.setUuidType(jaxbIntrospector.getElementName(surgery).getLocalPart());
                biospecimenMetaDataByUUIDORBarcode
                        .put((uuid == null || uuid.isEmpty()) ? surgeryMetaData.getBarcode()
                                : surgeryMetaData.getUuid(), surgeryMetaData);
            }//from   www.  j ava  2 s . c o  m
        }
    }
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.action.BiospecimenMetaDataProcessor.java

private void getAnalyteMetaData(final Portion portion, final BiospecimenMetaData portionMetaData,
        final Map<String, BiospecimenMetaData> biospecimenMetaDataByUUIDORBarcode,
        final JAXBIntrospector jaxbIntrospector, final Archive archive)
        throws ProcessorException, UUIDException {
    if (portion.getAnalytes() != null) {
        List<Analyte> analytes = portion.getAnalytes().getAnalyte();
        if (analytes != null) {
            // Get portion meta-data for the sample
            for (final Analyte analyte : analytes) {
                BiospecimenMetaData analyteMetaData = BiospecimenMetaData.newInstance(portionMetaData);
                final String uuid = JAXBUtil.getJAXBObjectValue(analyte.getBcrAnalyteUuid());
                analyteMetaData.setBarcode(analyte.getBcrAnalyteBarcode().getValue());
                setUUID(analyteMetaData, uuid, archive);
                analyteMetaData.setUuidType(jaxbIntrospector.getElementName(analyte).getLocalPart());
                analyteMetaData.setAnalyteType(analyte.getAnalyteTypeId().getValue());
                biospecimenMetaDataByUUIDORBarcode
                        .put((uuid == null || uuid.isEmpty()) ? analyteMetaData.getBarcode()
                                : analyteMetaData.getUuid(), analyteMetaData);
                getAliquotMetaData(analyte, analyteMetaData, biospecimenMetaDataByUUIDORBarcode,
                        jaxbIntrospector, archive);
                logger.debug("Aliquot metadata done");
                logger.info("BiospecimenMetaDataProcessor: Processed analyte with UUID "
                        + analyteMetaData.getUuid() + " and parent " + analyteMetaData.getParentUUID());

            }/*from   w w w.j av a  2  s.  c  o m*/
        }
    }
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.action.BiospecimenMetaDataProcessor.java

private void getRadiationMetaData(final Patient patient, final BiospecimenMetaData patientMetaData,
        final Map<String, BiospecimenMetaData> biospecimenMetaDataByUUIDORBarcode,
        final JAXBIntrospector jaxbIntrospector, final Archive archive)
        throws ProcessorException, UUIDException {
    if (patient.getRadiations() != null) {
        List<Radiation> radiations = patient.getRadiations().getRadiation();
        if (radiations != null) {
            // Get radiation meta-data for the patient
            for (final Radiation radiation : radiations) {
                BiospecimenMetaData radiationMetaData = BiospecimenMetaData.newInstance(patientMetaData);
                final String uuid = JAXBUtil.getJAXBObjectValue(radiation.getBcrRadiationUuid());
                radiationMetaData.setBarcode(radiation.getBcrRadiationBarcode().getValue());
                setUUID(radiationMetaData, uuid, archive);
                radiationMetaData.setUuidType(jaxbIntrospector.getElementName(radiation).getLocalPart());
                biospecimenMetaDataByUUIDORBarcode
                        .put((uuid == null || uuid.isEmpty()) ? radiationMetaData.getBarcode()
                                : radiationMetaData.getUuid(), radiationMetaData);
            }/*from   w w w.j  a  va  2  s. c  o m*/
        }
    }
}