Example usage for javax.xml.datatype DatatypeFactory newInstance

List of usage examples for javax.xml.datatype DatatypeFactory newInstance

Introduction

In this page you can find the example usage for javax.xml.datatype DatatypeFactory newInstance.

Prototype

public static DatatypeFactory newInstance() throws DatatypeConfigurationException 

Source Link

Document

Obtain a new instance of a DatatypeFactory .

Usage

From source file:org.callimachusproject.behaviours.AuthenticationManagerSupport.java

private XMLGregorianCalendar now() {
    try {//w  w  w. j  av  a 2 s  .  c o m
        TimeZone utc = TimeZone.getTimeZone("UTC");
        DatatypeFactory df = DatatypeFactory.newInstance();
        return df.newXMLGregorianCalendar(new GregorianCalendar(utc));
    } catch (DatatypeConfigurationException e) {
        throw new AssertionError(e);
    }
}

From source file:org.callimachusproject.sql.SqlTupleResult.java

public SqlTupleResult(ResultSet rs, Statement stmt, Connection conn)
        throws SQLException, DatatypeConfigurationException {
    this.rs = rs;
    this.stmt = stmt;
    this.conn = conn;
    md = rs.getMetaData();//from  w  w  w.j  a  v  a  2  s  . c  om
    df = DatatypeFactory.newInstance();
}

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

public CswSubscriptionEndpoint(EventProcessor eventProcessor, TransformerManager mimeTypeTransformerManager,
        TransformerManager schemaTransformerManager, TransformerManager inputTransformerManager,
        Validator validator, CswQueryFactory queryFactory) {
    this.eventProcessor = eventProcessor;
    this.mimeTypeTransformerManager = mimeTypeTransformerManager;
    this.schemaTransformerManager = schemaTransformerManager;
    this.inputTransformerManager = inputTransformerManager;
    this.validator = validator;
    this.queryFactory = queryFactory;

    try {//from ww w .  j  a v  a 2s .  c o  m
        this.datatypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException e) {
        LOGGER.error("Error initializing datatypeFactory", e);
    }
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.transformer.CswQueryResponseTransformer.java

private ByteArrayOutputStream writeAcknowledgement(GetRecordsType request) throws CatalogTransformerException {
    try {/*from   w  w  w. ja  v  a 2s  .co m*/
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        JAXBContext jaxBContext = JAXBContext.newInstance("net.opengis.cat.csw.v_2_0_2:"
                + "net.opengis.filter.v_1_1_0:net.opengis.gml.v_3_1_1:net.opengis.ows.v_1_0_0");
        Marshaller marshaller = jaxBContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

        AcknowledgementType ack = new AcknowledgementType();
        EchoedRequestType echoedRequest = new EchoedRequestType();
        JAXBElement<GetRecordsType> jaxBRequest = new ObjectFactory().createGetRecords(request);
        echoedRequest.setAny(jaxBRequest);
        ack.setEchoedRequest(echoedRequest);
        try {
            ack.setTimeStamp(DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar()));
        } catch (DatatypeConfigurationException e) {
            LOGGER.warn("Failed to set timestamp on Acknowledgement, Exception {}", e);
        }

        JAXBElement<AcknowledgementType> jaxBAck = new ObjectFactory().createAcknowledgement(ack);
        marshaller.marshal(jaxBAck, byteArrayOutputStream);
        return byteArrayOutputStream;
    } catch (JAXBException e) {
        throw new CatalogTransformerException(e);
    }
}

From source file:org.drugis.addis.entities.DoseUnitTest.java

@Test
public void testClone() throws DatatypeConfigurationException {
    DoseUnit cloned = d_mgDay.clone();/* www.  j  av  a  2 s  .  c  o m*/
    assertEntityEquals(d_mgDay, cloned);
    assertNotSame(d_mgDay, cloned);

    cloned.setScaleModifier(ScaleModifier.KILO);
    JUnitUtil.assertNotEquals(d_mgDay.getScaleModifier(), cloned.getScaleModifier());
    cloned.setScaleModifier(ScaleModifier.MILLI);
    assertEquals(d_mgDay.getScaleModifier(), cloned.getScaleModifier());

    cloned.setUnit(new Unit("nonsense", "ns"));
    JUnitUtil.assertNotEquals(d_mgDay.getUnit(), cloned.getUnit());
    cloned.setUnit(d_mgDay.getUnit());
    assertEquals(d_mgDay.getUnit(), cloned.getUnit());

    cloned.setPerTime(DatatypeFactory.newInstance().newDuration("P2D"));
    JUnitUtil.assertNotEquals(d_mgDay.getPerTime(), cloned.getPerTime());
    cloned.setPerTime(d_mgDay.getPerTime());
    assertEquals(d_mgDay.getPerTime(), cloned.getPerTime());
}

