Example usage for javax.xml.bind DatatypeConverter parseDouble

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

Introduction

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

Prototype

public static double parseDouble(String lexicalXSDDouble) 

Source Link

Document

Converts the string argument into a double value.

Usage

From source file:com.microsoft.windowsazure.management.compute.VirtualMachineOSImageOperationsImpl.java

/**
* The Create OS Image operation adds an operating system image that is
* stored in a storage account and is available from the image repository.
* (see http://msdn.microsoft.com/en-us/library/windowsazure/jj157192.aspx
* for more information)/*from w  w  w. j a  va  2 s .  c om*/
*
* @param parameters Required. Parameters supplied to the Create Virtual
* Machine Image operation.
* @throws InterruptedException Thrown when a thread is waiting, sleeping,
* or otherwise occupied, and the thread is interrupted, either before or
* during the activity. Occasionally a method may wish to test whether the
* current thread has been interrupted, and if so, to immediately throw
* this exception. The following code can be used to achieve this effect:
* @throws ExecutionException Thrown when attempting to retrieve the result
* of a task that aborted by throwing an exception. This exception can be
* inspected using the Throwable.getCause() method.
* @throws ServiceException Thrown if the server returned an error for the
* request.
* @throws IOException Thrown if there was an error setting up tracing for
* the request.
* @throws ParserConfigurationException Thrown if there was an error
* configuring the parser for the response body.
* @throws SAXException Thrown if there was an error parsing the response
* body.
* @throws TransformerException Thrown if there was an error creating the
* DOM transformer.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return Parameters returned from the Create Virtual Machine Image
* operation.
*/
@Override
public VirtualMachineOSImageCreateResponse create(VirtualMachineOSImageCreateParameters parameters)
        throws InterruptedException, ExecutionException, ServiceException, IOException,
        ParserConfigurationException, SAXException, TransformerException, URISyntaxException {
    // Validate
    if (parameters == null) {
        throw new NullPointerException("parameters");
    }
    if (parameters.getLabel() == null) {
        throw new NullPointerException("parameters.Label");
    }
    if (parameters.getMediaLinkUri() == null) {
        throw new NullPointerException("parameters.MediaLinkUri");
    }
    if (parameters.getName() == null) {
        throw new NullPointerException("parameters.Name");
    }
    if (parameters.getOperatingSystemType() == null) {
        throw new NullPointerException("parameters.OperatingSystemType");
    }

    // 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("parameters", parameters);
        CloudTracing.enter(invocationId, this, "createAsync", 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/images";
    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
    HttpPost httpRequest = new HttpPost(url);

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

    // Serialize Request
    String requestContent = null;
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document requestDoc = documentBuilder.newDocument();

    Element oSImageElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "OSImage");
    requestDoc.appendChild(oSImageElement);

    Element labelElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Label");
    labelElement.appendChild(requestDoc.createTextNode(parameters.getLabel()));
    oSImageElement.appendChild(labelElement);

    Element mediaLinkElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
            "MediaLink");
    mediaLinkElement.appendChild(requestDoc.createTextNode(parameters.getMediaLinkUri().toString()));
    oSImageElement.appendChild(mediaLinkElement);

    Element nameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Name");
    nameElement.appendChild(requestDoc.createTextNode(parameters.getName()));
    oSImageElement.appendChild(nameElement);

    Element osElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "OS");
    osElement.appendChild(requestDoc.createTextNode(parameters.getOperatingSystemType()));
    oSImageElement.appendChild(osElement);

    if (parameters.getEula() != null) {
        Element eulaElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Eula");
        eulaElement.appendChild(requestDoc.createTextNode(parameters.getEula()));
        oSImageElement.appendChild(eulaElement);
    }

    if (parameters.getDescription() != null) {
        Element descriptionElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
                "Description");
        descriptionElement.appendChild(requestDoc.createTextNode(parameters.getDescription()));
        oSImageElement.appendChild(descriptionElement);
    }

    if (parameters.getImageFamily() != null) {
        Element imageFamilyElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
                "ImageFamily");
        imageFamilyElement.appendChild(requestDoc.createTextNode(parameters.getImageFamily()));
        oSImageElement.appendChild(imageFamilyElement);
    }

    if (parameters.getPublishedDate() != null) {
        Element publishedDateElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
                "PublishedDate");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'");
        simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
        publishedDateElement.appendChild(
                requestDoc.createTextNode(simpleDateFormat.format(parameters.getPublishedDate().getTime())));
        oSImageElement.appendChild(publishedDateElement);
    }

    Element isPremiumElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
            "IsPremium");
    isPremiumElement
            .appendChild(requestDoc.createTextNode(Boolean.toString(parameters.isPremium()).toLowerCase()));
    oSImageElement.appendChild(isPremiumElement);

    Element showInGuiElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
            "ShowInGui");
    showInGuiElement
            .appendChild(requestDoc.createTextNode(Boolean.toString(parameters.isShowInGui()).toLowerCase()));
    oSImageElement.appendChild(showInGuiElement);

    if (parameters.getPrivacyUri() != null) {
        Element privacyUriElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
                "PrivacyUri");
        privacyUriElement.appendChild(requestDoc.createTextNode(parameters.getPrivacyUri().toString()));
        oSImageElement.appendChild(privacyUriElement);
    }

    if (parameters.getIconUri() != null) {
        Element iconUriElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
                "IconUri");
        iconUriElement.appendChild(requestDoc.createTextNode(parameters.getIconUri()));
        oSImageElement.appendChild(iconUriElement);
    }

    if (parameters.getRecommendedVMSize() != null) {
        Element recommendedVMSizeElement = requestDoc
                .createElementNS("http://schemas.microsoft.com/windowsazure", "RecommendedVMSize");
        recommendedVMSizeElement.appendChild(requestDoc.createTextNode(parameters.getRecommendedVMSize()));
        oSImageElement.appendChild(recommendedVMSizeElement);
    }

    if (parameters.getSmallIconUri() != null) {
        Element smallIconUriElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
                "SmallIconUri");
        smallIconUriElement.appendChild(requestDoc.createTextNode(parameters.getSmallIconUri()));
        oSImageElement.appendChild(smallIconUriElement);
    }

    if (parameters.getLanguage() != null) {
        Element languageElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
                "Language");
        languageElement.appendChild(requestDoc.createTextNode(parameters.getLanguage()));
        oSImageElement.appendChild(languageElement);
    }

    DOMSource domSource = new DOMSource(requestDoc);
    StringWriter stringWriter = new StringWriter();
    StreamResult streamResult = new StreamResult(stringWriter);
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.transform(domSource, streamResult);
    requestContent = stringWriter.toString();
    StringEntity entity = new StringEntity(requestContent);
    httpRequest.setEntity(entity);
    httpRequest.setHeader("Content-Type", "application/xml");

    // 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, requestContent, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

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

            Element oSImageElement2 = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "OSImage");
            if (oSImageElement2 != null) {
                Element locationElement = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "Location");
                if (locationElement != null) {
                    String locationInstance;
                    locationInstance = locationElement.getTextContent();
                    result.setLocation(locationInstance);
                }

                Element categoryElement = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "Category");
                if (categoryElement != null) {
                    String categoryInstance;
                    categoryInstance = categoryElement.getTextContent();
                    result.setCategory(categoryInstance);
                }

                Element labelElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "Label");
                if (labelElement2 != null) {
                    String labelInstance;
                    labelInstance = labelElement2.getTextContent();
                    result.setLabel(labelInstance);
                }

                Element logicalSizeInGBElement = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "LogicalSizeInGB");
                if (logicalSizeInGBElement != null) {
                    double logicalSizeInGBInstance;
                    logicalSizeInGBInstance = DatatypeConverter
                            .parseDouble(logicalSizeInGBElement.getTextContent());
                    result.setLogicalSizeInGB(logicalSizeInGBInstance);
                }

                Element mediaLinkElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "MediaLink");
                if (mediaLinkElement2 != null) {
                    URI mediaLinkInstance;
                    mediaLinkInstance = new URI(mediaLinkElement2.getTextContent());
                    result.setMediaLinkUri(mediaLinkInstance);
                }

                Element nameElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "Name");
                if (nameElement2 != null) {
                    String nameInstance;
                    nameInstance = nameElement2.getTextContent();
                    result.setName(nameInstance);
                }

                Element osElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "OS");
                if (osElement2 != null) {
                    String osInstance;
                    osInstance = osElement2.getTextContent();
                    result.setOperatingSystemType(osInstance);
                }

                Element eulaElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "Eula");
                if (eulaElement2 != null) {
                    String eulaInstance;
                    eulaInstance = eulaElement2.getTextContent();
                    result.setEula(eulaInstance);
                }

                Element descriptionElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "Description");
                if (descriptionElement2 != null) {
                    String descriptionInstance;
                    descriptionInstance = descriptionElement2.getTextContent();
                    result.setDescription(descriptionInstance);
                }

                Element imageFamilyElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "ImageFamily");
                if (imageFamilyElement2 != null) {
                    String imageFamilyInstance;
                    imageFamilyInstance = imageFamilyElement2.getTextContent();
                    result.setImageFamily(imageFamilyInstance);
                }

                Element publishedDateElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "PublishedDate");
                if (publishedDateElement2 != null && publishedDateElement2.getTextContent() != null
                        && !publishedDateElement2.getTextContent().isEmpty()) {
                    Calendar publishedDateInstance;
                    publishedDateInstance = DatatypeConverter
                            .parseDateTime(publishedDateElement2.getTextContent());
                    result.setPublishedDate(publishedDateInstance);
                }

                Element publisherNameElement = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "PublisherName");
                if (publisherNameElement != null) {
                    String publisherNameInstance;
                    publisherNameInstance = publisherNameElement.getTextContent();
                    result.setPublisherName(publisherNameInstance);
                }

                Element isPremiumElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "IsPremium");
                if (isPremiumElement2 != null && isPremiumElement2.getTextContent() != null
                        && !isPremiumElement2.getTextContent().isEmpty()) {
                    boolean isPremiumInstance;
                    isPremiumInstance = DatatypeConverter
                            .parseBoolean(isPremiumElement2.getTextContent().toLowerCase());
                    result.setIsPremium(isPremiumInstance);
                }

                Element showInGuiElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "ShowInGui");
                if (showInGuiElement2 != null && showInGuiElement2.getTextContent() != null
                        && !showInGuiElement2.getTextContent().isEmpty()) {
                    boolean showInGuiInstance;
                    showInGuiInstance = DatatypeConverter
                            .parseBoolean(showInGuiElement2.getTextContent().toLowerCase());
                    result.setShowInGui(showInGuiInstance);
                }

                Element privacyUriElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "PrivacyUri");
                if (privacyUriElement2 != null) {
                    URI privacyUriInstance;
                    privacyUriInstance = new URI(privacyUriElement2.getTextContent());
                    result.setPrivacyUri(privacyUriInstance);
                }

                Element iconUriElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "IconUri");
                if (iconUriElement2 != null) {
                    String iconUriInstance;
                    iconUriInstance = iconUriElement2.getTextContent();
                    result.setIconUri(iconUriInstance);
                }

                Element recommendedVMSizeElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "RecommendedVMSize");
                if (recommendedVMSizeElement2 != null) {
                    String recommendedVMSizeInstance;
                    recommendedVMSizeInstance = recommendedVMSizeElement2.getTextContent();
                    result.setRecommendedVMSize(recommendedVMSizeInstance);
                }

                Element smallIconUriElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "SmallIconUri");
                if (smallIconUriElement2 != null) {
                    String smallIconUriInstance;
                    smallIconUriInstance = smallIconUriElement2.getTextContent();
                    result.setSmallIconUri(smallIconUriInstance);
                }

                Element languageElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "Language");
                if (languageElement2 != null) {
                    String languageInstance;
                    languageInstance = languageElement2.getTextContent();
                    result.setLanguage(languageInstance);
                }

                Element iOTypeElement = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "IOType");
                if (iOTypeElement != null) {
                    String iOTypeInstance;
                    iOTypeInstance = iOTypeElement.getTextContent();
                    result.setIOType(iOTypeInstance);
                }
            }

        }
        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:com.microsoft.windowsazure.management.compute.VirtualMachineOSImageOperationsImpl.java

