Example usage for javax.xml.bind JAXBElement JAXBElement

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

Introduction

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

Prototype

public JAXBElement(QName name, Class<T> declaredType, T value) 

Source Link

Document

Construct an xml element instance.

Usage

From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswEndpointTest.java

private void verifyMarshalResponse(TransactionResponseType response, String contextPath, QName qName) {
    // Verify the response will marshal
    try {//from w  w  w  .  j  a  va 2s. com
        JAXBContext context = JAXBContext.newInstance(contextPath);
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        StringWriter sw = new StringWriter();

        JAXBElement<TransactionResponseType> wrappedResponse = new JAXBElement<>(qName,
                TransactionResponseType.class, response);

        marshaller.marshal(wrappedResponse, sw);

        LOGGER.info("Response: {}", sw.toString());

    } catch (JAXBException e) {
        fail("Could not marshal message, Error: " + e.getMessage());
    }
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswEndpointTest.java

/**
 * Creates default GetRecordsType POST request, with no sections specified
 *
 * @return Vanilla valid GetRecordsType object
 *///  w  w w  .j  a v a  2s  .c om
private GetRecordsType createDefaultPostRecordsRequest() {
    GetRecordsType grr = new GetRecordsType();

    grr.setOutputFormat(CswConstants.OUTPUT_FORMAT_XML);
    grr.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);

    QueryType query = new QueryType();
    List<QName> typeNames = new ArrayList<>();
    typeNames.add(new QName(CswConstants.CSW_OUTPUT_SCHEMA, VALID_TYPE, VALID_PREFIX));

    query.setTypeNames(typeNames);

    JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query);
    grr.setAbstractQuery(jaxbQuery);
    return grr;
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest.java

