List of usage examples for org.w3c.dom Document createTextNode
public Text createTextNode(String data);
Text
node given the specified string. From source file:com.microsoft.windowsazure.management.websites.WebHostingPlanOperationsImpl.java
/** * Updates an existing Web Hosting Plan. (see * http://azure.microsoft.com/en-us/documentation/articles/azure-web-sites-web-hosting-plans-in-depth-overview/ * for more information)/*from w w w.j ava 2 s. co m*/ * * @param webSpaceName Required. The name of the web space. * @param webHostingPlanName Required. The name of the web hosting plan. * @param parameters Required. Parameters supplied to the Update Web Hosting * Plan operation. * @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 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 URISyntaxException Thrown if there was an error parsing a URI in * the response. * @return The Create Web Hosting Plan operation response. */ @Override public WebHostingPlanUpdateResponse update(String webSpaceName, String webHostingPlanName, WebHostingPlanUpdateParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException, URISyntaxException { // Validate if (webSpaceName == null) { throw new NullPointerException("webSpaceName"); } if (webHostingPlanName == null) { throw new NullPointerException("webHostingPlanName"); } if (parameters == null) { throw new NullPointerException("parameters"); } // 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("webSpaceName", webSpaceName); tracingParameters.put("webHostingPlanName", webHostingPlanName); 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/WebSpaces/"; url = url + URLEncoder.encode(webSpaceName, "UTF-8"); url = url + "/ServerFarms/"; url = url + URLEncoder.encode(webHostingPlanName, "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", "2014-04-01"); // Serialize Request String requestContent = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document requestDoc = documentBuilder.newDocument(); Element serverFarmElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "ServerFarm"); requestDoc.appendChild(serverFarmElement); if (parameters.getNumberOfWorkers() != null) { Element numberOfWorkersElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "NumberOfWorkers"); numberOfWorkersElement .appendChild(requestDoc.createTextNode(Integer.toString(parameters.getNumberOfWorkers()))); serverFarmElement.appendChild(numberOfWorkersElement); } if (parameters.getSKU() != null) { Element sKUElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "SKU"); sKUElement.appendChild(requestDoc.createTextNode(parameters.getSKU().toString())); serverFarmElement.appendChild(sKUElement); } if (parameters.getWorkerSize() != null) { Element workerSizeElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "WorkerSize"); workerSizeElement.appendChild(requestDoc.createTextNode(parameters.getWorkerSize().toString())); serverFarmElement.appendChild(workerSizeElement); } if (parameters.getAdminSiteName() != null) { Element adminSiteNameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "AdminSiteName"); adminSiteNameElement.appendChild(requestDoc.createTextNode(parameters.getAdminSiteName())); serverFarmElement.appendChild(adminSiteNameElement); } 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 WebHostingPlanUpdateResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebHostingPlanUpdateResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element serverFarmElement2 = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ServerFarm"); if (serverFarmElement2 != null) { WebHostingPlan webHostingPlanInstance = new WebHostingPlan(); result.setWebHostingPlan(webHostingPlanInstance); Element nameElement = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); webHostingPlanInstance.setName(nameInstance); } Element numberOfWorkersElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "NumberOfWorkers"); if (numberOfWorkersElement2 != null && numberOfWorkersElement2.getTextContent() != null && !numberOfWorkersElement2.getTextContent().isEmpty()) { int numberOfWorkersInstance; numberOfWorkersInstance = DatatypeConverter .parseInt(numberOfWorkersElement2.getTextContent()); webHostingPlanInstance.setNumberOfWorkers(numberOfWorkersInstance); } Element sKUElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "SKU"); if (sKUElement2 != null && sKUElement2.getTextContent() != null && !sKUElement2.getTextContent().isEmpty()) { SkuOptions sKUInstance; sKUInstance = SkuOptions.valueOf(sKUElement2.getTextContent()); webHostingPlanInstance.setSKU(sKUInstance); } Element workerSizeElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "WorkerSize"); if (workerSizeElement2 != null && workerSizeElement2.getTextContent() != null && !workerSizeElement2.getTextContent().isEmpty()) { WorkerSizeOptions workerSizeInstance; workerSizeInstance = WorkerSizeOptions.valueOf(workerSizeElement2.getTextContent()); webHostingPlanInstance.setWorkerSize(workerSizeInstance); } Element adminSiteNameElement2 = XmlUtility.getElementByTagNameNS(serverFarmElement2, "http://schemas.microsoft.com/windowsazure", "AdminSiteName"); if (adminSiteNameElement2 != null) { String adminSiteNameInstance; adminSiteNameInstance = adminSiteNameElement2.getTextContent(); webHostingPlanInstance.setAdminSiteName(adminSiteNameInstance); } } } 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:gov.nih.nci.ncicb.tcga.dcc.qclive.common.action.ClinicalDateObscurer.java
/** * Creates a new DOM element which name starts with the <code>elapsedElementBase</code> value * and ends with the given <code>elementName</code>. This element will also have the following attributes * with the values for these attributes provided in the method arguments * * Note://from ww w . j a v a2 s. c o m * The org.w3c.dom API does not care in what order the attributes are added to a Node, * and the resulting DOM Document will display the attributes in alpabetical order, based * on the attribute's name * * @param document the document being modified * @param elementNamePrefix the prefix of the element name * @param elementNameSuffix the suffix of the element name * @param elementValue the value for the element created * @param cdeAttributeValue the value for the <code>CDE</code> attribute * @param ownerAttributeValue the value for the <code>OWNER</code> attribute * @param procurementStatusAttributeValue the value for the <code>PROCUREMENT_STATUS</code> attribute * @param tierAttributeValue the value for the <code>TIER</code> attribute * @param xsdVerAttributeValue the value for the <code>XSD_VER</code> attribute * @param precisionAttributeValue the value of the <code>PRECISION</code> attribute * @param floored <code>true</code> if the value has been floored, <code>false</code> otherwise * @return the new DOM element */ private Node createElementNode(final Document document, final String elementNamePrefix, final String elementNameSuffix, final String elementValue, final String cdeAttributeValue, final String ownerAttributeValue, final String procurementStatusAttributeValue, final String tierAttributeValue, final String xsdVerAttributeValue, final String precisionAttributeValue, final boolean floored) { //Create the Element final Element result = document.createElement(elementNamePrefix + elementNameSuffix); //Set Element value if (elementValue != null) { final Text textNode = document.createTextNode(elementValue); result.appendChild(textNode); } //Set cde attribute result.setAttribute(CDE, cdeAttributeValue); //Set procurement_status attribute if (procurementStatusAttributeValue != null) { result.setAttribute(PROCUREMENT_STATUS, procurementStatusAttributeValue); } //Set owner attribute if (ownerAttributeValue != null) { result.setAttribute(OWNER, ownerAttributeValue); } //Set xsd_ver attribute result.setAttribute(XSD_VER, xsdVerAttributeValue); //Set tier attribute // //Note: this attribute is not allowed for the element 'DAYSTOCOLLECTION', according to the 'intgen.org_TCGA_ver1_17.xsd' schema //so if the attribute value provided is null it will not be added if (tierAttributeValue != null) { result.setAttribute(TIER, tierAttributeValue); } //Set precision attribute // //Note: this attribute is optional, according to the 'intgen.org_TCGA_ver1_17.xsd' schema //so if if the attribute value provided is null or empty, it will not be added if (precisionAttributeValue != null && precisionAttributeValue.length() > 0) { result.setAttribute(PRECISION, precisionAttributeValue); } //Add an attribute that indicate if the element's value has been floored if (floored) { result.setAttribute(FLOORED, "true"); } return result; }
From source file:org.structr.web.entity.dom.DOMNode.java
@Override public final void normalize() { Document document = getOwnerDocument(); if (document != null) { // merge adjacent text nodes until there is only one left Node child = getFirstChild(); while (child != null) { if (child instanceof Text) { Node next = child.getNextSibling(); if (next != null && next instanceof Text) { String text1 = child.getNodeValue(); String text2 = next.getNodeValue(); // create new text node Text newText = document.createTextNode(text1.concat(text2)); removeChild(child);//from w ww.j a v a2s .c om insertBefore(newText, next); removeChild(next); child = newText; } else { // advance to next node child = next; } } else { // advance to next node child = child.getNextSibling(); } } // recursively normalize child nodes if (hasChildNodes()) { Node currentChild = getFirstChild(); while (currentChild != null) { currentChild.normalize(); currentChild = currentChild.getNextSibling(); } } } }
From source file:com.glaf.core.config.Configuration.java
/** * Return the XML DOM corresponding to this Configuration. *//* w w w . ja v a 2 s . co m*/ private synchronized Document asXmlDocument() throws IOException { Document doc; try { doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); } catch (ParserConfigurationException pe) { throw new IOException(pe); } Element conf = doc.createElement("configuration"); doc.appendChild(conf); conf.appendChild(doc.createTextNode("\n")); for (Enumeration<Object> e = properties.keys(); e.hasMoreElements();) { String name = (String) e.nextElement(); Object object = properties.get(name); String value = null; if (object instanceof String) { value = (String) object; } else { continue; } Element propNode = doc.createElement("property"); conf.appendChild(propNode); Element nameNode = doc.createElement("name"); nameNode.appendChild(doc.createTextNode(name)); propNode.appendChild(nameNode); Element valueNode = doc.createElement("value"); valueNode.appendChild(doc.createTextNode(value)); propNode.appendChild(valueNode); if (updatingResource != null) { String[] sources = updatingResource.get(name); if (sources != null) { for (String s : sources) { Element sourceNode = doc.createElement("source"); sourceNode.appendChild(doc.createTextNode(s)); propNode.appendChild(sourceNode); } } } conf.appendChild(doc.createTextNode("\n")); } return doc; }
From source file:com.microsoft.windowsazure.management.scheduler.JobCollectionOperationsImpl.java
/** * Create a job collection./*from w ww. j a v a2 s . c om*/ * * @param cloudServiceName Required. The name of the cloud service * containing the job collection. * @param jobCollectionName Required. The name of the job collection to * create. * @param parameters Required. Parameters supplied to the Create Job * Collection operation. * @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 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. * @return The Create Job Collection operation response. */ @Override public JobCollectionCreateResponse beginCreating(String cloudServiceName, String jobCollectionName, JobCollectionCreateParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException { // Validate if (cloudServiceName == null) { throw new NullPointerException("cloudServiceName"); } if (jobCollectionName == null) { throw new NullPointerException("jobCollectionName"); } if (jobCollectionName.length() > 100) { throw new IllegalArgumentException("jobCollectionName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getIntrinsicSettings() != null) { if (parameters.getIntrinsicSettings().getQuota() != null) { if (parameters.getIntrinsicSettings().getQuota().getMaxRecurrence() != null) { if (parameters.getIntrinsicSettings().getQuota().getMaxRecurrence().getFrequency() == null) { throw new NullPointerException( "parameters.IntrinsicSettings.Quota.MaxRecurrence.Frequency"); } } } } // 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("cloudServiceName", cloudServiceName); tracingParameters.put("jobCollectionName", jobCollectionName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "beginCreatingAsync", tracingParameters); } // Construct URL String url = ""; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/cloudservices/"; url = url + URLEncoder.encode(cloudServiceName, "UTF-8"); url = url + "/resources/"; url = url + "scheduler"; url = url + "/"; url = url + "JobCollections"; url = url + "/"; url = url + URLEncoder.encode(jobCollectionName, "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", "2013-03-01"); // Serialize Request String requestContent = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document requestDoc = documentBuilder.newDocument(); Element resourceElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Resource"); requestDoc.appendChild(resourceElement); if (parameters.getSchemaVersion() != null) { Element schemaVersionElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "SchemaVersion"); schemaVersionElement.appendChild(requestDoc.createTextNode(parameters.getSchemaVersion())); resourceElement.appendChild(schemaVersionElement); } if (parameters.getIntrinsicSettings() != null) { Element intrinsicSettingsElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "IntrinsicSettings"); resourceElement.appendChild(intrinsicSettingsElement); if (parameters.getIntrinsicSettings().getPlan() != null) { Element planElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Plan"); planElement.appendChild( requestDoc.createTextNode(parameters.getIntrinsicSettings().getPlan().toString())); intrinsicSettingsElement.appendChild(planElement); } if (parameters.getIntrinsicSettings().getQuota() != null) { Element quotaElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Quota"); intrinsicSettingsElement.appendChild(quotaElement); if (parameters.getIntrinsicSettings().getQuota().getMaxJobCount() != null) { Element maxJobCountElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "MaxJobCount"); maxJobCountElement.appendChild(requestDoc.createTextNode( Integer.toString(parameters.getIntrinsicSettings().getQuota().getMaxJobCount()))); quotaElement.appendChild(maxJobCountElement); } if (parameters.getIntrinsicSettings().getQuota().getMaxJobOccurrence() != null) { Element maxJobOccurrenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "MaxJobOccurrence"); maxJobOccurrenceElement.appendChild(requestDoc.createTextNode( Integer.toString(parameters.getIntrinsicSettings().getQuota().getMaxJobOccurrence()))); quotaElement.appendChild(maxJobOccurrenceElement); } if (parameters.getIntrinsicSettings().getQuota().getMaxRecurrence() != null) { Element maxRecurrenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "MaxRecurrence"); quotaElement.appendChild(maxRecurrenceElement); Element frequencyElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Frequency"); frequencyElement.appendChild(requestDoc.createTextNode(parameters.getIntrinsicSettings() .getQuota().getMaxRecurrence().getFrequency().toString())); maxRecurrenceElement.appendChild(frequencyElement); Element intervalElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Interval"); intervalElement.appendChild(requestDoc.createTextNode(Integer.toString( parameters.getIntrinsicSettings().getQuota().getMaxRecurrence().getInterval()))); maxRecurrenceElement.appendChild(intervalElement); } } } if (parameters.getLabel() != null) { Element labelElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Label"); labelElement.appendChild(requestDoc.createTextNode(Base64.encode(parameters.getLabel().getBytes()))); resourceElement.appendChild(labelElement); } 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_ACCEPTED) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result JobCollectionCreateResponse result = null; // Deserialize Response result = new JobCollectionCreateResponse(); result.setStatusCode(statusCode); if (httpResponse.getHeaders("ETag").length > 0) { result.setETag(httpResponse.getFirstHeader("ETag").getValue()); } 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:co.cask.cdap.common.conf.Configuration.java
/** * Return the XML DOM corresponding to this Configuration. *//*from w w w .j av a2 s. c om*/ private synchronized Document asXmlDocument() throws IOException { Document doc; try { doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); } catch (ParserConfigurationException pe) { throw new IOException(pe); } Element conf = doc.createElement("configuration"); doc.appendChild(conf); conf.appendChild(doc.createTextNode("\n")); handleDeprecation(); //ensure properties is set and deprecation is handled for (Enumeration e = properties.keys(); e.hasMoreElements();) { String name = (String) e.nextElement(); Object object = properties.get(name); String value = null; if (object instanceof String) { value = (String) object; } else { continue; } Element propNode = doc.createElement("property"); conf.appendChild(propNode); if (updatingResource != null) { Comment commentNode = doc.createComment("Loaded from " + updatingResource.get(name)); propNode.appendChild(commentNode); } Element nameNode = doc.createElement("name"); nameNode.appendChild(doc.createTextNode(name)); propNode.appendChild(nameNode); Element valueNode = doc.createElement("value"); valueNode.appendChild(doc.createTextNode(value)); propNode.appendChild(valueNode); conf.appendChild(doc.createTextNode("\n")); } return doc; }
From source file:com.microsoft.windowsazure.management.scheduler.JobCollectionOperationsImpl.java
/** * Update a job collection.// w ww . j a v a 2s . co m * * @param cloudServiceName Required. The name of the cloud service * containing the job collection. * @param jobCollectionName Required. The name of the job collection to * update. * @param parameters Required. Parameters supplied to the Update Job * Collection operation. * @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 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. * @return The Update Job Collection operation response. */ @Override public JobCollectionUpdateResponse beginUpdating(String cloudServiceName, String jobCollectionName, JobCollectionUpdateParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException { // Validate if (cloudServiceName == null) { throw new NullPointerException("cloudServiceName"); } if (jobCollectionName == null) { throw new NullPointerException("jobCollectionName"); } if (jobCollectionName.length() > 100) { throw new IllegalArgumentException("jobCollectionName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getETag() == null) { throw new NullPointerException("parameters.ETag"); } if (parameters.getIntrinsicSettings() != null) { if (parameters.getIntrinsicSettings().getQuota() != null) { if (parameters.getIntrinsicSettings().getQuota().getMaxRecurrence() != null) { if (parameters.getIntrinsicSettings().getQuota().getMaxRecurrence().getFrequency() == null) { throw new NullPointerException( "parameters.IntrinsicSettings.Quota.MaxRecurrence.Frequency"); } } } } // 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("cloudServiceName", cloudServiceName); tracingParameters.put("jobCollectionName", jobCollectionName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "beginUpdatingAsync", tracingParameters); } // Construct URL String url = ""; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/cloudservices/"; url = url + URLEncoder.encode(cloudServiceName, "UTF-8"); url = url + "/resources/"; url = url + "scheduler"; url = url + "/"; url = url + "JobCollections"; url = url + "/"; url = url + URLEncoder.encode(jobCollectionName, "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("If-Match", parameters.getETag()); httpRequest.setHeader("x-ms-version", "2013-03-01"); // Serialize Request String requestContent = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document requestDoc = documentBuilder.newDocument(); Element resourceElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Resource"); requestDoc.appendChild(resourceElement); if (parameters.getSchemaVersion() != null) { Element schemaVersionElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "SchemaVersion"); schemaVersionElement.appendChild(requestDoc.createTextNode(parameters.getSchemaVersion())); resourceElement.appendChild(schemaVersionElement); } Element eTagElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "ETag"); resourceElement.appendChild(eTagElement); if (parameters.getIntrinsicSettings() != null) { Element intrinsicSettingsElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "IntrinsicSettings"); resourceElement.appendChild(intrinsicSettingsElement); if (parameters.getIntrinsicSettings().getPlan() != null) { Element planElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Plan"); planElement.appendChild( requestDoc.createTextNode(parameters.getIntrinsicSettings().getPlan().toString())); intrinsicSettingsElement.appendChild(planElement); } if (parameters.getIntrinsicSettings().getQuota() != null) { Element quotaElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Quota"); intrinsicSettingsElement.appendChild(quotaElement); if (parameters.getIntrinsicSettings().getQuota().getMaxJobCount() != null) { Element maxJobCountElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "MaxJobCount"); maxJobCountElement.appendChild(requestDoc.createTextNode( Integer.toString(parameters.getIntrinsicSettings().getQuota().getMaxJobCount()))); quotaElement.appendChild(maxJobCountElement); } if (parameters.getIntrinsicSettings().getQuota().getMaxJobOccurrence() != null) { Element maxJobOccurrenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "MaxJobOccurrence"); maxJobOccurrenceElement.appendChild(requestDoc.createTextNode( Integer.toString(parameters.getIntrinsicSettings().getQuota().getMaxJobOccurrence()))); quotaElement.appendChild(maxJobOccurrenceElement); } if (parameters.getIntrinsicSettings().getQuota().getMaxRecurrence() != null) { Element maxRecurrenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "MaxRecurrence"); quotaElement.appendChild(maxRecurrenceElement); Element frequencyElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Frequency"); frequencyElement.appendChild(requestDoc.createTextNode(parameters.getIntrinsicSettings() .getQuota().getMaxRecurrence().getFrequency().toString())); maxRecurrenceElement.appendChild(frequencyElement); Element intervalElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Interval"); intervalElement.appendChild(requestDoc.createTextNode(Integer.toString( parameters.getIntrinsicSettings().getQuota().getMaxRecurrence().getInterval()))); maxRecurrenceElement.appendChild(intervalElement); } } } if (parameters.getLabel() != null) { Element labelElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Label"); labelElement.appendChild(requestDoc.createTextNode(Base64.encode(parameters.getLabel().getBytes()))); resourceElement.appendChild(labelElement); } 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_ACCEPTED) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result JobCollectionUpdateResponse result = null; // Deserialize Response result = new JobCollectionUpdateResponse(); result.setStatusCode(statusCode); if (httpResponse.getHeaders("ETag").length > 0) { result.setETag(httpResponse.getFirstHeader("ETag").getValue()); } 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.network.ReservedIPOperationsImpl.java
/** * The Begin Creating Reserved IP operation creates a reserved IP from your * the subscription./*from w w w . j a va 2 s . co m*/ * * @param parameters Required. Parameters supplied to the Begin Creating * Reserved IP operation. * @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 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. * @return The response body contains the status of the specified * asynchronous operation, indicating whether it has succeeded, is * inprogress, or has failed. Note that this status is distinct from the * HTTP status code returned for the Get Operation Status operation itself. * If the asynchronous operation succeeded, the response body includes the * HTTP status code for the successful request. If the asynchronous * operation failed, the response body includes the HTTP status code for * the failed request, and also includes error information regarding the * failure. */ @Override public OperationStatusResponse beginCreating(NetworkReservedIPCreateParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException { // Validate if (parameters == null) { throw new NullPointerException("parameters"); } // 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, "beginCreatingAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/networking/reservedips"; 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 reservedIPElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "ReservedIP"); requestDoc.appendChild(reservedIPElement); if (parameters.getName() != null) { Element nameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement.appendChild(requestDoc.createTextNode(parameters.getName())); reservedIPElement.appendChild(nameElement); } if (parameters.getLabel() != null) { Element labelElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Label"); labelElement.appendChild(requestDoc.createTextNode(parameters.getLabel())); reservedIPElement.appendChild(labelElement); } if (parameters.getServiceName() != null) { Element serviceNameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "ServiceName"); serviceNameElement.appendChild(requestDoc.createTextNode(parameters.getServiceName())); reservedIPElement.appendChild(serviceNameElement); } if (parameters.getDeploymentName() != null) { Element deploymentNameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "DeploymentName"); deploymentNameElement.appendChild(requestDoc.createTextNode(parameters.getDeploymentName())); reservedIPElement.appendChild(deploymentNameElement); } if (parameters.getLocation() != null) { Element locationElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Location"); locationElement.appendChild(requestDoc.createTextNode(parameters.getLocation())); reservedIPElement.appendChild(locationElement); } if (parameters.getVirtualIPName() != null) { Element virtualIPNameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "VirtualIPName"); virtualIPNameElement.appendChild(requestDoc.createTextNode(parameters.getVirtualIPName())); reservedIPElement.appendChild(virtualIPNameElement); } 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_ACCEPTED) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result OperationStatusResponse result = null; // Deserialize Response result = new OperationStatusResponse(); 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.sql.DatabaseCopyOperationsImpl.java
/** * Starts a SQL Server database copy./*from w w w. ja v a2 s .c o m*/ * * @param serverName Required. The name of the SQL Server where the source * database resides. * @param databaseName Required. The name of the source database. * @param parameters Required. The additional parameters for the create * database copy operation. * @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 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. * @return Represents a response to the create request. */ @Override public DatabaseCopyCreateResponse create(String serverName, String databaseName, DatabaseCopyCreateParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException { // Validate if (serverName == null) { throw new NullPointerException("serverName"); } if (databaseName == null) { throw new NullPointerException("databaseName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getPartnerDatabase() == null) { throw new NullPointerException("parameters.PartnerDatabase"); } if (parameters.getPartnerServer() == null) { throw new NullPointerException("parameters.PartnerServer"); } // 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("serverName", serverName); tracingParameters.put("databaseName", databaseName); 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/sqlservers/servers/"; url = url + URLEncoder.encode(serverName, "UTF-8"); url = url + "/databases/"; url = url + URLEncoder.encode(databaseName, "UTF-8"); url = url + "/databasecopies"; 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", "2012-03-01"); // Serialize Request String requestContent = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document requestDoc = documentBuilder.newDocument(); Element serviceResourceElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "ServiceResource"); requestDoc.appendChild(serviceResourceElement); Element partnerServerElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "PartnerServer"); partnerServerElement.appendChild(requestDoc.createTextNode(parameters.getPartnerServer())); serviceResourceElement.appendChild(partnerServerElement); Element partnerDatabaseElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "PartnerDatabase"); partnerDatabaseElement.appendChild(requestDoc.createTextNode(parameters.getPartnerDatabase())); serviceResourceElement.appendChild(partnerDatabaseElement); Element isContinuousElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "IsContinuous"); isContinuousElement .appendChild(requestDoc.createTextNode(Boolean.toString(parameters.isContinuous()).toLowerCase())); serviceResourceElement.appendChild(isContinuousElement); Element isOfflineSecondaryElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "IsOfflineSecondary"); isOfflineSecondaryElement.appendChild( requestDoc.createTextNode(Boolean.toString(parameters.isOfflineSecondary()).toLowerCase())); serviceResourceElement.appendChild(isOfflineSecondaryElement); 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_CREATED) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result DatabaseCopyCreateResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_CREATED) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new DatabaseCopyCreateResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element serviceResourceElement2 = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ServiceResource"); if (serviceResourceElement2 != null) { DatabaseCopy serviceResourceInstance = new DatabaseCopy(); result.setDatabaseCopy(serviceResourceInstance); Element sourceServerNameElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "SourceServerName"); if (sourceServerNameElement != null) { String sourceServerNameInstance; sourceServerNameInstance = sourceServerNameElement.getTextContent(); serviceResourceInstance.setSourceServerName(sourceServerNameInstance); } Element sourceDatabaseNameElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "SourceDatabaseName"); if (sourceDatabaseNameElement != null) { String sourceDatabaseNameInstance; sourceDatabaseNameInstance = sourceDatabaseNameElement.getTextContent(); serviceResourceInstance.setSourceDatabaseName(sourceDatabaseNameInstance); } Element destinationServerNameElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "DestinationServerName"); if (destinationServerNameElement != null) { String destinationServerNameInstance; destinationServerNameInstance = destinationServerNameElement.getTextContent(); serviceResourceInstance.setDestinationServerName(destinationServerNameInstance); } Element destinationDatabaseNameElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "DestinationDatabaseName"); if (destinationDatabaseNameElement != null) { String destinationDatabaseNameInstance; destinationDatabaseNameInstance = destinationDatabaseNameElement.getTextContent(); serviceResourceInstance.setDestinationDatabaseName(destinationDatabaseNameInstance); } Element isContinuousElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "IsContinuous"); if (isContinuousElement2 != null) { boolean isContinuousInstance; isContinuousInstance = DatatypeConverter .parseBoolean(isContinuousElement2.getTextContent().toLowerCase()); serviceResourceInstance.setIsContinuous(isContinuousInstance); } Element replicationStateElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "ReplicationState"); if (replicationStateElement != null) { byte replicationStateInstance; replicationStateInstance = DatatypeConverter .parseByte(replicationStateElement.getTextContent()); serviceResourceInstance.setReplicationState(replicationStateInstance); } Element replicationStateDescriptionElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "ReplicationStateDescription"); if (replicationStateDescriptionElement != null) { String replicationStateDescriptionInstance; replicationStateDescriptionInstance = replicationStateDescriptionElement.getTextContent(); serviceResourceInstance.setReplicationStateDescription(replicationStateDescriptionInstance); } Element localDatabaseIdElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "LocalDatabaseId"); if (localDatabaseIdElement != null) { int localDatabaseIdInstance; localDatabaseIdInstance = DatatypeConverter .parseInt(localDatabaseIdElement.getTextContent()); serviceResourceInstance.setLocalDatabaseId(localDatabaseIdInstance); } Element isLocalDatabaseReplicationTargetElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "IsLocalDatabaseReplicationTarget"); if (isLocalDatabaseReplicationTargetElement != null) { boolean isLocalDatabaseReplicationTargetInstance; isLocalDatabaseReplicationTargetInstance = DatatypeConverter.parseBoolean( isLocalDatabaseReplicationTargetElement.getTextContent().toLowerCase()); serviceResourceInstance .setIsLocalDatabaseReplicationTarget(isLocalDatabaseReplicationTargetInstance); } Element isInterlinkConnectedElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "IsInterlinkConnected"); if (isInterlinkConnectedElement != null) { boolean isInterlinkConnectedInstance; isInterlinkConnectedInstance = DatatypeConverter .parseBoolean(isInterlinkConnectedElement.getTextContent().toLowerCase()); serviceResourceInstance.setIsInterlinkConnected(isInterlinkConnectedInstance); } Element startDateElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "StartDate"); if (startDateElement != null) { String startDateInstance; startDateInstance = startDateElement.getTextContent(); serviceResourceInstance.setStartDate(startDateInstance); } Element modifyDateElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "ModifyDate"); if (modifyDateElement != null) { String modifyDateInstance; modifyDateInstance = modifyDateElement.getTextContent(); serviceResourceInstance.setModifyDate(modifyDateInstance); } Element percentCompleteElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "PercentComplete"); if (percentCompleteElement != null) { float percentCompleteInstance; percentCompleteInstance = DatatypeConverter .parseFloat(percentCompleteElement.getTextContent()); serviceResourceInstance.setPercentComplete(percentCompleteInstance); } Element isOfflineSecondaryElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "IsOfflineSecondary"); if (isOfflineSecondaryElement2 != null) { boolean isOfflineSecondaryInstance; isOfflineSecondaryInstance = DatatypeConverter .parseBoolean(isOfflineSecondaryElement2.getTextContent().toLowerCase()); serviceResourceInstance.setIsOfflineSecondary(isOfflineSecondaryInstance); } Element isTerminationAllowedElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "IsTerminationAllowed"); if (isTerminationAllowedElement != null) { boolean isTerminationAllowedInstance; isTerminationAllowedInstance = DatatypeConverter .parseBoolean(isTerminationAllowedElement.getTextContent().toLowerCase()); serviceResourceInstance.setIsTerminationAllowed(isTerminationAllowedInstance); } Element nameElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); serviceResourceInstance.setName(nameInstance); } Element typeElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "Type"); if (typeElement != null) { String typeInstance; typeInstance = typeElement.getTextContent(); serviceResourceInstance.setType(typeInstance); } Element stateElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); serviceResourceInstance.setState(stateInstance); } } } 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(); } } }