Example usage for javax.xml.datatype DatatypeConfigurationException getMessage

List of usage examples for javax.xml.datatype DatatypeConfigurationException getMessage

Introduction

In this page you can find the example usage for javax.xml.datatype DatatypeConfigurationException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:DatatypeAPIUsage.java

public static void main(String[] args) {
    try {/*from  w  w w .  ja  v a2s  .  c o  m*/
        DatatypeFactory df = DatatypeFactory.newInstance();
        // my work number in milliseconds:
        Duration myPhone = df.newDuration(9054133519l);
        Duration myLife = df.newDuration(true, 29, 2, 15, 13, 45, 0);
        int compareVal = myPhone.compare(myLife);
        switch (compareVal) {
        case DatatypeConstants.LESSER:
            System.out.println("There are fewer milliseconds in my phone number than my lifespan.");
            break;
        case DatatypeConstants.EQUAL:
            System.out.println("The same number of milliseconds are in my phone number and my lifespan.");
            break;
        case DatatypeConstants.GREATER:
            System.out.println("There are more milliseconds in my phone number than my lifespan.");
            break;
        case DatatypeConstants.INDETERMINATE:
            System.out.println("The comparison could not be carried out.");
        }

        // create a yearMonthDuration
        Duration ymDuration = df.newDurationYearMonth("P12Y10M");
        System.out.println("P12Y10M is of type: " + ymDuration.getXMLSchemaType());

        // create a dayTimeDuration (really this time)
        Duration dtDuration = df.newDurationDayTime("P10DT10H12M0S");
        System.out.println("P10DT10H12M0S is of type: " + dtDuration.getXMLSchemaType());

        // try to fool the factory!
        try {
            ymDuration = df.newDurationYearMonth("P12Y10M1D");
        } catch (IllegalArgumentException e) {
            System.out.println("'duration': P12Y10M1D is not 'yearMonthDuration'!!!");
        }

        XMLGregorianCalendar xgc = df.newXMLGregorianCalendar();
        xgc.setYear(1975);
        xgc.setMonth(DatatypeConstants.AUGUST);
        xgc.setDay(11);
        xgc.setHour(6);
        xgc.setMinute(44);
        xgc.setSecond(0);
        xgc.setMillisecond(0);
        xgc.setTimezone(5);
        xgc.add(myPhone);
        System.out.println("The approximate end of the number of milliseconds in my phone number was " + xgc);

        // adding a duration to XMLGregorianCalendar
        xgc.add(myLife);
        System.out.println("Adding the duration myLife to the above calendar:" + xgc);

        // create a new XMLGregorianCalendar using the string format of xgc.
        XMLGregorianCalendar xgcCopy = df.newXMLGregorianCalendar(xgc.toXMLFormat());

        // should be equal-if not what happened!!
        if (xgcCopy.compare(xgc) != DatatypeConstants.EQUAL) {
            System.out.println("oooops!");
        } else {
            System.out.println("Very good: " + xgc + " is equal to " + xgcCopy);
        }
    } catch (DatatypeConfigurationException dce) {
        System.err.println("error: Datatype error occurred - " + dce.getMessage());
        dce.printStackTrace(System.err);
    }
}

From source file:net.orpiske.dcd.dispatcher.impl.WebServicesConversor.java

private static XMLGregorianCalendar newXmlGregorianCalendar(final Date date) {
    GregorianCalendar reportDate = new GregorianCalendar();
    reportDate.setTime(date);/*from  w  w  w . ja  v  a  2  s  . co  m*/

    XMLGregorianCalendar ret = null;

    try {
        ret = DatatypeFactory.newInstance().newXMLGregorianCalendar(reportDate);
    } catch (DatatypeConfigurationException e) {
        logger.error("Unable to properly transform a date for XML data transfer: " + e.getMessage(), e);
    }

    return ret;
}

From source file:com.evolveum.midpoint.prism.xml.XmlTypeConverter.java

private static DatatypeFactory getDatatypeFactory() {
    if (datatypeFactory == null) {
        try {/* w  ww . j a v a 2 s .  c  o m*/
            datatypeFactory = DatatypeFactory.newInstance();
        } catch (DatatypeConfigurationException ex) {
            throw new IllegalStateException("Cannot construct DatatypeFactory: " + ex.getMessage(), ex);
        }
    }
    return datatypeFactory;
}