@SuppressWarnings("unchecked")
@Test//  www. jav a 2  s . co  m
public void testPostGetRecordsDistributedSearchSpecificSources()
        throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException {
    GetRecordsType grr = createDefaultPostRecordsRequest();

    DistributedSearchType distributedSearch = new DistributedSearchType();
    distributedSearch.setHopCount(BigInteger.TEN);

    grr.setDistributedSearch(distributedSearch);

    QueryType query = new QueryType();
    List<QName> typeNames = new ArrayList<QName>();
    typeNames.add(new QName(CswConstants.CSW_OUTPUT_SCHEMA, VALID_TYPE, VALID_PREFIX));

    query.setTypeNames(typeNames);
    QueryConstraintType constraint = new QueryConstraintType();

    constraint.setCqlText(CQL_FEDERATED_QUERY);

    query.setConstraint(constraint);

    JAXBElement<QueryType> jaxbQuery = new JAXBElement<QueryType>(cswQnameOutPutSchema, QueryType.class, query);
    grr.setAbstractQuery(jaxbQuery);

    QueryRequest queryRequest = queryFactory.getQuery(grr);
    assertThat(queryRequest.isEnterprise(), is(false));
    assertThat(queryRequest.getSourceIds(), contains("source1"));
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest.java

@Test
public void testPostGetRecordsContextualCQLQuery()
        throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException {
    GetRecordsType grr = createDefaultPostRecordsRequest();

    QueryType query = new QueryType();
    List<QName> typeNames = new ArrayList<QName>();
    typeNames.add(new QName(CswConstants.CSW_OUTPUT_SCHEMA, VALID_TYPE, VALID_PREFIX));
    query.setTypeNames(typeNames);/*from ww  w . j a  v  a  2  s  .c  om*/
    QueryConstraintType constraint = new QueryConstraintType();
    constraint.setCqlText(CQL_CONTEXTUAL_LIKE_QUERY);

    query.setConstraint(constraint);
    JAXBElement<QueryType> jaxbQuery = new JAXBElement<QueryType>(cswQnameOutPutSchema, QueryType.class, query);

    grr.setAbstractQuery(jaxbQuery);

    QueryRequest queryRequest = queryFactory.getQuery(grr);
    QueryImpl frameworkQuery = (QueryImpl) queryRequest.getQuery();
    assertThat(frameworkQuery.getFilter(), instanceOf(PropertyIsLike.class));
    PropertyIsLike like = (PropertyIsLike) frameworkQuery.getFilter();
    assertThat(like.getLiteral(), is(CQL_CONTEXTUAL_PATTERN));
    assertThat(((AttributeExpressionImpl) like.getExpression()).getPropertyName(),
            is(CQL_FRAMEWORK_TEST_ATTRIBUTE));
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest.java

@Test
public void testPostGetRecordsValidSort()
        throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException {
    GetRecordsType grr = createDefaultPostRecordsRequest();

    grr.setResultType(ResultType.RESULTS);
    QueryType query = new QueryType();

    SortByType incomingSort = new SortByType();
    SortPropertyType propType = new SortPropertyType();
    PropertyNameType propName = new PropertyNameType();
    propName.setContent(Arrays.asList((Object) TITLE_TEST_ATTRIBUTE));
    propType.setPropertyName(propName);/*from  www.j a  v  a  2  s.  c  o m*/
    incomingSort.getSortProperty().add(propType);
    query.setSortBy(incomingSort);

    JAXBElement<QueryType> jaxbQuery = new JAXBElement<QueryType>(cswQnameOutPutSchema, QueryType.class, query);

    grr.setAbstractQuery(jaxbQuery);

    QueryRequest queryRequest = queryFactory.getQuery(grr);

    SortBy resultSort = queryRequest.getQuery().getSortBy();

    assertThat(resultSort.getPropertyName().getPropertyName(), is(CQL_FRAMEWORK_TEST_ATTRIBUTE));
    assertThat(resultSort.getSortOrder(), is(SortOrder.ASCENDING));
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest.java

/**
 * Runs a binary Spatial CQL Query, verifying that the right filter class is generated based on CQL
 *
 * @param clz Class of filter to generate
 * @param cql CQL Query String//from w  ww.j a  v  a  2  s. c o  m
 * @throws UnsupportedQueryException
 * @throws SourceUnavailableException
 * @throws FederationException
 * @throws CswException
 */
private <N extends BinarySpatialOperator> void cqlSpatialQuery(Class<N> clz, String cql)
        throws UnsupportedQueryException, SourceUnavailableException, FederationException, CswException {
    GetRecordsType grr = createDefaultPostRecordsRequest();

    QueryType query = new QueryType();
    List<QName> typeNames = new ArrayList<QName>();
    typeNames.add(new QName(CswConstants.CSW_OUTPUT_SCHEMA, VALID_TYPE, VALID_PREFIX));
    query.setTypeNames(typeNames);
    QueryConstraintType constraint = new QueryConstraintType();
    constraint.setCqlText(cql);

    query.setConstraint(constraint);
    JAXBElement<QueryType> jaxbQuery = new JAXBElement<QueryType>(cswQnameOutPutSchema, QueryType.class, query);

    grr.setAbstractQuery(jaxbQuery);

    QueryImpl frameworkQuery = (QueryImpl) queryFactory.getQuery(grr).getQuery();
    assertThat(frameworkQuery.getFilter(), instanceOf(clz));
    @SuppressWarnings("unchecked")
    N spatial = (N) frameworkQuery.getFilter();
    assertThat((Polygon) ((LiteralExpressionImpl) spatial.getExpression2()).getValue(), is(polygon));

    assertThat(((AttributeExpressionImpl) spatial.getExpression1()).getPropertyName(),
            is(SPATIAL_TEST_ATTRIBUTE));
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest.java

/**
 * Runs a relative spatial CQL Query, verifying that the right filter class is generated based on CQL
 *
 * @param clz Class of filter to generate
 * @param cql CQL Query String//  w  w  w  .  jav a2  s . c om
 * @throws UnsupportedQueryException
 * @throws SourceUnavailableException
 * @throws FederationException
 * @throws CswException
 */
private <N extends DistanceBufferOperator> void cqlSpatialRelativeQuery(Class<N> clz, String cql)
        throws UnsupportedQueryException, SourceUnavailableException, FederationException, CswException {
    GetRecordsType grr = createDefaultPostRecordsRequest();

    QueryType query = new QueryType();
    List<QName> typeNames = new ArrayList<QName>();
    typeNames.add(new QName(CswConstants.CSW_OUTPUT_SCHEMA, VALID_TYPE, VALID_PREFIX));
    query.setTypeNames(typeNames);
    QueryConstraintType constraint = new QueryConstraintType();
    constraint.setCqlText(cql);

    query.setConstraint(constraint);
    JAXBElement<QueryType> jaxbQuery = new JAXBElement<QueryType>(cswQnameOutPutSchema, QueryType.class, query);

    grr.setAbstractQuery(jaxbQuery);

    QueryImpl frameworkQuery = (QueryImpl) queryFactory.getQuery(grr).getQuery();
    assertThat(frameworkQuery.getFilter(), instanceOf(clz));
    @SuppressWarnings("unchecked")
    N spatial = (N) frameworkQuery.getFilter();
    assertThat((Polygon) ((LiteralExpressionImpl) spatial.getExpression2()).getValue(), is(polygon));

    assertThat(((AttributeExpressionImpl) spatial.getExpression1()).getPropertyName(),
            is(SPATIAL_TEST_ATTRIBUTE));

    assertThat(spatial.getDistanceUnits(), is(UomOgcMapping.METRE.name()));
    assertThat(spatial.getDistance(), is(EXPECTED_GEO_DISTANCE));
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest.java

/**
 * Runs a binary Spatial OGC Query, verifying that the right filter class is generated based on OGC Filter
 *
 * @param spatialOps BinarySpatialOps query
 * @throws UnsupportedQueryException//from   w w  w .  j  a  va 2s  .c  o  m
 * @throws SourceUnavailableException
 * @throws FederationException
 * @throws CswException
 */
private <N extends DistanceBufferOperator> void ogcSpatialRelativeQuery(Class<N> clz,
        JAXBElement<DistanceBufferType> spatialOps)
        throws UnsupportedQueryException, SourceUnavailableException, FederationException, CswException {
    GetRecordsType grr = createDefaultPostRecordsRequest();

    QueryType query = new QueryType();
    List<QName> typeNames = new ArrayList<QName>();
    typeNames.add(new QName(CswConstants.CSW_OUTPUT_SCHEMA, VALID_TYPE, VALID_PREFIX));
    query.setTypeNames(typeNames);
    QueryConstraintType constraint = new QueryConstraintType();
    FilterType filter = new FilterType();
    filter.setSpatialOps(spatialOps);

    constraint.setFilter(filter);

    query.setConstraint(constraint);
    JAXBElement<QueryType> jaxbQuery = new JAXBElement<QueryType>(cswQnameOutPutSchema, QueryType.class, query);

    grr.setAbstractQuery(jaxbQuery);

    QueryImpl frameworkQuery = (QueryImpl) queryFactory.getQuery(grr).getQuery();
    assertThat(frameworkQuery.getFilter(), instanceOf(clz));
    @SuppressWarnings("unchecked")
    N spatial = (N) frameworkQuery.getFilter();
    assertThat((Polygon) ((LiteralExpressionImpl) spatial.getExpression2()).getValue(), is(polygon));

    assertThat(((AttributeExpressionImpl) spatial.getExpression1()).getPropertyName(),
            is(SPATIAL_TEST_ATTRIBUTE));
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest.java

/**
 * Runs a binary Spatial OGC Query, verifying that the right filter class is generated based on OGC Filter
 *
 * @param spatialOps BinarySpatialOps query
 * @throws UnsupportedQueryException//  www. j av  a2  s  . c o m
 * @throws SourceUnavailableException
 * @throws FederationException
 * @throws CswException
 */
private <N extends BinarySpatialOperator> void ogcSpatialQuery(Class<N> clz,
        JAXBElement<BinarySpatialOpType> spatialOps)
        throws UnsupportedQueryException, SourceUnavailableException, FederationException, CswException {
    GetRecordsType grr = createDefaultPostRecordsRequest();

    QueryType query = new QueryType();
    List<QName> typeNames = new ArrayList<QName>();
    typeNames.add(new QName(CswConstants.CSW_OUTPUT_SCHEMA, VALID_TYPE, VALID_PREFIX));
    query.setTypeNames(typeNames);
    QueryConstraintType constraint = new QueryConstraintType();
    FilterType filter = new FilterType();
    filter.setSpatialOps(spatialOps);

    constraint.setFilter(filter);

    query.setConstraint(constraint);
    JAXBElement<QueryType> jaxbQuery = new JAXBElement<QueryType>(cswQnameOutPutSchema, QueryType.class, query);

    grr.setAbstractQuery(jaxbQuery);

    QueryImpl frameworkQuery = (QueryImpl) queryFactory.getQuery(grr).getQuery();
    assertThat(frameworkQuery.getFilter(), instanceOf(clz));
    @SuppressWarnings("unchecked")
    N spatial = (N) frameworkQuery.getFilter();
    assertThat((Polygon) ((LiteralExpressionImpl) spatial.getExpression2()).getValue(), is(polygon));

    assertThat(((AttributeExpressionImpl) spatial.getExpression1()).getPropertyName(),
            is(SPATIAL_TEST_ATTRIBUTE));
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest.java

private Filter generateTemporalFilter(JAXBElement<BinaryComparisonOpType> temporalOps)
        throws UnsupportedQueryException, SourceUnavailableException, FederationException, CswException {
    GetRecordsType grr = createDefaultPostRecordsRequest();

    QueryType query = new QueryType();
    List<QName> typeNames = new ArrayList<QName>();
    typeNames.add(new QName(CswConstants.CSW_OUTPUT_SCHEMA, VALID_TYPE, VALID_PREFIX));
    query.setTypeNames(typeNames);/* www . j av a  2 s . c  o  m*/
    QueryConstraintType constraint = new QueryConstraintType();
    FilterType filter = new FilterType();
    filter.setComparisonOps(temporalOps);

    constraint.setFilter(filter);

    query.setConstraint(constraint);
    JAXBElement<QueryType> jaxbQuery = new JAXBElement<QueryType>(cswQnameOutPutSchema, QueryType.class, query);

    grr.setAbstractQuery(jaxbQuery);

    QueryImpl frameworkQuery = (QueryImpl) queryFactory.getQuery(grr).getQuery();
    return frameworkQuery.getFilter();
}