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:io.mapzone.controller.catalog.csw.FilterParser.java

protected void handleComparison(JAXBElement<? extends ComparisonOpsType> jaxb) throws Exception {
    if (jaxb != null && jaxb.getValue() != null) {
        ComparisonOpsType op = jaxb.getValue();

        // BinaryComparison
        if (op instanceof BinaryComparisonOpType) {
            BinaryComparisonOpType binary = (BinaryComparisonOpType) op;
            binary.getExpression().stream().forEach(expr -> log.info("EXPRESSION: " + expr.getValue()));

            // FIXME super hack; PropertyIsEqulTo is unmarshalled as BinaryComparison; I don't know
            // where to get op type from
            PropertyNameType propName = (PropertyNameType) binary.getExpression().get(0).getValue();
            LiteralType literal = (LiteralType) binary.getExpression().get(1).getValue();
            handleComparison((String) propName.getContent().get(0), (String) literal.getContent().get(0),
                    ComparisonOperatorType.EQUAL_TO);
        }//from  www  .j a  v a 2  s .  co m

        // PropertyIsLike
        else if (op instanceof PropertyIsLikeType) {
            PropertyIsLikeType isLike = (PropertyIsLikeType) op;
            if (!"*".equals(isLike.getWildCard())) {
                throw new UnsupportedOperationException("Wildcard other than '*' is not supported.");
            }
            String propName = (String) isLike.getPropertyName().getContent().get(0);
            String literal = (String) isLike.getLiteral().getContent().get(0);
            handleComparison(propName, literal, ComparisonOperatorType.LIKE);
        }
        // unhandled
        else {
            throw new UnsupportedOperationException("Unhandled Comparison type: " + op.getClass().getName());
        }
    }
}

From source file:com.evolveum.midpoint.model.impl.dataModel.dot.DotMappingRelation.java

@Override
public String getNodeStyleAttributes() {
    ExpressionType expression = getMapping().getExpression();
    if (expression == null || expression.getExpressionEvaluator().isEmpty()) {
        return "";
    }// w  w  w  .j  a va  2 s  .  co m
    JAXBElement<?> evalElement = expression.getExpressionEvaluator().get(0);
    Object eval = evalElement.getValue();
    if (QNameUtil.match(evalElement.getName(), SchemaConstants.C_VALUE)) {
        return "style=filled, fillcolor=ivory";
    } else if (eval instanceof AsIsExpressionEvaluatorType) {
        return "";
    } else if (eval instanceof ScriptExpressionEvaluatorType) {
        return "style=filled, fillcolor=wheat";
    } else {
        return "";
    }
}

From source file:com.evolveum.midpoint.model.impl.dataModel.dot.DotMappingRelation.java

private String getTooltipString() {
    ExpressionType expression = getMapping().getExpression();
    if (expression == null || expression.getExpressionEvaluator().isEmpty()) {
        return "asIs";
    }/* ww w  . ja v  a2 s.c o m*/
    JAXBElement<?> evalElement = expression.getExpressionEvaluator().get(0);
    Object eval = evalElement.getValue();
    if (QNameUtil.match(evalElement.getName(), SchemaConstants.C_VALUE)) {
        return getStringConstant(eval);
    } else if (eval instanceof AsIsExpressionEvaluatorType) {
        return "asIs";
    } else if (eval instanceof ScriptExpressionEvaluatorType) {
        return ((ScriptExpressionEvaluatorType) eval).getCode();
    } else if (eval instanceof ItemPathType) {
        return String.valueOf(((ItemPathType) eval).getItemPath());
    } else {
        return "";
    }
}

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