From source file:eu.europa.esig.dss.DSSXMLUtils.java

/**
 * Converts a given {@code Date} to a new {@code XMLGregorianCalendar}.
 *
 * @param date the date to be converted/*www .  jav  a  2s  . c  o m*/
 * @return the new {@code XMLGregorianCalendar} or null
 */
public static XMLGregorianCalendar createXMLGregorianCalendar(final Date date) {

    if (date == null) {
        return null;
    }
    final GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(date);
    try {

        XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance()
                .newXMLGregorianCalendar(calendar);
        xmlGregorianCalendar.setFractionalSecond(null);
        xmlGregorianCalendar = xmlGregorianCalendar.normalize(); // to UTC = Zulu
        return xmlGregorianCalendar;
    } catch (DatatypeConfigurationException e) {
        LOG.warn("Unable to properly convert a Date to an XMLGregorianCalendar " + e.getMessage(), e);
    }
    return null;
}

From source file:edu.harvard.i2b2.fhir.FhirUtil.java

private static Meta createMeta() {
    Meta meta = new Meta();
    Id vId = new Id();
    vId.setValue("1");
    meta.setVersionId(vId);/*  w ww.  j a va  2 s .  c  o m*/
    Instant instantVal = new Instant();
    XMLGregorianCalendar xmlGregvalue;
    try {
        xmlGregvalue = DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar());
    } catch (DatatypeConfigurationException e) {
        logger.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
    instantVal.setValue(xmlGregvalue);
    meta.setLastUpdated(instantVal);
    return meta;
}

From source file:com.epam.catgenome.manager.externaldb.bindings.ExternalDBBindingTest.java

private Object createParam(Class type)
        throws IllegalAccessException, InvocationTargetException, InstantiationException {
    Object param;/*w  w  w .jav a 2  s.  c om*/
    if (type == String.class) {
        param = "test";
    } else if (type == Integer.class || type == Integer.TYPE) {
        param = RandomUtils.nextInt();
    } else if (type == Long.class || type == Long.TYPE) {
        param = RandomUtils.nextLong();
    } else if (type == Float.class || type == Float.TYPE) {
        param = RandomUtils.nextFloat();
    } else if (type == Double.class || type == Double.TYPE) {
        param = RandomUtils.nextDouble();
    } else if (type == Boolean.class || type == Boolean.TYPE) {
        param = RandomUtils.nextBoolean();
    } else if (type == BigInteger.class) {
        param = new BigInteger(TEST_BIGINTEGER);
    } else if (type == List.class) {
        param = new ArrayList<>();
    } else if (type == XMLGregorianCalendar.class) {
        try {
            param = DatatypeFactory.newInstance().newXMLGregorianCalendar();
        } catch (DatatypeConfigurationException e) {
            throw new IllegalArgumentException(e.getMessage(), e);
        }
    } else {
        Constructor[] constructors = type.getConstructors();
        param = constructors[0].newInstance();
    }

    return param;
}

From source file:com.hpe.elderberry.Taxii10Template.java

/**
 * polls a TAXII 1.0 service/* w w w.j ava2s . c om*/
 *
 * @param pollUrl        poll service URL
 * @param feedName       feed name to poll
 * @param subscriptionId an optional subscription ID. Some service require it, even if they ignore it (like hail a taxii)
 * @param exclusiveBegin begin time to poll
 * @param inclusiveEnd   end time to poll
 * @return a poll response
 * @throws URISyntaxException when the feed record URL cannot be converted to a URI
 */
public PollResponse poll(URL pollUrl, String feedName, String subscriptionId, Date exclusiveBegin,
        Date inclusiveEnd) throws URISyntaxException {
    try {
        PollRequest pollRequest = new PollRequest().withMessageId(generateMessageId()).withFeedName(feedName)
                .withExclusiveBeginTimestamp(toXmlGregorianCalendar(exclusiveBegin))
                .withInclusiveEndTimestamp(toXmlGregorianCalendar(inclusiveEnd))
                .withSubscriptionId(subscriptionId);

        ResponseEntity<PollResponse> response = conn.getRestTemplate().postForEntity(pollUrl.toURI(),
                wrapRequest(pollRequest), PollResponse.class);

        return respond(response);
    } catch (DatatypeConfigurationException e) {
        log.error("error converting dates: " + e.getMessage(), e);
        return null;
    }
}