/**
* The Get OS Image operation retrieves the details for an operating system
* image from the image repository.  (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj157191.aspx for
* more information)//from  w  w  w.java  2 s .c om
*
* @param imageName Required. The name of the OS image to retrieve.
* @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.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return A virtual machine image associated with your subscription.
*/
@Override
public VirtualMachineOSImageGetResponse get(String imageName)
        throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException {
    // Validate
    if (imageName == null) {
        throw new NullPointerException("imageName");
    }

    // 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("imageName", imageName);
        CloudTracing.enter(invocationId, this, "getAsync", 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/images/";
    url = url + URLEncoder.encode(imageName, "UTF-8");
    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
        VirtualMachineOSImageGetResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new VirtualMachineOSImageGetResponse();
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));

            Element oSImageElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "OSImage");
            if (oSImageElement != null) {
                Element affinityGroupElement = XmlUtility.getElementByTagNameNS(oSImageElement,
                        "http://schemas.microsoft.com/windowsazure", "AffinityGroup");
                if (affinityGroupElement != null) {
                    String affinityGroupInstance;
                    affinityGroupInstance = affinityGroupElement.getTextContent();
                    result.setAffinityGroup(affinityGroupInstance);
                }

                Element categoryElement = XmlUtility.getElementByTagNameNS(oSImageElement,
                        "http://schemas.microsoft.com/windowsazure", "Category");
                if (categoryElement != null) {
                    String categoryInstance;
                    categoryInstance = categoryElement.getTextContent();
                    result.setCategory(categoryInstance);
                }

                Element labelElement = XmlUtility.getElementByTagNameNS(oSImageElement,
                        "http://schemas.microsoft.com/windowsazure", "Label");
                if (labelElement != null) {
                    String labelInstance;
                    labelInstance = labelElement.getTextContent();
                    result.setLabel(labelInstance);
                }

                Element locationElement = XmlUtility.getElementByTagNameNS(oSImageElement,
                        "http://schemas.microsoft.com/windowsazure", "Location");
                if (locationElement != null) {
                    String locationInstance;
                    locationInstance = locationElement.getTextContent();
                    result.setLocation(locationInstance);
                }

                Element logicalSizeInGBElement = XmlUtility.getElementByTagNameNS(oSImageElement,
                        "http://schemas.microsoft.com/windowsazure", "LogicalSizeInGB");
                if (logicalSizeInGBElement != null) {
                    double logicalSizeInGBInstance;
                    logicalSizeInGBInstance = DatatypeConverter
                            .parseDouble(logicalSizeInGBElement.getTextContent());
                    result.setLogicalSizeInGB(logicalSizeInGBInstance);
                }

                Element mediaLinkElement = XmlUtility.getElementByTagNameNS(oSImageElement,
                        "http://schemas.microsoft.com/windowsazure", "MediaLink");
                if (mediaLinkElement != null) {
                    URI mediaLinkInstance;
                    mediaLinkInstance = new URI(mediaLinkElement.getTextContent());
                    result.setMediaLinkUri(mediaLinkInstance);
                }

                Element nameElement = XmlUtility.getElementByTagNameNS(oSImageElement,
                        "http://schemas.microsoft.com/windowsazure", "Name");
                if (nameElement != null) {
                    String nameInstance;
                    nameInstance = nameElement.getTextContent();
                    result.setName(nameInstance);
                }

                Element osElement = XmlUtility.getElementByTagNameNS(oSImageElement,
                        "http://schemas.microsoft.com/windowsazure", "OS");
                if (osElement != null) {
                    String osInstance;
                    osInstance = osElement.getTextContent();
                    result.setOperatingSystemType(osInstance);
                }

                Element eulaElement = XmlUtility.getElementByTagNameNS(oSImageElement,
                        "http://schemas.microsoft.com/windowsazure", "Eula");
                if (eulaElement != null) {
                    String eulaInstance;
                    eulaInstance = eulaElement.getTextContent();
                    result.setEula(eulaInstance);
                }

                Element descriptionElement = XmlUtility.getElementByTagNameNS(oSImageElement,
                        "http://schemas.microsoft.com/windowsazure", "Description");
                if (descriptionElement != null) {
                    String descriptionInstance;
                    descriptionInstance = descriptionElement.getTextContent();
                    result.setDescription(descriptionInstance);
                }

                Element imageFamilyElement = XmlUtility.getElementByTagNameNS(oSImageElement,
                        "http://schemas.microsoft.com/windowsazure", "ImageFamily");
                if (imageFamilyElement != null) {
                    String imageFamilyInstance;
                    imageFamilyInstance = imageFamilyElement.getTextContent();
                    result.setImageFamily(imageFamilyInstance);
                }

                Element showInGuiElement = XmlUtility.getElementByTagNameNS(oSImageElement,
                        "http://schemas.microsoft.com/windowsazure", "ShowInGui");
                if (showInGuiElement != null && showInGuiElement.getTextContent() != null
                        && !showInGuiElement.getTextContent().isEmpty()) {
                    boolean showInGuiInstance;
                    showInGuiInstance = DatatypeConverter
                            .parseBoolean(showInGuiElement.getTextContent().toLowerCase());
                    result.setShowInGui(showInGuiInstance);
                }

                Element publishedDateElement = XmlUtility.getElementByTagNameNS(oSImageElement,
                        "http://schemas.microsoft.com/windowsazure", "PublishedDate");
                if (publishedDateElement != null) {
                    Calendar publishedDateInstance;
                    publishedDateInstance = DatatypeConverter
                            .parseDateTime(publishedDateElement.getTextContent());
                    result.setPublishedDate(publishedDateInstance);
                }

                Element isPremiumElement = XmlUtility.getElementByTagNameNS(oSImageElement,
                        "http://schemas.microsoft.com/windowsazure", "IsPremium");
                if (isPremiumElement != null && isPremiumElement.getTextContent() != null
                        && !isPremiumElement.getTextContent().isEmpty()) {
                    boolean isPremiumInstance;
                    isPremiumInstance = DatatypeConverter
                            .parseBoolean(isPremiumElement.getTextContent().toLowerCase());
                    result.setIsPremium(isPremiumInstance);
                }

                Element iconUriElement = XmlUtility.getElementByTagNameNS(oSImageElement,
                        "http://schemas.microsoft.com/windowsazure", "IconUri");
                if (iconUriElement != null) {
                    String iconUriInstance;
                    iconUriInstance = iconUriElement.getTextContent();
                    result.setIconUri(iconUriInstance);
                }

                Element privacyUriElement = XmlUtility.getElementByTagNameNS(oSImageElement,
                        "http://schemas.microsoft.com/windowsazure", "PrivacyUri");
                if (privacyUriElement != null) {
                    URI privacyUriInstance;
                    privacyUriInstance = new URI(privacyUriElement.getTextContent());
                    result.setPrivacyUri(privacyUriInstance);
                }

                Element recommendedVMSizeElement = XmlUtility.getElementByTagNameNS(oSImageElement,
                        "http://schemas.microsoft.com/windowsazure", "RecommendedVMSize");
                if (recommendedVMSizeElement != null) {
                    String recommendedVMSizeInstance;
                    recommendedVMSizeInstance = recommendedVMSizeElement.getTextContent();
                    result.setRecommendedVMSize(recommendedVMSizeInstance);
                }

                Element publisherNameElement = XmlUtility.getElementByTagNameNS(oSImageElement,
                        "http://schemas.microsoft.com/windowsazure", "PublisherName");
                if (publisherNameElement != null) {
                    String publisherNameInstance;
                    publisherNameInstance = publisherNameElement.getTextContent();
                    result.setPublisherName(publisherNameInstance);
                }

                Element smallIconUriElement = XmlUtility.getElementByTagNameNS(oSImageElement,
                        "http://schemas.microsoft.com/windowsazure", "SmallIconUri");
                if (smallIconUriElement != null) {
                    String smallIconUriInstance;
                    smallIconUriInstance = smallIconUriElement.getTextContent();
                    result.setSmallIconUri(smallIconUriInstance);
                }

                Element languageElement = XmlUtility.getElementByTagNameNS(oSImageElement,
                        "http://schemas.microsoft.com/windowsazure", "Language");
                if (languageElement != null) {
                    String languageInstance;
                    languageInstance = languageElement.getTextContent();
                    result.setLanguage(languageInstance);
                }

                Element iOTypeElement = XmlUtility.getElementByTagNameNS(oSImageElement,
                        "http://schemas.microsoft.com/windowsazure", "IOType");
                if (iOTypeElement != null) {
                    String iOTypeInstance;
                    iOTypeInstance = iOTypeElement.getTextContent();
                    result.setIOType(iOTypeInstance);
                }
            }

        }
        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:com.microsoft.windowsazure.management.compute.VirtualMachineOSImageOperationsImpl.java