From source file:org.eclipse.om2m.binding.coap.CoapServer.java

private void mapParameters(Request request, RequestPrimitive primitive) {
    List<String> params = request.getOptions().getURIQueries();
    String name, value;/*from   w  w w . ja  v a  2s  .c om*/
    FilterCriteria filterCriteria = new FilterCriteria();

    for (int i = 0; i < params.size(); i++) {
        if (params.get(i).split("=").length == 2) {
            name = params.get(i).split("=")[0];
            value = params.get(i).split("=")[1];

            if (name.equals(CoapParameters.RESPONSE_TYPE)) {
                if (primitive.getResponseTypeInfo() == null) {
                    primitive.setResponseTypeInfo(new ResponseTypeInfo());
                }
                primitive.getResponseTypeInfo().setResponseType(new BigInteger(value));
            }
            if (name.equals(CoapParameters.RESULT_CONTENT)) {
                primitive.setResultContent(new BigInteger(value));
            }
            if (name.equals(CoapParameters.RESULT_PERSISTENCE)) {
                try {
                    Duration duration = DatatypeFactory.newInstance().newDuration(value);
                    primitive.setResultPersistence(duration);
                } catch (DatatypeConfigurationException e) {
                    LOGGER.debug("Error in Duration creation", e);
                }
            }
            if (name.equals(CoapParameters.DELIVERY_AGGREGATION)) {
                primitive.setDeliveryAggregation(Boolean.parseBoolean(value));
            }

            if (name.equals(CoapParameters.DISCOVERY_RESULT_TYPE)) {
                primitive.setDiscoveryResultType(new BigInteger(value));
            }

            if (name.equals(CoapParameters.FILTER_USAGE)) {
                filterCriteria.setFilterUsage(new BigInteger(value));
            }

            if (name.equals(CoapParameters.LIMIT)) {
                filterCriteria.setLimit(new BigInteger(value));
            }
            if (name.equals(CoapParameters.LABELS)) {
                filterCriteria.getLabels().add(value);
            }
            if (name.equals(CoapParameters.RESOURCE_TYPE)) {
                filterCriteria.setResourceType(new BigInteger(value));
            }
        }
    }

    if (filterCriteria.getFilterUsage() != null) {
        primitive.setFilterCriteria(filterCriteria);
    }

}

From source file:org.eclipse.om2m.binding.http.RestHttpServlet.java

/**
 * Method used to map uri parameters to generic oneM2M request primitive.
 * @param request http request//from ww w.ja  v  a 2s  .com
 * @param primitive oneM2M generic request
 */
private void mapParameters(HttpServletRequest request, RequestPrimitive primitive) {
    if (request.getParameter(HttpParameters.RESPONSE_TYPE) != null) {
        if (primitive.getResponseTypeInfo() == null) {
            primitive.setResponseTypeInfo(new ResponseTypeInfo());
        }
        primitive.getResponseTypeInfo()
                .setResponseType(new BigInteger(request.getParameter(HttpParameters.RESPONSE_TYPE)));
        ;
    }
    if (request.getParameter(HttpParameters.RESULT_CONTENT) != null) {
        primitive.setResultContent(new BigInteger(request.getParameter(HttpParameters.RESULT_CONTENT)));
    }
    if (request.getParameter(HttpParameters.RESULT_PERSISTENCE) != null) {
        try {
            Duration duration = DatatypeFactory.newInstance()
                    .newDuration(request.getParameter(HttpParameters.RESULT_PERSISTENCE));
            primitive.setResultPersistence(duration);
        } catch (DatatypeConfigurationException e) {
            LOGGER.debug("Error in Duration creation", e);
        }
    }
    if (request.getParameter(HttpParameters.DELIVERY_AGGREGATION) != null) {
        primitive.setDeliveryAggregation(
                Boolean.parseBoolean(request.getParameter(HttpParameters.DELIVERY_AGGREGATION)));
    }

    if (request.getParameter(HttpParameters.DISCOVERY_RESULT_TYPE) != null) {
        primitive.setDiscoveryResultType(
                new BigInteger(request.getParameter(HttpParameters.DISCOVERY_RESULT_TYPE)));
    }

    if (request.getParameter(HttpParameters.FILTER_USAGE) != null) {
        FilterCriteria filterCriteria = new FilterCriteria();
        filterCriteria.setFilterUsage(new BigInteger(request.getParameter(HttpParameters.FILTER_USAGE)));
        if (request.getParameter(HttpParameters.LIMIT) != null) {
            filterCriteria.setLimit(new BigInteger(request.getParameter(HttpParameters.LIMIT)));
        }
        if (request.getParameter(HttpParameters.LABELS) != null) {
            filterCriteria.getLabels().addAll(Arrays.asList(request.getParameterValues(HttpParameters.LABELS)));
        }
        if (request.getParameter(HttpParameters.RESOURCE_TYPE) != null) {
            filterCriteria.setResourceType(new BigInteger(request.getParameter(HttpParameters.RESOURCE_TYPE)));
        }
        primitive.setFilterCriteria(filterCriteria);
    }
}