private void parseParameterValue(Map<JobParameter, Object> parameters, JAXBElement elementJAXB) {
    Parameter cmlParameter = (Parameter) elementJAXB.getValue();
    String name = cmlParameter.getName().toUpperCase();
    JobParameter jobParameter = JobParameter.valueOf(name);
    String value = cmlParameter.getValue();
    switch (jobParameter) {
    case REGION_CUBE:
        parameters.put(jobParameter, Region.Name.valueOf(value));
        break;/*from  w ww  . ja  v  a 2  s . co  m*/
    case NUMBER_QM:
    case NUMBER_PARTITION:
    case NUMBER_BUFFER:
        parameters.put(jobParameter, Integer.parseInt(value));
        break;
    case DORI_STEPSIZE:
        double[] doriCubeStepSize = new double[3];
        String[] splited = value.split("\\s+");
        doriCubeStepSize[0] = Double.parseDouble(splited[0]);
        doriCubeStepSize[1] = Double.parseDouble(splited[1]);
        doriCubeStepSize[2] = Double.parseDouble(splited[2]);
        parameters.put(jobParameter, doriCubeStepSize);
        break;
    case SEDD_STEPSIZE:
        double[] seddCubeStepSize = new double[3];
        String[] splitedSize = value.split("\\s+");
        seddCubeStepSize[0] = Double.parseDouble(splitedSize[0]);
        seddCubeStepSize[1] = Double.parseDouble(splitedSize[1]);
        seddCubeStepSize[2] = Double.parseDouble(splitedSize[2]);
        parameters.put(jobParameter, seddCubeStepSize);
        break;
    case SMOOTHNER:
        parameters.put(jobParameter, Smoothner.Type.valueOf(value));
        break;
    case PARTITIONER:
        parameters.put(jobParameter, Partitioner.Type.valueOf(value));
        break;
    case JOB_NAME:
        //case INPUT_FOLDER:
    case OUTPUT_FOLDER:
        parameters.put(jobParameter, value);
        break;
    case DISTANCE_BUFFER:
    case DISTANCE_QM:
    case DISTANCE_S_QM_IN:
    case DISTANCE_T_QM_IN:
    case DISTANCE_S_QM_OUT:
    case DISTANCE_T_QM_OUT:
    case DISTANCE_S_MM_IN:
    case DISTANCE_T_MM_IN:
    case DISTANCE_S_MM_OUT:
    case DISTANCE_T_MM_OUT:
        parameters.put(jobParameter, Double.parseDouble(value) * unitConverterType.value());
        break;
    default:
        parameters.put(jobParameter, Double.parseDouble(value));
    }
}

From source file:com.samples.platform.service.iss.tech.support.GetForwardedReferenceDataOperation.java

/**
 * @param message/*from   w ww  .  j  a v a 2s  . com*/
 *            the {@link JAXBElement} containing a
 *            {@link GetForwardedReferenceDataRequestType}.
 * @return the {@link JAXBElement} with a
 *         {@link GetForwardedReferenceDataResponseType}.
 */
@InsightEndPoint
@ServiceActivator
public final JAXBElement<GetForwardedReferenceDataResponseType> getForwardedReferenceData(
        final JAXBElement<GetForwardedReferenceDataRequestType> message) {
    this.logger.debug("+getForwardedReferenceData");
    GetForwardedReferenceDataRequestType request = message.getValue();
    GetForwardedReferenceDataResponseType response = this.of.createGetForwardedReferenceDataResponseType();
    long start = System.currentTimeMillis();
    try {
        GetReferenceDataRequestType getReferenceDataRequestType = this.commonOf
                .createGetReferenceDataRequestType();
        getReferenceDataRequestType.setCriteria(request.getCriteria());
        JAXBElement<GetReferenceDataResponseType> forwardResponse = this.getAggregatedReferenceData
                .invoke(this.commonOf.createGetReferenceDataRequest(getReferenceDataRequestType));
        if (forwardResponse != null && forwardResponse.getValue() != null) {
            response.getFailure().addAll(forwardResponse.getValue().getFailure());
            response.getReferenceData().addAll(forwardResponse.getValue().getReferenceData());
        } else {
            throw new IllegalStateException("Forward response empty!");
        }
    } catch (Throwable e) {
        /* Add a not covered error to the response. */
        this.logger.error(e.getMessage(), e);
    } finally {
        this.logger.debug(" getForwardedReferenceData duration {}", DateUtil.getDuration(start));
        this.logger.debug("-getForwardedReferenceData #{}, #f{}", response/* .get() */ != null ? 1 : 0,
                response.getFailure().size());
    }
    return this.of.createGetForwardedReferenceDataResponse(response);
}

From source file:org.gofleet.openls.GeoCodingTest.java