/**
* Gets OS Image's properties and its replication details. This operation is
* only for publishers. You have to be registered as image publisher with
* Windows Azure to be able to call this.
*
* @param imageName Required. The name of the virtual machine image to
* replicate.//from  w ww  .j  a  va 2  s  .c  o  m
* @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.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return The Get Details OS Images operation response.
*/
@Override
public VirtualMachineOSImageGetDetailsResponse getDetails(String imageName)
        throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException {
    // Validate
    if (imageName == null) {
        throw new NullPointerException("imageName");
    }

    // 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("imageName", imageName);
        CloudTracing.enter(invocationId, this, "getDetailsAsync", 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/images/";
    url = url + URLEncoder.encode(imageName, "UTF-8");
    url = url + "/details";
    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
        VirtualMachineOSImageGetDetailsResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new VirtualMachineOSImageGetDetailsResponse();
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));

            Element oSImageDetailsElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "OSImageDetails");
            if (oSImageDetailsElement != null) {
                Element isCorruptedElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "IsCorrupted");
                if (isCorruptedElement != null && isCorruptedElement.getTextContent() != null
                        && !isCorruptedElement.getTextContent().isEmpty()) {
                    boolean isCorruptedInstance;
                    isCorruptedInstance = DatatypeConverter
                            .parseBoolean(isCorruptedElement.getTextContent().toLowerCase());
                    result.setIsCorrupted(isCorruptedInstance);
                }

                Element replicationProgressSequenceElement = XmlUtility.getElementByTagNameNS(
                        oSImageDetailsElement, "http://schemas.microsoft.com/windowsazure",
                        "ReplicationProgress");
                if (replicationProgressSequenceElement != null) {
                    for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(replicationProgressSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "ReplicationProgressElement")
                            .size(); i1 = i1 + 1) {
                        org.w3c.dom.Element replicationProgressElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                                .getElementsByTagNameNS(replicationProgressSequenceElement,
                                        "http://schemas.microsoft.com/windowsazure",
                                        "ReplicationProgressElement")
                                .get(i1));
                        VirtualMachineOSImageGetDetailsResponse.ReplicationProgressElement replicationProgressElementInstance = new VirtualMachineOSImageGetDetailsResponse.ReplicationProgressElement();
                        result.getReplicationProgress().add(replicationProgressElementInstance);

                        Element locationElement = XmlUtility.getElementByTagNameNS(replicationProgressElement,
                                "http://schemas.microsoft.com/windowsazure", "Location");
                        if (locationElement != null) {
                            String locationInstance;
                            locationInstance = locationElement.getTextContent();
                            replicationProgressElementInstance.setLocation(locationInstance);
                        }

                        Element progressElement = XmlUtility.getElementByTagNameNS(replicationProgressElement,
                                "http://schemas.microsoft.com/windowsazure", "Progress");
                        if (progressElement != null) {
                            String progressInstance;
                            progressInstance = progressElement.getTextContent();
                            replicationProgressElementInstance.setProgress(progressInstance);
                        }
                    }
                }

                Element computeImageAttributesElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "ComputeImageAttributes");
                if (computeImageAttributesElement != null) {
                    ComputeImageAttributes computeImageAttributesInstance = new ComputeImageAttributes();
                    result.setComputeImageAttributes(computeImageAttributesInstance);

                    Element offerElement = XmlUtility.getElementByTagNameNS(computeImageAttributesElement,
                            "http://schemas.microsoft.com/windowsazure", "Offer");
                    if (offerElement != null) {
                        String offerInstance;
                        offerInstance = offerElement.getTextContent();
                        computeImageAttributesInstance.setOffer(offerInstance);
                    }

                    Element skuElement = XmlUtility.getElementByTagNameNS(computeImageAttributesElement,
                            "http://schemas.microsoft.com/windowsazure", "Sku");
                    if (skuElement != null) {
                        String skuInstance;
                        skuInstance = skuElement.getTextContent();
                        computeImageAttributesInstance.setSku(skuInstance);
                    }

                    Element versionElement = XmlUtility.getElementByTagNameNS(computeImageAttributesElement,
                            "http://schemas.microsoft.com/windowsazure", "Version");
                    if (versionElement != null) {
                        String versionInstance;
                        versionInstance = versionElement.getTextContent();
                        computeImageAttributesInstance.setVersion(versionInstance);
                    }
                }

                Element marketplaceImageAttributesElement = XmlUtility.getElementByTagNameNS(
                        oSImageDetailsElement, "http://schemas.microsoft.com/windowsazure",
                        "MarketplaceImageAttributes");
                if (marketplaceImageAttributesElement != null) {
                    MarketplaceImageAttributes marketplaceImageAttributesInstance = new MarketplaceImageAttributes();
                    result.setMarketplaceImageAttributes(marketplaceImageAttributesInstance);

                    Element publisherIdElement = XmlUtility.getElementByTagNameNS(
                            marketplaceImageAttributesElement, "http://schemas.microsoft.com/windowsazure",
                            "PublisherId");
                    if (publisherIdElement != null) {
                        String publisherIdInstance;
                        publisherIdInstance = publisherIdElement.getTextContent();
                        marketplaceImageAttributesInstance.setPublisherId(publisherIdInstance);
                    }

                    Element planElement = XmlUtility.getElementByTagNameNS(marketplaceImageAttributesElement,
                            "http://schemas.microsoft.com/windowsazure", "Plan");
                    if (planElement != null) {
                        Plan planInstance = new Plan();
                        marketplaceImageAttributesInstance.setPlan(planInstance);

                        Element nameElement = XmlUtility.getElementByTagNameNS(planElement,
                                "http://schemas.microsoft.com/windowsazure", "Name");
                        if (nameElement != null) {
                            String nameInstance;
                            nameInstance = nameElement.getTextContent();
                            planInstance.setName(nameInstance);
                        }

                        Element publisherElement = XmlUtility.getElementByTagNameNS(planElement,
                                "http://schemas.microsoft.com/windowsazure", "Publisher");
                        if (publisherElement != null) {
                            String publisherInstance;
                            publisherInstance = publisherElement.getTextContent();
                            planInstance.setPublisher(publisherInstance);
                        }

                        Element productElement = XmlUtility.getElementByTagNameNS(planElement,
                                "http://schemas.microsoft.com/windowsazure", "Product");
                        if (productElement != null) {
                            String productInstance;
                            productInstance = productElement.getTextContent();
                            planInstance.setProduct(productInstance);
                        }
                    }
                }

                Element affinityGroupElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "AffinityGroup");
                if (affinityGroupElement != null) {
                    String affinityGroupInstance;
                    affinityGroupInstance = affinityGroupElement.getTextContent();
                    result.setAffinityGroup(affinityGroupInstance);
                }

                Element categoryElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "Category");
                if (categoryElement != null) {
                    String categoryInstance;
                    categoryInstance = categoryElement.getTextContent();
                    result.setCategory(categoryInstance);
                }

                Element labelElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "Label");
                if (labelElement != null) {
                    String labelInstance;
                    labelInstance = labelElement.getTextContent();
                    result.setLabel(labelInstance);
                }

                Element locationElement2 = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "Location");
                if (locationElement2 != null) {
                    String locationInstance2;
                    locationInstance2 = locationElement2.getTextContent();
                    result.setLocation(locationInstance2);
                }

                Element logicalSizeInGBElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "LogicalSizeInGB");
                if (logicalSizeInGBElement != null) {
                    double logicalSizeInGBInstance;
                    logicalSizeInGBInstance = DatatypeConverter
                            .parseDouble(logicalSizeInGBElement.getTextContent());
                    result.setLogicalSizeInGB(logicalSizeInGBInstance);
                }

                Element mediaLinkElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "MediaLink");
                if (mediaLinkElement != null) {
                    URI mediaLinkInstance;
                    mediaLinkInstance = new URI(mediaLinkElement.getTextContent());
                    result.setMediaLinkUri(mediaLinkInstance);
                }

                Element nameElement2 = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "Name");
                if (nameElement2 != null) {
                    String nameInstance2;
                    nameInstance2 = nameElement2.getTextContent();
                    result.setName(nameInstance2);
                }

                Element osElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "OS");
                if (osElement != null) {
                    String osInstance;
                    osInstance = osElement.getTextContent();
                    result.setOperatingSystemType(osInstance);
                }

                Element eulaElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "Eula");
                if (eulaElement != null) {
                    String eulaInstance;
                    eulaInstance = eulaElement.getTextContent();
                    result.setEula(eulaInstance);
                }

                Element descriptionElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "Description");
                if (descriptionElement != null) {
                    String descriptionInstance;
                    descriptionInstance = descriptionElement.getTextContent();
                    result.setDescription(descriptionInstance);
                }

                Element imageFamilyElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "ImageFamily");
                if (imageFamilyElement != null) {
                    String imageFamilyInstance;
                    imageFamilyInstance = imageFamilyElement.getTextContent();
                    result.setImageFamily(imageFamilyInstance);
                }

                Element showInGuiElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "ShowInGui");
                if (showInGuiElement != null && showInGuiElement.getTextContent() != null
                        && !showInGuiElement.getTextContent().isEmpty()) {
                    boolean showInGuiInstance;
                    showInGuiInstance = DatatypeConverter
                            .parseBoolean(showInGuiElement.getTextContent().toLowerCase());
                    result.setShowInGui(showInGuiInstance);
                }

                Element publishedDateElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "PublishedDate");
                if (publishedDateElement != null) {
                    Calendar publishedDateInstance;
                    publishedDateInstance = DatatypeConverter
                            .parseDateTime(publishedDateElement.getTextContent());
                    result.setPublishedDate(publishedDateInstance);
                }

                Element isPremiumElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "IsPremium");
                if (isPremiumElement != null && isPremiumElement.getTextContent() != null
                        && !isPremiumElement.getTextContent().isEmpty()) {
                    boolean isPremiumInstance;
                    isPremiumInstance = DatatypeConverter
                            .parseBoolean(isPremiumElement.getTextContent().toLowerCase());
                    result.setIsPremium(isPremiumInstance);
                }

                Element iconUriElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "IconUri");
                if (iconUriElement != null) {
                    String iconUriInstance;
                    iconUriInstance = iconUriElement.getTextContent();
                    result.setIconUri(iconUriInstance);
                }

                Element privacyUriElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "PrivacyUri");
                if (privacyUriElement != null) {
                    URI privacyUriInstance;
                    privacyUriInstance = new URI(privacyUriElement.getTextContent());
                    result.setPrivacyUri(privacyUriInstance);
                }

                Element recommendedVMSizeElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "RecommendedVMSize");
                if (recommendedVMSizeElement != null) {
                    String recommendedVMSizeInstance;
                    recommendedVMSizeInstance = recommendedVMSizeElement.getTextContent();
                    result.setRecommendedVMSize(recommendedVMSizeInstance);
                }

                Element publisherNameElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "PublisherName");
                if (publisherNameElement != null) {
                    String publisherNameInstance;
                    publisherNameInstance = publisherNameElement.getTextContent();
                    result.setPublisherName(publisherNameInstance);
                }

                Element smallIconUriElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "SmallIconUri");
                if (smallIconUriElement != null) {
                    String smallIconUriInstance;
                    smallIconUriInstance = smallIconUriElement.getTextContent();
                    result.setSmallIconUri(smallIconUriInstance);
                }

                Element languageElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "Language");
                if (languageElement != null) {
                    String languageInstance;
                    languageInstance = languageElement.getTextContent();
                    result.setLanguage(languageInstance);
                }

                Element iOTypeElement = XmlUtility.getElementByTagNameNS(oSImageDetailsElement,
                        "http://schemas.microsoft.com/windowsazure", "IOType");
                if (iOTypeElement != null) {
                    String iOTypeInstance;
                    iOTypeInstance = iOTypeElement.getTextContent();
                    result.setIOType(iOTypeInstance);
                }
            }

        }
        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:com.microsoft.windowsazure.management.compute.VirtualMachineOSImageOperationsImpl.java

