Example usage for javax.xml.bind JAXBElement getValue

List of usage examples for javax.xml.bind JAXBElement getValue

Introduction

In this page you can find the example usage for javax.xml.bind JAXBElement getValue.

Prototype

public T getValue() 

Source Link

Document

Return the content model and attribute values for this element.

See #isNil() for a description of a property constraint when this value is null

Usage

From source file:com.hp.autonomy.searchcomponents.idol.parametricvalues.IdolParametricValuesService.java

@Override
public Set<QueryTagInfo> getAllParametricValues(final IdolParametricRequest parametricRequest)
        throws AciErrorException {
    final Collection<String> fieldNames = new HashSet<>();
    fieldNames.addAll(parametricRequest.getFieldNames());
    if (fieldNames.isEmpty()) {
        fieldNames.addAll(fieldsService.getParametricFields(new IdolFieldsRequest.Builder().build()));
    }//from   ww w.j a  v  a2 s  . c  om

    final Set<QueryTagInfo> results;
    if (fieldNames.isEmpty()) {
        results = Collections.emptySet();
    } else {
        final AciParameters aciParameters = new AciParameters(TagActions.GetQueryTagValues.name());
        parameterHandler.addSearchRestrictions(aciParameters, parametricRequest.getQueryRestrictions());

        if (parametricRequest.isModified()) {
            parameterHandler.addQmsParameters(aciParameters, parametricRequest.getQueryRestrictions());
        }

        aciParameters.add(GetQueryTagValuesParams.DocumentCount.name(), true);
        aciParameters.add(GetQueryTagValuesParams.MaxValues.name(), parametricRequest.getMaxValues());
        aciParameters.add(GetQueryTagValuesParams.FieldName.name(),
                StringUtils.join(fieldNames.toArray(), ','));
        aciParameters.add(GetQueryTagValuesParams.Sort.name(), SortParam.DocumentCount.name());

        final GetQueryTagValuesResponseData responseData = contentAciService.executeAction(aciParameters,
                queryTagValuesResponseProcessor);
        final List<FlatField> fields = responseData.getField();
        results = new LinkedHashSet<>(fields.size());
        for (final FlatField field : fields) {
            final List<JAXBElement<? extends Serializable>> valueElements = field.getValueOrSubvalueOrValues();
            final LinkedHashSet<QueryTagCountInfo> values = new LinkedHashSet<>(valueElements.size());
            for (final JAXBElement<?> element : valueElements) {
                if (VALUE_NODE_NAME.equals(element.getName().getLocalPart())) {
                    final TagValue tagValue = (TagValue) element.getValue();
                    values.add(new QueryTagCountInfo(tagValue.getValue(), tagValue.getCount()));
                }
            }
            final String fieldName = getFieldNameFromPath(field.getName().get(0));
            if (!values.isEmpty()) {
                results.add(new QueryTagInfo(fieldName, values));
            }
        }
    }

    return results;
}

From source file:com.thistech.spotlink.engine.AbstractPlacementDecisionEngine.java

/**
 * Construct a list of Placements to best fill the PlacementOpportunity / PlacementControl from the supplied list
 * of PlacementDecisions//from   ww  w.  j av a  2  s  . com
 * @param placementRequest The PlacementRequest
 * @param ads The list of Ads
 * @return The Placements
 */
protected List<PlacementDecisionType> fillPlacementRequest(PlacementRequestType placementRequest,
        List<Ad> ads) {
    List<PlacementDecisionType> placementDecisions = new ArrayList<PlacementDecisionType>();
    for (JAXBElement<? extends PlacementOpportunityType> element : placementRequest.getPlacementOpportunity()) {
        PlacementOpportunityType placementOpportunity = element.getValue();
        placementDecisions.add(fillPlacementOpportunity(placementRequest, placementOpportunity, ads));
    }
    return placementDecisions;
}

From source file:edu.harvard.i2b2.crc.delegate.pdo.GetPDOTemplateHandler.java

/**
 * Perform operation for the given request using business class(ejb) and
 * return response/*from w w w  .  j a  v a 2s .c  o  m*/
 */