@Test
public void testGeocoding() throws FileNotFoundException, JAXBException, XMLStreamException,
        FactoryConfigurationError, SAXException {
    XLSType object = openLS.openLS(Utils.convertFile2XLSType("/geocodingRequest.xml", XLSType.class));

    XLSType xls = (XLSType) object;/*from w w  w  . j  a  v a2 s .c o  m*/

    assertNotNull("The response is null", xls);

    assertNotNull("The body is null.", xls.getBody());

    List<JAXBElement<? extends AbstractBodyType>> body = xls.getBody();

    assertNotNull("The body is null! How? We have just checked it!", body);

    for (JAXBElement<? extends AbstractBodyType> body_ : body) {
        AbstractBodyType o = body_.getValue();

        assertTrue("This is no response!", o instanceof ResponseType);

        ResponseType response = (ResponseType) o;

        assertNotNull("The contents of the body are null? (ResponseType)", response);

        assertEquals("I should have only one response", response.getNumberOfResponses().intValue(), 1);

        assertNotNull("Response parameters are null!", response.getResponseParameters());

        AbstractResponseParametersType arpt = response.getResponseParameters().getValue();

        assertTrue("The response is not a geocode response", arpt instanceof GeocodeResponseType);

        GeocodeResponseType grrt = (GeocodeResponseType) arpt;
        for (GeocodeResponseListType list : grrt.getGeocodeResponseList()) {
            List<GeocodedAddressType> arrayAddress = list.getGeocodedAddress();
            assertTrue(arrayAddress.size() > 0);
            for (GeocodedAddressType addressType : arrayAddress) {
                AddressType paramEval = addressType.getAddress();
                assertNotNull(paramEval.getCountryCode());
                assertNotNull(paramEval.getStreetAddress());
                assertNotNull(paramEval.getPlace());
            }
        }
    }
}

From source file:com.evolveum.midpoint.model.impl.dataModel.dot.DotMappingRelation.java

@Nullable
private String getLabel(String defaultLabel, boolean showConstant) {
    ExpressionType expression = getMapping().getExpression();
    if (expression == null || expression.getExpressionEvaluator().isEmpty()) {
        return defaultLabel;
    }//  w w w  .  j  av  a 2s. c om
    if (expression.getExpressionEvaluator().size() > 1) {
        return "> 1 evaluator"; // TODO multivalues
    }
    JAXBElement<?> evalElement = expression.getExpressionEvaluator().get(0);
    Object eval = evalElement.getValue();
    if (QNameUtil.match(evalElement.getName(), SchemaConstants.C_VALUE)) {
        if (showConstant) {
            String str = getStringConstant(eval);
            return "\'" + StringUtils.abbreviate(str, MAX_CONSTANT_WIDTH) + "\'";
        } else {
            return "constant";
        }
    } else if (eval instanceof AsIsExpressionEvaluatorType) {
        return defaultLabel;
    } else if (eval instanceof ScriptExpressionEvaluatorType) {
        ScriptExpressionEvaluatorType script = (ScriptExpressionEvaluatorType) eval;
        if (script.getLanguage() == null) {
            return "groovy";
        } else {
            return StringUtils.substringAfter(script.getLanguage(), "#");
        }
    } else {
        return evalElement.getName().getLocalPart();
    }
}

From source file:com.samples.platform.service.iss.tech.support.GetAggregatedReferenceDataOperation.java

/**
 * @param message//from   ww w . jav  a  2 s . com
 *            the {@link JAXBElement} containing a
 *            {@link GetAggregatedReferenceDataRequestType}.
 * @return the {@link JAXBElement} with a
 *         {@link GetAggregatedReferenceDataResponseType}.
 */
@InsightEndPoint
@ServiceActivator
public final JAXBElement<GetAggregatedReferenceDataResponseType> getAggregatedReferenceData(
        final JAXBElement<GetAggregatedReferenceDataRequestType> message) {
    this.logger.debug("+getAggregatedReferenceData");
    GetAggregatedReferenceDataRequestType request = message.getValue();
    GetAggregatedReferenceDataResponseType response = this.of.createGetAggregatedReferenceDataResponseType();
    long start = System.currentTimeMillis();
    try {
        GetReferenceDataRequestType getReferenceDataRequestType = this.commonOf
                .createGetReferenceDataRequestType();
        getReferenceDataRequestType.setCriteria(request.getCriteria());
        JAXBElement<GetReferenceDataResponseType> aggregateResponse = this.getAggregatedReferenceData
                .invoke(this.commonOf.createGetReferenceDataRequest(getReferenceDataRequestType));
        if (aggregateResponse != null && aggregateResponse.getValue() != null) {
            response.getFailure().addAll(aggregateResponse.getValue().getFailure());
            response.getReferenceData().addAll(aggregateResponse.getValue().getReferenceData());
        } else {
            throw new IllegalStateException("Aggregated response empty!");
        }
    } catch (Throwable e) {
        /* Add a not covered error to the response. */
        this.logger.error(e.getMessage(), e);
    } finally {
        this.logger.debug(" getAggregatedReferenceData duration {}", DateUtil.getDuration(start));
        this.logger.debug("-getAggregatedReferenceData #{}, #f{}", response/* .get() */ != null ? 1 : 0,
                response.getFailure().size());
    }
    return this.of.createGetAggregatedReferenceDataResponse(response);
}