/**
* The List OS Images operation retrieves a list of the operating system
* images from the image repository.  (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj157191.aspx for
* more information)//from   w  w  w  .  j a v a 2s . c  om
*
* @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.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return The List OS Images operation response.
*/
@Override
public VirtualMachineOSImageListResponse list()
        throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException {
    // Validate

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        CloudTracing.enter(invocationId, this, "listAsync", 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/images";
    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
        VirtualMachineOSImageListResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new VirtualMachineOSImageListResponse();
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));

            Element imagesSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "Images");
            if (imagesSequenceElement != null) {
                for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                        .getElementsByTagNameNS(imagesSequenceElement,
                                "http://schemas.microsoft.com/windowsazure", "OSImage")
                        .size(); i1 = i1 + 1) {
                    org.w3c.dom.Element imagesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(imagesSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "OSImage")
                            .get(i1));
                    VirtualMachineOSImageListResponse.VirtualMachineOSImage oSImageInstance = new VirtualMachineOSImageListResponse.VirtualMachineOSImage();
                    result.getImages().add(oSImageInstance);

                    Element affinityGroupElement = XmlUtility.getElementByTagNameNS(imagesElement,
                            "http://schemas.microsoft.com/windowsazure", "AffinityGroup");
                    if (affinityGroupElement != null) {
                        String affinityGroupInstance;
                        affinityGroupInstance = affinityGroupElement.getTextContent();
                        oSImageInstance.setAffinityGroup(affinityGroupInstance);
                    }

                    Element categoryElement = XmlUtility.getElementByTagNameNS(imagesElement,
                            "http://schemas.microsoft.com/windowsazure", "Category");
                    if (categoryElement != null) {
                        String categoryInstance;
                        categoryInstance = categoryElement.getTextContent();
                        oSImageInstance.setCategory(categoryInstance);
                    }

                    Element labelElement = XmlUtility.getElementByTagNameNS(imagesElement,
                            "http://schemas.microsoft.com/windowsazure", "Label");
                    if (labelElement != null) {
                        String labelInstance;
                        labelInstance = labelElement.getTextContent();
                        oSImageInstance.setLabel(labelInstance);
                    }

                    Element locationElement = XmlUtility.getElementByTagNameNS(imagesElement,
                            "http://schemas.microsoft.com/windowsazure", "Location");
                    if (locationElement != null) {
                        String locationInstance;
                        locationInstance = locationElement.getTextContent();
                        oSImageInstance.setLocation(locationInstance);
                    }

                    Element logicalSizeInGBElement = XmlUtility.getElementByTagNameNS(imagesElement,
                            "http://schemas.microsoft.com/windowsazure", "LogicalSizeInGB");
                    if (logicalSizeInGBElement != null) {
                        double logicalSizeInGBInstance;
                        logicalSizeInGBInstance = DatatypeConverter
                                .parseDouble(logicalSizeInGBElement.getTextContent());
                        oSImageInstance.setLogicalSizeInGB(logicalSizeInGBInstance);
                    }

                    Element mediaLinkElement = XmlUtility.getElementByTagNameNS(imagesElement,
                            "http://schemas.microsoft.com/windowsazure", "MediaLink");
                    if (mediaLinkElement != null) {
                        URI mediaLinkInstance;
                        mediaLinkInstance = new URI(mediaLinkElement.getTextContent());
                        oSImageInstance.setMediaLinkUri(mediaLinkInstance);
                    }

                    Element nameElement = XmlUtility.getElementByTagNameNS(imagesElement,
                            "http://schemas.microsoft.com/windowsazure", "Name");
                    if (nameElement != null) {
                        String nameInstance;
                        nameInstance = nameElement.getTextContent();
                        oSImageInstance.setName(nameInstance);
                    }

                    Element osElement = XmlUtility.getElementByTagNameNS(imagesElement,
                            "http://schemas.microsoft.com/windowsazure", "OS");
                    if (osElement != null) {
                        String osInstance;
                        osInstance = osElement.getTextContent();
                        oSImageInstance.setOperatingSystemType(osInstance);
                    }

                    Element eulaElement = XmlUtility.getElementByTagNameNS(imagesElement,
                            "http://schemas.microsoft.com/windowsazure", "Eula");
                    if (eulaElement != null) {
                        String eulaInstance;
                        eulaInstance = eulaElement.getTextContent();
                        oSImageInstance.setEula(eulaInstance);
                    }

                    Element descriptionElement = XmlUtility.getElementByTagNameNS(imagesElement,
                            "http://schemas.microsoft.com/windowsazure", "Description");
                    if (descriptionElement != null) {
                        String descriptionInstance;
                        descriptionInstance = descriptionElement.getTextContent();
                        oSImageInstance.setDescription(descriptionInstance);
                    }

                    Element imageFamilyElement = XmlUtility.getElementByTagNameNS(imagesElement,
                            "http://schemas.microsoft.com/windowsazure", "ImageFamily");
                    if (imageFamilyElement != null) {
                        String imageFamilyInstance;
                        imageFamilyInstance = imageFamilyElement.getTextContent();
                        oSImageInstance.setImageFamily(imageFamilyInstance);
                    }

                    Element showInGuiElement = XmlUtility.getElementByTagNameNS(imagesElement,
                            "http://schemas.microsoft.com/windowsazure", "ShowInGui");
                    if (showInGuiElement != null && showInGuiElement.getTextContent() != null
                            && !showInGuiElement.getTextContent().isEmpty()) {
                        boolean showInGuiInstance;
                        showInGuiInstance = DatatypeConverter
                                .parseBoolean(showInGuiElement.getTextContent().toLowerCase());
                        oSImageInstance.setShowInGui(showInGuiInstance);
                    }

                    Element publishedDateElement = XmlUtility.getElementByTagNameNS(imagesElement,
                            "http://schemas.microsoft.com/windowsazure", "PublishedDate");
                    if (publishedDateElement != null) {
                        Calendar publishedDateInstance;
                        publishedDateInstance = DatatypeConverter
                                .parseDateTime(publishedDateElement.getTextContent());
                        oSImageInstance.setPublishedDate(publishedDateInstance);
                    }

                    Element isPremiumElement = XmlUtility.getElementByTagNameNS(imagesElement,
                            "http://schemas.microsoft.com/windowsazure", "IsPremium");
                    if (isPremiumElement != null && isPremiumElement.getTextContent() != null
                            && !isPremiumElement.getTextContent().isEmpty()) {
                        boolean isPremiumInstance;
                        isPremiumInstance = DatatypeConverter
                                .parseBoolean(isPremiumElement.getTextContent().toLowerCase());
                        oSImageInstance.setIsPremium(isPremiumInstance);
                    }

                    Element privacyUriElement = XmlUtility.getElementByTagNameNS(imagesElement,
                            "http://schemas.microsoft.com/windowsazure", "PrivacyUri");
                    if (privacyUriElement != null) {
                        URI privacyUriInstance;
                        privacyUriInstance = new URI(privacyUriElement.getTextContent());
                        oSImageInstance.setPrivacyUri(privacyUriInstance);
                    }

                    Element recommendedVMSizeElement = XmlUtility.getElementByTagNameNS(imagesElement,
                            "http://schemas.microsoft.com/windowsazure", "RecommendedVMSize");
                    if (recommendedVMSizeElement != null) {
                        String recommendedVMSizeInstance;
                        recommendedVMSizeInstance = recommendedVMSizeElement.getTextContent();
                        oSImageInstance.setRecommendedVMSize(recommendedVMSizeInstance);
                    }

                    Element publisherNameElement = XmlUtility.getElementByTagNameNS(imagesElement,
                            "http://schemas.microsoft.com/windowsazure", "PublisherName");
                    if (publisherNameElement != null) {
                        String publisherNameInstance;
                        publisherNameInstance = publisherNameElement.getTextContent();
                        oSImageInstance.setPublisherName(publisherNameInstance);
                    }

                    Element pricingDetailLinkElement = XmlUtility.getElementByTagNameNS(imagesElement,
                            "http://schemas.microsoft.com/windowsazure", "PricingDetailLink");
                    if (pricingDetailLinkElement != null) {
                        URI pricingDetailLinkInstance;
                        pricingDetailLinkInstance = new URI(pricingDetailLinkElement.getTextContent());
                        oSImageInstance.setPricingDetailUri(pricingDetailLinkInstance);
                    }

                    Element iconUriElement = XmlUtility.getElementByTagNameNS(imagesElement,
                            "http://schemas.microsoft.com/windowsazure", "IconUri");
                    if (iconUriElement != null) {
                        String iconUriInstance;
                        iconUriInstance = iconUriElement.getTextContent();
                        oSImageInstance.setIconUri(iconUriInstance);
                    }

                    Element smallIconUriElement = XmlUtility.getElementByTagNameNS(imagesElement,
                            "http://schemas.microsoft.com/windowsazure", "SmallIconUri");
                    if (smallIconUriElement != null) {
                        String smallIconUriInstance;
                        smallIconUriInstance = smallIconUriElement.getTextContent();
                        oSImageInstance.setSmallIconUri(smallIconUriInstance);
                    }

                    Element languageElement = XmlUtility.getElementByTagNameNS(imagesElement,
                            "http://schemas.microsoft.com/windowsazure", "Language");
                    if (languageElement != null) {
                        String languageInstance;
                        languageInstance = languageElement.getTextContent();
                        oSImageInstance.setLanguage(languageInstance);
                    }

                    Element iOTypeElement = XmlUtility.getElementByTagNameNS(imagesElement,
                            "http://schemas.microsoft.com/windowsazure", "IOType");
                    if (iOTypeElement != null) {
                        String iOTypeInstance;
                        iOTypeInstance = iOTypeElement.getTextContent();
                        oSImageInstance.setIOType(iOTypeInstance);
                    }
                }
            }

        }
        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:com.microsoft.windowsazure.management.compute.VirtualMachineOSImageOperationsImpl.java

