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:org.jasig.portlet.announcements.Importer.java

private void importTopics() {
    try {//from   w ww .  j a  v a  2  s . c om
        JAXBContext jc = JAXBContext.newInstance(Topic.class);
        Unmarshaller unmarshaller = jc.createUnmarshaller();

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

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

            for (File f : files) {
                log.info("Processing file " + f.toString());
                StreamSource xmlFile = new StreamSource(f.getAbsoluteFile());
                try {
                    JAXBElement<Topic> je1 = unmarshaller.unmarshal(xmlFile, Topic.class);
                    Topic topic = je1.getValue();

                    if (StringUtils.isBlank(topic.getTitle())) {
                        String msg = "Error parsing file " + f.toString() + "; did not get valid record:\n"
                                + topic.toString();
                        log.error(msg);
                        errors.add(msg);
                    } else {
                        announcementService.addOrSaveTopic(topic);
                        log.info("Successfully imported topic '" + topic.getTitle() + "'");
                    }
                } 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 importTopics - no topics imported";
        log.fatal(msg, e);
        errors.add(msg + ".  See stack trace");
    }
}

From source file:org.socialhistoryservices.pid.ws.PidServiceEndPoint.java

@PayloadRoot(localPart = "UpdatePidRequest", namespace = namespace)
@ResponsePayload/*from   w  w w .  j a va  2s  .c  o  m*/
public JAXBElement<UpdatePidResponseType> updatePid(
        @RequestPayload JAXBElement<UpdatePidRequestType> requestElement) throws IOException, HandleException {
    final PidType handle = normalize(requestElement.getValue().getHandle());
    final PidType pidType = pidResourceService.updatePid(handle);
    final UpdatePidResponseType response = objectFactory.createUpdatePidResponseType();
    response.setHandle(pidType);
    return objectFactory.createUpdatePidResponse(response);
}

From source file:com.agimatec.validation.jsr303.xml.ValidationParser.java

private ValidationConfigType parseXmlConfig() {
    try {/*w w  w.  java  2  s  .c o m*/
        InputStream inputStream = getInputStream(validationXmlFile);
        if (inputStream == null) {
            if (log.isDebugEnabled())
                log.debug("No " + validationXmlFile + " found. Using annotation based configuration only.");
            return null;
        }

        if (log.isDebugEnabled())
            log.debug(validationXmlFile + " found.");

        Schema schema = getSchema();
        JAXBContext jc = JAXBContext.newInstance(ValidationConfigType.class);
        Unmarshaller unmarshaller = jc.createUnmarshaller();
        unmarshaller.setSchema(schema);
        StreamSource stream = new StreamSource(inputStream);
        JAXBElement<ValidationConfigType> root = unmarshaller.unmarshal(stream, ValidationConfigType.class);
        return root.getValue();
    } catch (JAXBException e) {
        throw new ValidationException("Unable to parse " + validationXmlFile, e);
    } catch (IOException e) {
        throw new ValidationException("Unable to parse " + validationXmlFile, e);
    }
}

From source file:org.socialhistoryservices.pid.ws.PidServiceEndPoint.java

@PayloadRoot(localPart = "GetPidRequest", namespace = namespace)
@ResponsePayload/*from  w w  w  .  j  a va  2  s.  co  m*/
public JAXBElement<GetPidResponseType> getPid(@RequestPayload JAXBElement<GetPidRequestType> requestElement)
        throws IOException, HandleException {
    final String pid = normalize(requestElement.getValue().getPid(), true);
    final PidType handle = pidResourceService.getPid(pid);
    final GetPidResponseType response = objectFactory.createGetPidResponseType();
    response.setHandle(handle);
    return objectFactory.createGetPidResponse(response);
}

From source file:edu.harvard.i2b2.pm.ws.VersionMessage.java

/**
 * The constructor/*from w ww  . j  av a  2 s.  c om*/
 */
public VersionMessage(String requestPdo) throws I2B2Exception {
    jaxbUtil = new JAXBUtil(JAXBConstant.DEFAULT_PACKAGE_NAME);

    try {
        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(requestPdo);

        if (jaxbElement == null) {
            throw new I2B2Exception("Null value from unmashall for PDO xml : " + requestPdo);
        }

        this.reqMessageType = (RequestMessageType) jaxbElement.getValue();

    } catch (JAXBUtilException e) {
        e.printStackTrace();
        log.error(e.getMessage(), e);
        throw new I2B2Exception("Umashaller error: " + e.getMessage() + requestPdo, e);
    }
}

From source file:be.agiv.security.handler.WSAddressingHandler.java

private void handleInboundMessage(SOAPMessageContext context) {
    String messageId = (String) context.get(MESSAGE_ID_CONTEXT_ATTRIBUTE);
    LOG.debug("checking RelatesTo message id: " + messageId);
    Object[] headers = context.getHeaders(new QName(WSConstants.WS_ADDR_NAMESPACE, "RelatesTo"),
            this.jaxbContext, false);
    for (Object headerObject : headers) {
        JAXBElement<RelatesToType> element = (JAXBElement<RelatesToType>) headerObject;
        RelatesToType relatesTo = element.getValue();
        if (false == messageId.equals(relatesTo.getValue())) {
            throw new ProtocolException("incorrect a:RelatesTo value");
        }/*www .  j a v a 2  s. c om*/
    }
}

From source file:org.socialhistoryservices.pid.ws.PidServiceEndPoint.java

@PayloadRoot(localPart = "GetQuickPidRequest", namespace = namespace)
@ResponsePayload/*w w w.  j av a2  s  . c  om*/
public JAXBElement<GetQuickPidResponseType> quickPid(
        @RequestPayload JAXBElement<GetQuickPidRequestType> requestElement)
        throws IOException, HandleException {
    final String na = normalize(requestElement.getValue().getNa(), true);
    final String lid = normalize(requestElement.getValue().getLocalIdentifier(), true);
    final String resolveUrl = normalize(requestElement.getValue().getResolveUrl(), false);
    final PidType handle = pidResourceService.createHopePid(na, lid, resolveUrl);
    final GetQuickPidResponseType response = objectFactory.createGetQuickPidResponseType();
    response.setHandle(handle);
    return objectFactory.createGetQuickPidResponse(response);
}

From source file:edu.harvard.i2b2.ontology.ws.RequestDataMessage.java

/**
 * The constructor/* w  w  w  .j  a va2  s.  c om*/
 */
public RequestDataMessage(String requestVdo) throws I2B2Exception {
    try {
        JAXBElement jaxbElement = OntologyJAXBUtil.getJAXBUtil().unMashallFromString(requestVdo);

        if (jaxbElement == null) {
            throw new I2B2Exception("Null value from unmarshall for VDO xml : " + requestVdo);
        }

        this.reqMessageType = (RequestMessageType) jaxbElement.getValue();
    } catch (JAXBUtilException e) {
        log.error(e.getMessage(), e);
        throw new I2B2Exception("Umarshaller error: " + e.getMessage() + requestVdo, e);
    }
}

From source file:com.rabidgremlin.legalbeagle.util.HttpHelper.java

public Model getPom(MavenArtifact mavenArtifact) throws Exception {
    String requestUrl = "http://search.maven.org/remotecontent?filepath="
            + mavenArtifact.getGroupId().replaceAll("\\.", "/") + "/" + mavenArtifact.getArtifactId() + "/"
            + mavenArtifact.getVersion() + "/" + mavenArtifact.getArtifactId() + "-"
            + mavenArtifact.getVersion() + ".pom";

    // System.out.println("url:" + requestUrl);

    // URL url = new
    // URL("http://search.maven.org/remotecontent?filepath=com/jolira/guice/3.0.0/guice-3.0.0.pom");

    // URL url = new
    // URL("http://repo1.maven.org/maven2/org/eclipse/jetty/jetty-webapp/7.3.0.v20110203/jetty-webapp-7.3.0.v20110203.pom");

    JAXBElement<Model> projectElem = unMarshallPom(executeGet(requestUrl).returnContent().asString());

    // System.out.println(projectElem.toString());
    // System.out.println(projectElem.getName());

    return projectElem.getValue();
}

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

@Override
public Set<QueryTagInfo> getAllParametricValues(final IdolParametricRequest idolParametricRequest)
        throws AciErrorException {
    final Collection<String> fieldNames = new HashSet<>();
    fieldNames.addAll(idolParametricRequest.getFieldNames());
    if (fieldNames.isEmpty()) {
        fieldNames.addAll(getTagNames());
    }//  w  ww.  j  a va  2 s . co  m

    final Set<QueryTagInfo> results;
    if (fieldNames.isEmpty()) {
        results = Collections.emptySet();
    } else {
        final AciParameters aciParameters = new AciParameters(TagActions.GetQueryTagValues.name());
        aciParameters.add(QueryParams.Combine.name(), CombineParam.Simple);
        aciParameters.add(QueryParams.Text.name(), idolParametricRequest.getQueryText());
        aciParameters.add(QueryParams.FieldText.name(), idolParametricRequest.getFieldText());
        aciParameters.add(QueryParams.DatabaseMatch.name(),
                new Databases(idolParametricRequest.getDatabases()));
        aciParameters.add(QueryParams.MinDate.name(), formatDate(idolParametricRequest.getMinDate()));
        aciParameters.add(QueryParams.MaxDate.name(), formatDate(idolParametricRequest.getMaxDate()));
        aciParameters.add(QueryParams.AnyLanguage.name(), true);
        aciParameters.add(GetQueryTagValuesParams.DocumentCount.name(), true);
        aciParameters.add(GetQueryTagValuesParams.MaxValues.name(), MAX_VALUES);
        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;
}