From source file:org.gofleet.openls.GeoCodingTest.java

@Test
public void testReverseGeocoding() throws FileNotFoundException, JAXBException, XMLStreamException,
        FactoryConfigurationError, SAXException {
    XLSType xls = openLS.openLS(Utils.convertFile2XLSType("/reverseGeocoding.xml", XLSType.class));

    assertNotNull("The response is null", xls);

    assertNotNull("The body is null.", xls.getBody());

    List<JAXBElement<? extends AbstractBodyType>> body = xls.getBody();

    assertNotNull("The body is null! How? We have just checked it!", body);

    assertEquals("The body should have one single response", body.size(), 1);

    for (JAXBElement<? extends AbstractBodyType> body_ : body) {
        AbstractBodyType o = body_.getValue();

        assertTrue("This is no response!", o instanceof ResponseType);

        ResponseType response = (ResponseType) o;

        assertNotNull("The contents of the body are null? (ResponseType)", response);

        assertEquals("I should have only one response", response.getNumberOfResponses().intValue(), 1);

        assertNotNull("Response parameters are null!", response.getResponseParameters());

        AbstractResponseParametersType arpt = response.getResponseParameters().getValue();

        assertNotNull(arpt);/*from   w w w . j a  v a 2 s . c  o  m*/
        assertTrue("The response is not a geocode response", arpt instanceof ReverseGeocodeResponseType);

        ReverseGeocodeResponseType res = (ReverseGeocodeResponseType) arpt;

        List<ReverseGeocodedLocationType> res_array = res.getReverseGeocodedLocation();
        assertNotNull(res_array);
        assertTrue(res_array.size() > 0);
        for (ReverseGeocodedLocationType locationType : res_array) {
            AddressType addressRes = locationType.getAddress();
            assertNotNull(addressRes.getCountryCode());
            assertNotNull(addressRes.getStreetAddress());
            assertNotNull(addressRes.getStreetAddress().getStreet());
            assertEquals(addressRes.getStreetAddress().getStreet().size(), 1);
        }
    }
}

From source file:org.jasig.portlet.degreeprogress.dao.mock.MockDegreeProgressDaoImpl.java

@Override
public void afterPropertiesSet() throws Exception {
    try {// w ww  . j a  va 2 s . c o  m
        JAXBContext jaxbContext = JAXBContext
                .newInstance(org.jasig.portlet.degreeprogress.model.xml.DegreeProgressReport.class);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        this.report = (DegreeProgressReport) unmarshaller.unmarshal(mockData.getInputStream());

        for (DegreeRequirementSection section : report.getDegreeRequirementSections()) {
            for (JAXBElement<? extends GeneralRequirementType> requirement : section.getGeneralRequirements()) {
                GeneralRequirementType req = requirement.getValue();
                if (req instanceof GpaRequirement) {
                    section.setRequiredGpa(((GpaRequirement) req).getRequiredGpa());
                }
            }

            for (CourseRequirement req : section.getCourseRequirements()) {
                for (Course course : req.getCourses()) {
                    StudentCourseRegistration registration = new StudentCourseRegistration();
                    registration.setCredits(course.getCredits());
                    registration.setSource(course.getSource());
                    registration.setSemester(course.getSemester());
                    registration.setCourse(course);

                    Grade grade = new Grade();
                    grade.setCode(course.getGrade().getCode());
                    registration.setGrade(grade);

                    req.getRegistrations().add(registration);
                }
            }
            this.report.addSection(section);
        }
    } catch (IOException e) {
        log.error("Failed to read mock data", e);
    } catch (JAXBException e) {
        log.error("Failed to unmarshall mock data", e);
    }
}