/**
* The Update OS Image operation updates an OS image that in your image
* repository.  (see/* www  . j  a v a 2 s  . c om*/
* http://msdn.microsoft.com/en-us/library/windowsazure/jj157198.aspx for
* more information)
*
* @param imageName Required. The name of the virtual machine image to be
* updated.
* @param parameters Required. Parameters supplied to the Update Virtual
* Machine Image operation.
* @throws InterruptedException Thrown when a thread is waiting, sleeping,
* or otherwise occupied, and the thread is interrupted, either before or
* during the activity. Occasionally a method may wish to test whether the
* current thread has been interrupted, and if so, to immediately throw
* this exception. The following code can be used to achieve this effect:
* @throws ExecutionException Thrown when attempting to retrieve the result
* of a task that aborted by throwing an exception. This exception can be
* inspected using the Throwable.getCause() method.
* @throws ServiceException Thrown if the server returned an error for the
* request.
* @throws IOException Thrown if there was an error setting up tracing for
* the request.
* @throws ParserConfigurationException Thrown if there was an error
* configuring the parser for the response body.
* @throws SAXException Thrown if there was an error parsing the response
* body.
* @throws TransformerException Thrown if there was an error creating the
* DOM transformer.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return Parameters returned from the Create Virtual Machine Image
* operation.
*/
@Override
public VirtualMachineOSImageUpdateResponse update(String imageName,
        VirtualMachineOSImageUpdateParameters parameters)
        throws InterruptedException, ExecutionException, ServiceException, IOException,
        ParserConfigurationException, SAXException, TransformerException, URISyntaxException {
    // Validate
    if (imageName == null) {
        throw new NullPointerException("imageName");
    }
    if (parameters == null) {
        throw new NullPointerException("parameters");
    }
    if (parameters.getLabel() == null) {
        throw new NullPointerException("parameters.Label");
    }

    // 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("imageName", imageName);
        tracingParameters.put("parameters", parameters);
        CloudTracing.enter(invocationId, this, "updateAsync", 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/images/";
    url = url + URLEncoder.encode(imageName, "UTF-8");
    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
    HttpPut httpRequest = new HttpPut(url);

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

    // Serialize Request
    String requestContent = null;
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document requestDoc = documentBuilder.newDocument();

    Element oSImageElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "OSImage");
    requestDoc.appendChild(oSImageElement);

    Element labelElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Label");
    labelElement.appendChild(requestDoc.createTextNode(parameters.getLabel()));
    oSImageElement.appendChild(labelElement);

    if (parameters.getEula() != null) {
        Element eulaElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Eula");
        eulaElement.appendChild(requestDoc.createTextNode(parameters.getEula()));
        oSImageElement.appendChild(eulaElement);
    }

    if (parameters.getDescription() != null) {
        Element descriptionElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
                "Description");
        descriptionElement.appendChild(requestDoc.createTextNode(parameters.getDescription()));
        oSImageElement.appendChild(descriptionElement);
    }

    if (parameters.getImageFamily() != null) {
        Element imageFamilyElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
                "ImageFamily");
        imageFamilyElement.appendChild(requestDoc.createTextNode(parameters.getImageFamily()));
        oSImageElement.appendChild(imageFamilyElement);
    }

    if (parameters.isShowInGui() != null) {
        Element showInGuiElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
                "ShowInGui");
        showInGuiElement.appendChild(
                requestDoc.createTextNode(Boolean.toString(parameters.isShowInGui()).toLowerCase()));
        oSImageElement.appendChild(showInGuiElement);
    }

    if (parameters.getPublishedDate() != null) {
        Element publishedDateElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
                "PublishedDate");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'");
        simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
        publishedDateElement.appendChild(
                requestDoc.createTextNode(simpleDateFormat.format(parameters.getPublishedDate().getTime())));
        oSImageElement.appendChild(publishedDateElement);
    }

    if (parameters.isPremium() != null) {
        Element isPremiumElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
                "IsPremium");
        isPremiumElement
                .appendChild(requestDoc.createTextNode(Boolean.toString(parameters.isPremium()).toLowerCase()));
        oSImageElement.appendChild(isPremiumElement);
    }

    if (parameters.getPrivacyUri() != null) {
        Element privacyUriElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
                "PrivacyUri");
        privacyUriElement.appendChild(requestDoc.createTextNode(parameters.getPrivacyUri().toString()));
        oSImageElement.appendChild(privacyUriElement);
    }

    if (parameters.getIconUri() != null) {
        Element iconUriElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
                "IconUri");
        iconUriElement.appendChild(requestDoc.createTextNode(parameters.getIconUri()));
        oSImageElement.appendChild(iconUriElement);
    }

    if (parameters.getRecommendedVMSize() != null) {
        Element recommendedVMSizeElement = requestDoc
                .createElementNS("http://schemas.microsoft.com/windowsazure", "RecommendedVMSize");
        recommendedVMSizeElement.appendChild(requestDoc.createTextNode(parameters.getRecommendedVMSize()));
        oSImageElement.appendChild(recommendedVMSizeElement);
    }

    if (parameters.getSmallIconUri() != null) {
        Element smallIconUriElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
                "SmallIconUri");
        smallIconUriElement.appendChild(requestDoc.createTextNode(parameters.getSmallIconUri()));
        oSImageElement.appendChild(smallIconUriElement);
    }

    if (parameters.getLanguage() != null) {
        Element languageElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
                "Language");
        languageElement.appendChild(requestDoc.createTextNode(parameters.getLanguage()));
        oSImageElement.appendChild(languageElement);
    }

    DOMSource domSource = new DOMSource(requestDoc);
    StringWriter stringWriter = new StringWriter();
    StreamResult streamResult = new StreamResult(stringWriter);
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.transform(domSource, streamResult);
    requestContent = stringWriter.toString();
    StringEntity entity = new StringEntity(requestContent);
    httpRequest.setEntity(entity);
    httpRequest.setHeader("Content-Type", "application/xml");

    // 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, requestContent, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

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

            Element oSImageElement2 = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "OSImage");
            if (oSImageElement2 != null) {
                Element locationElement = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "Location");
                if (locationElement != null) {
                    String locationInstance;
                    locationInstance = locationElement.getTextContent();
                    result.setLocation(locationInstance);
                }

                Element categoryElement = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "Category");
                if (categoryElement != null) {
                    String categoryInstance;
                    categoryInstance = categoryElement.getTextContent();
                    result.setCategory(categoryInstance);
                }

                Element labelElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "Label");
                if (labelElement2 != null) {
                    String labelInstance;
                    labelInstance = labelElement2.getTextContent();
                    result.setLabel(labelInstance);
                }

                Element logicalSizeInGBElement = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "LogicalSizeInGB");
                if (logicalSizeInGBElement != null) {
                    double logicalSizeInGBInstance;
                    logicalSizeInGBInstance = DatatypeConverter
                            .parseDouble(logicalSizeInGBElement.getTextContent());
                    result.setLogicalSizeInGB(logicalSizeInGBInstance);
                }

                Element mediaLinkElement = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "MediaLink");
                if (mediaLinkElement != null) {
                    URI mediaLinkInstance;
                    mediaLinkInstance = new URI(mediaLinkElement.getTextContent());
                    result.setMediaLinkUri(mediaLinkInstance);
                }

                Element nameElement = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "Name");
                if (nameElement != null) {
                    String nameInstance;
                    nameInstance = nameElement.getTextContent();
                    result.setName(nameInstance);
                }

                Element osElement = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "OS");
                if (osElement != null) {
                    String osInstance;
                    osInstance = osElement.getTextContent();
                    result.setOperatingSystemType(osInstance);
                }

                Element eulaElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "Eula");
                if (eulaElement2 != null) {
                    String eulaInstance;
                    eulaInstance = eulaElement2.getTextContent();
                    result.setEula(eulaInstance);
                }

                Element descriptionElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "Description");
                if (descriptionElement2 != null) {
                    String descriptionInstance;
                    descriptionInstance = descriptionElement2.getTextContent();
                    result.setDescription(descriptionInstance);
                }

                Element imageFamilyElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "ImageFamily");
                if (imageFamilyElement2 != null) {
                    String imageFamilyInstance;
                    imageFamilyInstance = imageFamilyElement2.getTextContent();
                    result.setImageFamily(imageFamilyInstance);
                }

                Element publishedDateElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "PublishedDate");
                if (publishedDateElement2 != null && publishedDateElement2.getTextContent() != null
                        && !publishedDateElement2.getTextContent().isEmpty()) {
                    Calendar publishedDateInstance;
                    publishedDateInstance = DatatypeConverter
                            .parseDateTime(publishedDateElement2.getTextContent());
                    result.setPublishedDate(publishedDateInstance);
                }

                Element publisherNameElement = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "PublisherName");
                if (publisherNameElement != null) {
                    String publisherNameInstance;
                    publisherNameInstance = publisherNameElement.getTextContent();
                    result.setPublisherName(publisherNameInstance);
                }

                Element isPremiumElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "IsPremium");
                if (isPremiumElement2 != null && isPremiumElement2.getTextContent() != null
                        && !isPremiumElement2.getTextContent().isEmpty()) {
                    boolean isPremiumInstance;
                    isPremiumInstance = DatatypeConverter
                            .parseBoolean(isPremiumElement2.getTextContent().toLowerCase());
                    result.setIsPremium(isPremiumInstance);
                }

                Element showInGuiElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "ShowInGui");
                if (showInGuiElement2 != null && showInGuiElement2.getTextContent() != null
                        && !showInGuiElement2.getTextContent().isEmpty()) {
                    boolean showInGuiInstance;
                    showInGuiInstance = DatatypeConverter
                            .parseBoolean(showInGuiElement2.getTextContent().toLowerCase());
                    result.setShowInGui(showInGuiInstance);
                }

                Element privacyUriElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "PrivacyUri");
                if (privacyUriElement2 != null) {
                    URI privacyUriInstance;
                    privacyUriInstance = new URI(privacyUriElement2.getTextContent());
                    result.setPrivacyUri(privacyUriInstance);
                }

                Element iconUriElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "IconUri");
                if (iconUriElement2 != null) {
                    String iconUriInstance;
                    iconUriInstance = iconUriElement2.getTextContent();
                    result.setIconUri(iconUriInstance);
                }

                Element recommendedVMSizeElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "RecommendedVMSize");
                if (recommendedVMSizeElement2 != null) {
                    String recommendedVMSizeInstance;
                    recommendedVMSizeInstance = recommendedVMSizeElement2.getTextContent();
                    result.setRecommendedVMSize(recommendedVMSizeInstance);
                }

                Element smallIconUriElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "SmallIconUri");
                if (smallIconUriElement2 != null) {
                    String smallIconUriInstance;
                    smallIconUriInstance = smallIconUriElement2.getTextContent();
                    result.setSmallIconUri(smallIconUriInstance);
                }

                Element languageElement2 = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "Language");
                if (languageElement2 != null) {
                    String languageInstance;
                    languageInstance = languageElement2.getTextContent();
                    result.setLanguage(languageInstance);
                }

                Element iOTypeElement = XmlUtility.getElementByTagNameNS(oSImageElement2,
                        "http://schemas.microsoft.com/windowsazure", "IOType");
                if (iOTypeElement != null) {
                    String iOTypeInstance;
                    iOTypeInstance = iOTypeElement.getTextContent();
                    result.setIOType(iOTypeInstance);
                }
            }

        }
        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.kalypso.service.wps.client.WPSRequest.java