public BodyType execute() throws I2B2Exception {
    // call ejb and pass input object
    QueryProcessorUtil qpUtil = QueryProcessorUtil.getInstance();
    String responseString = null;
    BodyType bodyType = new BodyType();

    try {
        InputStream resourceAsStream = getClass().getResourceAsStream("pdo_template.xml");
        //.getContextClassLoader().getResourceAsStream(
        //      "pdo_template.xml");

        if (resourceAsStream == null) {
            log.debug("Unable to read pdo_template.xml, the inputstream is null");
        } else {
            log.debug("pdo_template.xml, the inputstream is not null");
        }
        // .currentThread()
        // .getContextClassLoader()
        // .getResourceAsStream(
        // );
        String pdoXmlContent = convertStreamToString(resourceAsStream);
        JAXBElement pdoJaxb = null;

        pdoJaxb = CRCJAXBUtil.getJAXBUtil().unMashallFromString(pdoXmlContent);

        PatientDataType patientDataType = (PatientDataType) pdoJaxb.getValue();

        //TODO removed EJBs
        //PdoQueryLocalHome pdoQueryLocalHome = qpUtil.getPdoQueryLocalHome();
        //PdoQueryLocal pdoQueryInfoLocal = pdoQueryLocalHome.create();
        PdoQueryBean query = new PdoQueryBean();
        List<ParamType> patientParamList = query.getPDOTemplate("patient_dimension", this.getDataSourceLookup(),
                false);
        patientDataType.getPatientSet().getPatient().get(0).getParam().clear();
        patientDataType.getPatientSet().getPatient().get(0).getParam().addAll(patientParamList);

        List<ParamType> visitParamList = query.getPDOTemplate("visit_dimension", this.getDataSourceLookup(),
                false);
        patientDataType.getEventSet().getEvent().get(0).getParam().clear();
        patientDataType.getEventSet().getEvent().get(0).getParam().addAll(visitParamList);

        PatientDataResponseType patientDataResponseType = new PatientDataResponseType();
        patientDataResponseType.setPatientData(patientDataType);
        edu.harvard.i2b2.crc.datavo.pdo.query.ObjectFactory objectFactory = new edu.harvard.i2b2.crc.datavo.pdo.query.ObjectFactory();

        bodyType.getAny().add(objectFactory.createResponse(patientDataResponseType));

    } catch (JAXBUtilException e) {
        log.error("", e);
        throw new I2B2Exception("", e);
    } catch (Exception e) {
        log.error("", e);
        throw new I2B2Exception("", e);
    }
    return bodyType;
}

From source file:org.jasig.portlet.announcements.Importer.java

private void importAnnouncements() {
    try {/*w ww . jav a  2  s.  c o m*/
        JAXBContext jc = JAXBContext.newInstance(Announcement.class);
        Unmarshaller unmarshaller = jc.createUnmarshaller();

        File[] files = dataDirectory.listFiles(new AnnouncementImportFileFilter());

        if (files == null) {
            errors.add("Directory " + dataDirectory + " is not a valid directory");
        } else {

            for (File f : files) {
                log.info("Processing file " + f.toString());
                StreamSource xml = new StreamSource(f.getAbsoluteFile());
                try {
                    JAXBElement<Announcement> je1 = unmarshaller.unmarshal(xml, Announcement.class);
                    Announcement announcement = je1.getValue();
                    if (StringUtils.isBlank(announcement.getTitle())) {
                        String msg = "Error parsing " + f.toString() + "; did not get valid record:\n"
                                + announcement.toString();
                        log.error(msg);
                        errors.add(msg);
                    } else if (announcement.getParent() == null
                            || StringUtils.isBlank(announcement.getParent().getTitle())) {
                        String msg = "Announcement in file " + f.toString()
                                + " does not reference a topic with a title";
                        log.error(msg);
                        errors.add(msg);
                    } else {
                        Topic topic = findTopicForAnnouncement(announcement);
                        announcement.setParent(topic);
                        announcementService.addOrSaveAnnouncement(announcement);
                        log.info("Successfully imported announcement '" + announcement.getTitle() + "'");
                    }
                } catch (ImportException e) {
                    log.error(e.getMessage());
                    errors.add(e.getMessage());
                } catch (JAXBException e) {
                    String msg = "JAXB exception " + e.getCause().getMessage() + " processing file "
                            + f.toString();
                    log.error(msg, e);
                    errors.add(msg + ". See stack trace");
                } catch (HibernateException e) {
                    String msg = "Hibernate exception " + e.getCause().getMessage() + " processing file "
                            + f.toString();
                    log.error(msg, e);
                    errors.add(msg + ". See stack trace");
                }
            }
        }
    } catch (JAXBException e) {
        String msg = "Fatal JAXBException in importAnnouncements - no Announcements imported";
        log.fatal(msg, e);
        errors.add(msg + ".  See stack trace");
    }
}

