Example usage for javax.xml.bind DatatypeConverter parseLong

List of usage examples for javax.xml.bind DatatypeConverter parseLong

Introduction

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

Prototype

public static long parseLong(String lexicalXSDLong) 

Source Link

Document

Converts the string argument into a long value.

Usage

From source file:com.microsoft.windowsazure.management.network.GatewayOperationsImpl.java

/**
* The List Connections operation returns a list of the local network
* connections that can be accessed through the gateway.  (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154120.aspx for
* more information)//from  w  w  w  .ja  va  2 s .c  o  m
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @return The response to a ListConnections request to a Virtual Network
* Gateway.
*/
@Override
public GatewayListConnectionsResponse listConnections(String networkName)
        throws IOException, ServiceException, ParserConfigurationException, SAXException {
    // Validate
    if (networkName == null) {
        throw new NullPointerException("networkName");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("networkName", networkName);
        CloudTracing.enter(invocationId, this, "listConnectionsAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/services/networking/";
    url = url + URLEncoder.encode(networkName, "UTF-8");
    url = url + "/gateway/connections";
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpGet httpRequest = new HttpGet(url);

    // Set Headers
    httpRequest.setHeader("x-ms-version", "2015-04-01");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        GatewayListConnectionsResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new GatewayListConnectionsResponse();
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));

            Element connectionsSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "Connections");
            if (connectionsSequenceElement != null) {
                for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                        .getElementsByTagNameNS(connectionsSequenceElement,
                                "http://schemas.microsoft.com/windowsazure", "Connection")
                        .size(); i1 = i1 + 1) {
                    org.w3c.dom.Element connectionsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(connectionsSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "Connection")
                            .get(i1));
                    GatewayListConnectionsResponse.GatewayConnection connectionInstance = new GatewayListConnectionsResponse.GatewayConnection();
                    result.getConnections().add(connectionInstance);

                    Element localNetworkSiteNameElement = XmlUtility.getElementByTagNameNS(connectionsElement,
                            "http://schemas.microsoft.com/windowsazure", "LocalNetworkSiteName");
                    if (localNetworkSiteNameElement != null) {
                        String localNetworkSiteNameInstance;
                        localNetworkSiteNameInstance = localNetworkSiteNameElement.getTextContent();
                        connectionInstance.setLocalNetworkSiteName(localNetworkSiteNameInstance);
                    }

                    Element connectivityStateElement = XmlUtility.getElementByTagNameNS(connectionsElement,
                            "http://schemas.microsoft.com/windowsazure", "ConnectivityState");
                    if (connectivityStateElement != null && connectivityStateElement.getTextContent() != null
                            && !connectivityStateElement.getTextContent().isEmpty()) {
                        GatewayConnectivityState connectivityStateInstance;
                        connectivityStateInstance = GatewayConnectivityState
                                .valueOf(connectivityStateElement.getTextContent());
                        connectionInstance.setConnectivityState(connectivityStateInstance);
                    }

                    Element lastEventElement = XmlUtility.getElementByTagNameNS(connectionsElement,
                            "http://schemas.microsoft.com/windowsazure", "LastEvent");
                    if (lastEventElement != null) {
                        GatewayEvent lastEventInstance = new GatewayEvent();
                        connectionInstance.setLastEvent(lastEventInstance);

                        Element timestampElement = XmlUtility.getElementByTagNameNS(lastEventElement,
                                "http://schemas.microsoft.com/windowsazure", "Timestamp");
                        if (timestampElement != null) {
                            Calendar timestampInstance;
                            timestampInstance = DatatypeConverter
                                    .parseDateTime(timestampElement.getTextContent());
                            lastEventInstance.setTimestamp(timestampInstance);
                        }

                        Element idElement = XmlUtility.getElementByTagNameNS(lastEventElement,
                                "http://schemas.microsoft.com/windowsazure", "Id");
                        if (idElement != null) {
                            String idInstance;
                            idInstance = idElement.getTextContent();
                            lastEventInstance.setId(idInstance);
                        }

                        Element messageElement = XmlUtility.getElementByTagNameNS(lastEventElement,
                                "http://schemas.microsoft.com/windowsazure", "Message");
                        if (messageElement != null) {
                            String messageInstance;
                            messageInstance = messageElement.getTextContent();
                            lastEventInstance.setMessage(messageInstance);
                        }

                        Element dataElement = XmlUtility.getElementByTagNameNS(lastEventElement,
                                "http://schemas.microsoft.com/windowsazure", "Data");
                        if (dataElement != null) {
                            String dataInstance;
                            dataInstance = dataElement.getTextContent();
                            lastEventInstance.setData(dataInstance);
                        }
                    }

                    Element ingressBytesTransferredElement = XmlUtility.getElementByTagNameNS(
                            connectionsElement, "http://schemas.microsoft.com/windowsazure",
                            "IngressBytesTransferred");
                    if (ingressBytesTransferredElement != null) {
                        long ingressBytesTransferredInstance;
                        ingressBytesTransferredInstance = DatatypeConverter
                                .parseLong(ingressBytesTransferredElement.getTextContent());
                        connectionInstance.setIngressBytesTransferred(ingressBytesTransferredInstance);
                    }

                    Element egressBytesTransferredElement = XmlUtility.getElementByTagNameNS(connectionsElement,
                            "http://schemas.microsoft.com/windowsazure", "EgressBytesTransferred");
                    if (egressBytesTransferredElement != null) {
                        long egressBytesTransferredInstance;
                        egressBytesTransferredInstance = DatatypeConverter
                                .parseLong(egressBytesTransferredElement.getTextContent());
                        connectionInstance.setEgressBytesTransferred(egressBytesTransferredInstance);
                    }

                    Element lastConnectionEstablishedElement = XmlUtility.getElementByTagNameNS(
                            connectionsElement, "http://schemas.microsoft.com/windowsazure",
                            "LastConnectionEstablished");
                    if (lastConnectionEstablishedElement != null) {
                        Calendar lastConnectionEstablishedInstance;
                        lastConnectionEstablishedInstance = DatatypeConverter
                                .parseDateTime(lastConnectionEstablishedElement.getTextContent());
                        connectionInstance.setLastConnectionEstablished(lastConnectionEstablishedInstance);
                    }

                    Element allocatedIPAddressesSequenceElement = XmlUtility.getElementByTagNameNS(
                            connectionsElement, "http://schemas.microsoft.com/windowsazure",
                            "AllocatedIPAddresses");
                    if (allocatedIPAddressesSequenceElement != null) {
                        for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility
                                .getElementsByTagNameNS(allocatedIPAddressesSequenceElement,
                                        "http://schemas.microsoft.com/windowsazure", "string")
                                .size(); i2 = i2 + 1) {
                            org.w3c.dom.Element allocatedIPAddressesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                    .getElementsByTagNameNS(allocatedIPAddressesSequenceElement,
                                            "http://schemas.microsoft.com/windowsazure", "string")
                                    .get(i2));
                            connectionInstance.getAllocatedIPAddresses()
                                    .add(allocatedIPAddressesElement.getTextContent());
                        }
                    }
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:org.openestate.io.is24_xml.Is24XmlUtils.java

public static Long parseZahl2(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseLong(value) : null;
}

From source file:org.openestate.io.is24_xml.Is24XmlUtils.java

public static Long parseZahl3(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseLong(value) : null;
}

From source file:org.openestate.io.is24_xml.Is24XmlUtils.java

public static Long parseZahl4(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseLong(value) : null;
}

From source file:org.openestate.io.is24_xml.Is24XmlUtils.java

public static Long parseZahl5(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseLong(value) : null;
}

From source file:org.openestate.io.is24_xml.Is24XmlUtils.java

public static Long parseZahl8(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseLong(value) : null;
}

From source file:org.openestate.io.is24_xml.Is24XmlUtils.java

public static Long parseZahl10(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseLong(value) : null;
}

From source file:org.openestate.io.kyero.KyeroUtils.java

public static Long parsePriceType(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null && !"x".equalsIgnoreCase(value)) ? DatatypeConverter.parseLong(value) : null;
}