/**
 * Collects the process output.<br>
 * <br>/*from ww  w  .j  a v  a2  s  . c  o  m*/
 * <ol>
 * <li>All files (ComplexValueReference) will be collected with their id.</li>
 * <li>All literals (LiteralValueType) will be collected with their id.</li>
 * <li>All bounding boxes (BoundingBoxType) will be collected with their id.</li>
 * <li>All complex datas (ComplexDataType) will be collected with their id.</li>
 * </ol>
 * 
 * @param processOutputs
 *          The process outputs contains the info of the results, which are to be collected.
 */
private void collectOutput(final ExecuteResponseType.ProcessOutputs processOutputs) {
    // TODO: maybe check, if all desired outputs have been created??

    /* Collect all data for the client. */
    final List<IOValueType> ioValues = processOutputs.getOutput();
    for (final IOValueType ioValue : ioValues) {
        /* Complex value reference. */
        final ComplexValueReference complexValueReference = ioValue.getComplexValueReference();
        if (complexValueReference != null) {
            m_references.put(ioValue.getIdentifier().getValue(), complexValueReference);
            continue;
        }

        /* Literal value type. */
        final LiteralValueType literalValue = ioValue.getLiteralValue();
        if (literalValue != null) {
            final String value = literalValue.getValue();
            final String dataType = literalValue.getDataType();

            Object result = null;
            if ("string".equals(dataType)) //$NON-NLS-1$
            {
                result = DatatypeConverter.parseString(value);
            } else if ("int".equals(dataType)) //$NON-NLS-1$
            {
                result = DatatypeConverter.parseInt(value);
            } else if ("double".equals(dataType)) //$NON-NLS-1$
            {
                result = DatatypeConverter.parseDouble(value);
            } else if ("boolean".equals(dataType)) //$NON-NLS-1$
            {
                result = DatatypeConverter.parseBoolean(value);
            }

            if (result != null) {
                if (m_literals == null) {
                    m_literals = new LinkedHashMap<>();
                }

                m_literals.put(ioValue.getIdentifier().getValue(), result);
            }

            continue;
        }

        /* Bounding box type. */
        final BoundingBoxType boundingBox = ioValue.getBoundingBoxValue();
        if (boundingBox != null) {
            if (m_boundingBoxes == null)
                m_boundingBoxes = new LinkedHashMap<>();

            m_boundingBoxes.put(ioValue.getIdentifier().getValue(), boundingBox);

            continue;
        }

        /* Complex value type. */
        final ComplexValueType complexValue = ioValue.getComplexValue();
        if (complexValue != null) {
            if (m_complexValues == null)
                m_complexValues = new LinkedHashMap<>();

            m_complexValues.put(ioValue.getIdentifier().getValue(), complexValue);

            continue;
        }
    }
}