From source file:org.eclipse.om2m.commons.utils.DateConverter.java

/**
 * Converts java.util.Date to javax.xml.datatype.XMLGregorianCalendar
 * @param date - The Date to convert//from  w  ww  . j av a  2s. co m
 * @return xmlGregorianCalendar object
 */
public static XMLGregorianCalendar toXMLGregorianCalendar(Date date) {
    GregorianCalendar gregorianCalendar = new GregorianCalendar();
    gregorianCalendar.setTime(date);
    XMLGregorianCalendar xmlGregorianCalendar = null;
    try {
        xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);
    } catch (DatatypeConfigurationException e) {
        LOGGER.error("Date to XMLGregorianCalendar error", e);
    }
    return xmlGregorianCalendar;
}

From source file:org.eclipse.smila.ontology.records.SesameValueHelper.java

/**
 * create a Sesame date literal value from a SMILA date value.
 * /*from www .  j a v a2s  . co m*/
 * @param connection
 *          repository connection
 * @param literal
 *          a SMILA literal with a date value.
 * @return a Sesame date literal, if all goes well. Else return a string literal as fallback.
 */
private org.openrdf.model.Literal createDateLiteral(final RepositoryConnection connection,
        final Value literal) {
    try {
        final DatatypeFactory factory = DatatypeFactory.newInstance();
        final Calendar cal = Calendar.getInstance();
        cal.setTime(literal.asDate());
        // TODO: Support timezone here? I think one should use date/times if this should be handled timezone specific.
        // A date is the same on the whole planet, so always write it as a UTC literal.
        // final int zoneOffsetMinutes = cal.get(Calendar.ZONE_OFFSET) / MILLISECONDS_PER_MINUTE;
        final XMLGregorianCalendar time = factory.newXMLGregorianCalendarDate(cal.get(Calendar.YEAR),
                cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH), 0); // zoneOffsetMinutes);
        return connection.getValueFactory().createLiteral(time);
    } catch (final Exception ex) {
        _log.warn("cuold not create a time literal from value '" + literal + "', just adding a string literal",
                ex);
        return connection.getValueFactory().createLiteral(literal.toString());
    }
}

From source file:org.eclipse.smila.ontology.records.SesameValueHelper.java

/**
 * create a Sesame date/time literal value from a SMILA date/time value.
 * //from   w ww  .ja v a2 s  .com
 * @param connection
 *          repository connection
 * @param literal
 *          a SMILA literal with a date/time value.
 * @return a Sesame date/time literal, if all goes well. Else return a string literal as fallback.
 */
private org.openrdf.model.Literal createDateTimeLiteral(final RepositoryConnection connection,
        final Value literal) {
    try {
        final DatatypeFactory factory = DatatypeFactory.newInstance();
        final Calendar cal = Calendar.getInstance();
        cal.setTime(literal.asDateTime());
        final int zoneOffsetMinutes = cal.get(Calendar.ZONE_OFFSET) / MILLISECONDS_PER_MINUTE;
        final XMLGregorianCalendar time = factory.newXMLGregorianCalendar(cal.get(Calendar.YEAR),
                cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY),
                cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND), cal.get(Calendar.MILLISECOND),
                zoneOffsetMinutes);
        return connection.getValueFactory().createLiteral(time);
    } catch (final Exception ex) {
        _log.warn("cuold not create a time literal from value '" + literal + "', just adding a string literal",
                ex);
        return connection.getValueFactory().createLiteral(literal.toString());
    }
}