From source file:be.fedict.eid.pkira.contracts.EIDPKIRAContractsClient.java

/**
 * Unmarshals an XML from a reader.// w w  w.j a va 2  s .c  om
 * 
 * @param <T>
 *            the type of document that is expected.
 * @param reader
 *            the reader to get the document from.
 * @param clazz
 *            the type of object.
 * @return the unmarshalled object.
 * @throws XmlMarshallingException
 *             when this fails.
 */
@SuppressWarnings("unchecked")
public <T extends EIDPKIRAContractType> T unmarshal(Reader reader, Class<T> clazz)
        throws XmlMarshallingException {
    Object unmarshalled;
    try {
        unmarshalled = getUnmarshaller().unmarshal(reader);
    } catch (JAXBException e) {
        throw new XmlMarshallingException("Cannot unmarshal XML data.", e);
    }

    if (unmarshalled != null && unmarshalled instanceof JAXBElement<?>) {
        JAXBElement<?> jaxbElement = (JAXBElement<?>) unmarshalled;
        if (jaxbElement.getDeclaredType() == clazz) {
            return (T) jaxbElement.getValue();
        } else {
            throw new XmlMarshallingException("XML contains an invalid element: "
                    + jaxbElement.getDeclaredType().getSimpleName() + ". Expected " + clazz.getSimpleName());
        }
    }

    throw new XmlMarshallingException("XML did not contain a valid element.");
}

From source file:com.evolveum.midpoint.web.application.DescriptorLoader.java

public void loadData(MidPointApplication application) {
    LOGGER.info("Loading data from descriptor files.");

    String baseFileName = "/WEB-INF/descriptor.xml";
    String customFileName = "/WEB-INF/classes/descriptor.xml";

    try (InputStream baseInput = application.getServletContext().getResourceAsStream(baseFileName);
            InputStream customInput = application.getServletContext().getResourceAsStream(customFileName)) {
        if (baseInput == null) {
            LOGGER.error(//from   w ww.  j a  v a2  s  .  c  o m
                    "Couldn't find " + baseFileName + " file, can't load application menu and other stuff.");
        }

        JAXBContext context = JAXBContext.newInstance(ObjectFactory.class);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        JAXBElement<DescriptorType> element = (JAXBElement) unmarshaller.unmarshal(baseInput);
        DescriptorType descriptor = element.getValue();

        LOGGER.debug("Loading menu bar from " + baseFileName + " .");
        MenuType menu = descriptor.getMenu();
        Map<Integer, RootMenuItemType> rootMenuItems = new HashMap<>();
        mergeRootMenuItems(menu, rootMenuItems);

        DescriptorType customDescriptor = null;
        if (customInput != null) {
            element = (JAXBElement) unmarshaller.unmarshal(customInput);
            customDescriptor = element.getValue();
            mergeRootMenuItems(customDescriptor.getMenu(), rootMenuItems);
        }

        List<RootMenuItemType> sortedRootMenuItems = sortRootMenuItems(rootMenuItems);
        loadMenuBar(sortedRootMenuItems);

        scanPackagesForPages(descriptor.getPackagesToScan(), application);
        if (customDescriptor != null) {
            scanPackagesForPages(customDescriptor.getPackagesToScan(), application);
        }
    } catch (Exception ex) {
        LoggingUtils.logException(LOGGER, "Couldn't process application descriptor", ex);
    }
}