From source file:com.hpe.elderberry.Taxii11Template.java

/**
 * polls a TAXII 1.1 service/*w  w  w  .j  a  va 2s . c om*/
 *
 * @param pollUrl        poll service URL
 * @param collectionName collection name to poll
 * @param subscriptionId an optional subscription ID. Some service require it, even if they ignore it (like hail a taxii)
 * @param exclusiveBegin begin time to poll
 * @param inclusiveEnd   end time to poll
 * @return a poll response
 * @throws URISyntaxException when the collection record URL cannot be converted to a URI
 */
public PollResponse poll(URL pollUrl, String collectionName, String subscriptionId, Date exclusiveBegin,
        Date inclusiveEnd) throws URISyntaxException {
    PollRequest pollRequest;
    try {
        pollRequest = new PollRequest().withMessageId(generateMessageId()).withCollectionName(collectionName)
                .withExclusiveBeginTimestamp(toXmlGregorianCalendar(exclusiveBegin))
                .withInclusiveEndTimestamp(toXmlGregorianCalendar(inclusiveEnd))
                .withSubscriptionID(subscriptionId);
    } catch (DatatypeConfigurationException e) {
        log.error("error converting dates: " + e.getMessage(), e);
        return null;
    }

    try {
        // poll
        ResponseEntity<PollResponse> response = conn.getRestTemplate().postForEntity(pollUrl.toURI(),
                wrapRequest(pollRequest), PollResponse.class);

        return respond(response);
    } catch (TypeMismatchException e) {
        // if we're here this means that the poll request returned an error in the form of a StatusMessage, let's
        // poll again and log the message

        log.error("poll request failed, response contained a status message instead of a poll response, "
                + "requesting again to retrieve the status message", e);

        ResponseEntity<StatusMessage> response = conn.getRestTemplate().postForEntity(pollUrl.toURI(),
                wrapRequest(pollRequest), StatusMessage.class);

        log.error("error polling, status: " + statusMessageSafelyToString(response.getBody()));

        return null;
    }
}

From source file:be.e_contract.mycarenet.xkms2.XKMS2Client.java

/**
 * Main constructor.//from   w w  w  .j a  v  a2s .  c  om
 * 
 * @param location
 *            the URL of the MyCareNet XKMS 2.0 web service.
 */
public XKMS2Client(String location) {
    XMLKeyManagementService service = XKMS2ServiceFactory.newInstance();
    this.keyServicePort = service.getKeyServiceSoapPort();
    BindingProvider bindingProvider = (BindingProvider) this.keyServicePort;
    bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, location);

    Binding binding = bindingProvider.getBinding();
    @SuppressWarnings("rawtypes")
    List<Handler> handlerChain = binding.getHandlerChain();
    this.proofOfPossessionSignatureSOAPHandler = new ProofOfPossessionSignatureSOAPHandler();
    handlerChain.add(new LoggingHandler());
    handlerChain.add(this.proofOfPossessionSignatureSOAPHandler);
    this.keyBindingAuthenticationSignatureSOAPHandler = new KeyBindingAuthenticationSignatureSOAPHandler();
    handlerChain.add(this.keyBindingAuthenticationSignatureSOAPHandler);
    handlerChain.add(new LoggingHandler());
    binding.setHandlerChain(handlerChain);

    this.objectFactory = new ObjectFactory();
    this.xmldsigObjectFactory = new be.e_contract.mycarenet.jaxb.xmldsig.ObjectFactory();
    try {
        this.datatypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException("DatatypeFactory error: " + e.getMessage(), e);
    }

}

From source file:org.enotron.EnergySimulatorEndpoint.java

public EnergySimulatorEndpoint() {

    try {//from   w  ww.j  ava 2  s  .  c  o m
        factory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException e) {
        _logger.warning("Exception on XML DataFactory Creation: " + e.getMessage());
        e.printStackTrace();
    }
}