From source file:org.kalypso.service.wps.refactoring.DefaultWPSProcess.java

private static Object parseValue(final String value, final String dataType) {
    if ("string".equals(dataType)) //$NON-NLS-1$
        return DatatypeConverter.parseString(value);

    if ("int".equals(dataType)) //$NON-NLS-1$
        return DatatypeConverter.parseInt(value);

    if ("double".equals(dataType)) //$NON-NLS-1$
        return DatatypeConverter.parseDouble(value);

    if ("boolean".equals(dataType)) //$NON-NLS-1$
        return DatatypeConverter.parseBoolean(value);

    throw new UnsupportedOperationException("Unknown result type: " + dataType); //$NON-NLS-1$
}

From source file:org.kalypsodeegree_impl.graphics.sld.SLDFactory.java

private static ShadedRelief createShadedRelief(final Element element) {
    if (element == null)
        return null;

    final String brightnessOnlyString = XMLTools.getStringValue("BrightnessOnly", NS.SLD, element, null);
    final Boolean brightnessOnly = brightnessOnlyString == null ? null
            : DatatypeConverter.parseBoolean(brightnessOnlyString);

    final String reliefFactorString = XMLTools.getStringValue("ReliefFactor", NS.SLD, element, null);
    final Double reliefFactor = reliefFactorString == null ? null
            : DatatypeConverter.parseDouble(reliefFactorString);

    return new ShadedRelief(brightnessOnly, reliefFactor);
}