From source file:io.mapzone.arena.csw.CswRequest.java

/**
 * Unmarshall the given object type from the given stream.
 *//* w w  w.j  av a2s.c  om*/
protected <T> T readObject(InputStream in, Class<T> type) throws JAXBException {
    Unmarshaller unmarshaller = jaxbContext.get().createUnmarshaller();
    JAXBElement<T> elm = unmarshaller.unmarshal(new StreamSource(in), type);
    return elm.getValue();
}

From source file:org.wallerlab.yoink.molecular.service.translator.MolecularSystemTranslator.java

private void init(JAXBElement<Cml> cml) {
    moleculeIndexCounter = 0;/*from   www. ja  va 2  s  . c  o m*/
    atomIndexCounter = 0;
    this.cml = cml;
    this.molecules = new ArrayList<Molecule>();
    this.cmlMolecularSystem = cml.getValue();
}

From source file:com.netflix.imfutility.cpl._2013.Cpl2013ContextBuilderStrategy.java

@Override
protected void buildFromCpl() {
    // 1. get a composition edit rate (it's used if no specific edit rate is specified for a segment).
    this.compositionEditRate = ConversionHelper.parseEditRate(cpl2013.getEditRate());

    // 2. go through all segments and all sequences and build segment, sequence and resource contexts.
    for (SegmentType segment : cpl2013.getSegmentList().getSegment()) {
        this.currentSegmentUuid = SegmentUUID.create(segment.getId());

        contextProvider.getSegmentContext().initSegment(currentSegmentUuid);

        for (Object anySeqJaxb : segment.getSequenceList().getAny()) {
            if (!(anySeqJaxb instanceof JAXBElement)) {
                throw new ConversionException(
                        String.format("Could not understand a sequence '%s'", anySeqJaxb.toString()));
            }/*from   w  w  w . ja  v  a2s.c  om*/

            JAXBElement jaxbElement = (JAXBElement) (anySeqJaxb);
            Object anySeq = jaxbElement.getValue();

            SequenceTypeCpl currentSequenceTypeCpl = SequenceTypeCpl
                    .fromName(jaxbElement.getName().getLocalPart());
            if ((currentSequenceTypeCpl != null) && (anySeq instanceof SequenceType)) {
                this.currentSequence = (SequenceType) anySeq;
                this.currentSequenceType = currentSequenceTypeCpl.toSequenceType();
                this.currentSequenceUuid = SequenceUUID.create(currentSequence.getTrackId());
                processSequence();
            }
        }
    }
}

From source file:com.netflix.imfutility.cpl._2016.Cpl2016ContextBuilderStrategy.java

@Override
protected void buildFromCpl() {
    // 1. get a composition edit rate (it's used if no specific edit rate is specified for a segment).
    this.compositionEditRate = ConversionHelper.parseEditRate(cpl2016.getEditRate());

    // 2. go through all segments and all sequences and build segment, sequence and resource contexts.
    for (SegmentType segment : cpl2016.getSegmentList().getSegment()) {
        this.currentSegmentUuid = SegmentUUID.create(segment.getId());

        contextProvider.getSegmentContext().initSegment(currentSegmentUuid);

        for (Object anySeqJaxb : segment.getSequenceList().getAny()) {
            if (!(anySeqJaxb instanceof JAXBElement)) {
                throw new ConversionException(
                        String.format("Could not understand a sequence '%s'", anySeqJaxb.toString()));
            }/*  w w  w.  j  a va 2  s . com*/

            JAXBElement jaxbElement = (JAXBElement) (anySeqJaxb);
            Object anySeq = jaxbElement.getValue();

            SequenceTypeCpl currentSequenceTypeCpl = SequenceTypeCpl
                    .fromName(jaxbElement.getName().getLocalPart());
            if ((currentSequenceTypeCpl != null) && (anySeq instanceof SequenceType)) {
                this.currentSequence = (SequenceType) anySeq;
                this.currentSequenceType = currentSequenceTypeCpl.toSequenceType();
                this.currentSequenceUuid = SequenceUUID.create(currentSequence.getTrackId());
                processSequence();
            }
        }
    }
}