From source file:org.openestate.io.openimmo.converters.OpenImmo_1_2_0.java

/**
 * Downgrade &lt;mieteinnahmen_ist&gt;, &lt;mieteinnahmen_soll&gt; elements
 * to OpenImmo 1.1.//w w  w  . ja va 2  s . c o m
 * <p>
 * The "periode" attribute of the &lt;mieteinnahmen_ist&gt; and
 * &lt;mieteinnahmen_soll&gt; elements is not available in version 1.1.
 * <p>
 * Any occurences of these values is removed.
 * <p>
 * The numeric value within the &lt;mieteinnahmen_ist&gt; and
 * &lt;mieteinnahmen_soll&gt; elements is converted according to the value of
 * the "periode" attribute.
 *
 * @param doc OpenImmo document in version 1.2.0
 * @throws JaxenException
 */
protected void downgradeMieteinnahmenElements(Document doc) throws JaxenException {
    List nodes = XmlUtils
            .newXPath(
                    "/io:openimmo/io:anbieter/io:immobilie/io:preise/io:mieteinnahmen_ist[@periode] |"
                            + "/io:openimmo/io:anbieter/io:immobilie/io:preise/io:mieteinnahmen_soll[@periode]",
                    doc)
            .selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;

        String value = StringUtils.trimToNull(node.getTextContent());
        Double numericValue = null;
        try {
            numericValue = (value != null) ? DatatypeConverter.parseDouble(value) : null;
        } catch (Exception ex) {
            String tagName = node.getTagName();
            LOGGER.warn("Can't parse <" + tagName + ">" + value + "</" + tagName + "> as number!");
            LOGGER.warn("> " + ex.getLocalizedMessage(), ex);
        }

        if (numericValue != null && numericValue > 0) {
            String periode = StringUtils.trimToNull(node.getAttribute("periode"));
            if ("MONAT".equalsIgnoreCase(periode)) {
                node.setTextContent(DatatypeConverter.printDouble(numericValue * 12));
            } else if ("WOCHE".equalsIgnoreCase(periode)) {
                node.setTextContent(DatatypeConverter.printDouble(numericValue * 52));
            } else if ("TAG".equalsIgnoreCase(periode)) {
                node.setTextContent(DatatypeConverter.printDouble(numericValue * 365));
            }
        }

        node.removeAttribute("periode");
    }
}