List of usage examples for org.w3c.dom Document createAttributeNS
public Attr createAttributeNS(String namespaceURI, String qualifiedName) throws DOMException;
From source file:com.microsoft.windowsazure.management.servicebus.QueueOperationsImpl.java
/** * Creates a new queue. Once created, this queue's resource manifest is * immutable. This operation is idempotent. Repeating the create call, * after a queue with same name has been created successfully, will result * in a 409 Conflict error message. (see * http://msdn.microsoft.com/en-us/library/windowsazure/jj856295.aspx for * more information)//from w ww . j a va 2 s . c o m * * @param namespaceName Required. The namespace name. * @param queue Required. The service bus queue. * @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 A response to a request for a particular queue. */ @Override public ServiceBusQueueResponse create(String namespaceName, ServiceBusQueueCreateParameters queue) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException, URISyntaxException { // Validate if (namespaceName == null) { throw new NullPointerException("namespaceName"); } if (queue == null) { throw new NullPointerException("queue"); } if (queue.getName() == null) { throw new NullPointerException("queue.Name"); } // 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("namespaceName", namespaceName); tracingParameters.put("queue", queue); 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/servicebus/namespaces/"; url = url + URLEncoder.encode(namespaceName, "UTF-8"); url = url + "/queues/"; url = url + URLEncoder.encode(queue.getName(), "UTF-8"); url = url + "/"; 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/atom+xml"); httpRequest.setHeader("type", "entry"); httpRequest.setHeader("x-ms-version", "2013-08-01"); httpRequest.setHeader("x-process-at", "ServiceBus"); // Serialize Request String requestContent = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document requestDoc = documentBuilder.newDocument(); Element entryElement = requestDoc.createElementNS("http://www.w3.org/2005/Atom", "entry"); requestDoc.appendChild(entryElement); Element contentElement = requestDoc.createElementNS("http://www.w3.org/2005/Atom", "content"); entryElement.appendChild(contentElement); Attr typeAttribute = requestDoc.createAttribute("type"); typeAttribute.setValue("application/atom+xml;type=entry;charset=utf-8"); contentElement.setAttributeNode(typeAttribute); Element queueDescriptionElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "QueueDescription"); contentElement.appendChild(queueDescriptionElement); if (queue.getLockDuration() != null) { Element lockDurationElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "LockDuration"); lockDurationElement.appendChild(requestDoc.createTextNode(queue.getLockDuration())); queueDescriptionElement.appendChild(lockDurationElement); } Element maxSizeInMegabytesElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "MaxSizeInMegabytes"); maxSizeInMegabytesElement .appendChild(requestDoc.createTextNode(Integer.toString(queue.getMaxSizeInMegabytes()))); queueDescriptionElement.appendChild(maxSizeInMegabytesElement); Element requiresDuplicateDetectionElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "RequiresDuplicateDetection"); requiresDuplicateDetectionElement.appendChild( requestDoc.createTextNode(Boolean.toString(queue.isRequiresDuplicateDetection()).toLowerCase())); queueDescriptionElement.appendChild(requiresDuplicateDetectionElement); Element requiresSessionElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "RequiresSession"); requiresSessionElement .appendChild(requestDoc.createTextNode(Boolean.toString(queue.isRequiresSession()).toLowerCase())); queueDescriptionElement.appendChild(requiresSessionElement); if (queue.getDefaultMessageTimeToLive() != null) { Element defaultMessageTimeToLiveElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "DefaultMessageTimeToLive"); defaultMessageTimeToLiveElement .appendChild(requestDoc.createTextNode(queue.getDefaultMessageTimeToLive())); queueDescriptionElement.appendChild(defaultMessageTimeToLiveElement); } Element deadLetteringOnMessageExpirationElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "DeadLetteringOnMessageExpiration"); deadLetteringOnMessageExpirationElement.appendChild(requestDoc .createTextNode(Boolean.toString(queue.isDeadLetteringOnMessageExpiration()).toLowerCase())); queueDescriptionElement.appendChild(deadLetteringOnMessageExpirationElement); if (queue.getDuplicateDetectionHistoryTimeWindow() != null) { Element duplicateDetectionHistoryTimeWindowElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "DuplicateDetectionHistoryTimeWindow"); duplicateDetectionHistoryTimeWindowElement .appendChild(requestDoc.createTextNode(queue.getDuplicateDetectionHistoryTimeWindow())); queueDescriptionElement.appendChild(duplicateDetectionHistoryTimeWindowElement); } Element enableBatchedOperationsElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "EnableBatchedOperations"); enableBatchedOperationsElement.appendChild( requestDoc.createTextNode(Boolean.toString(queue.isEnableBatchedOperations()).toLowerCase())); queueDescriptionElement.appendChild(enableBatchedOperationsElement); Element sizeInBytesElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "SizeInBytes"); sizeInBytesElement.appendChild(requestDoc.createTextNode(Integer.toString(queue.getSizeInBytes()))); queueDescriptionElement.appendChild(sizeInBytesElement); Element messageCountElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "MessageCount"); messageCountElement.appendChild(requestDoc.createTextNode(Integer.toString(queue.getMessageCount()))); queueDescriptionElement.appendChild(messageCountElement); Element isAnonymousAccessibleElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "IsAnonymousAccessible"); isAnonymousAccessibleElement.appendChild( requestDoc.createTextNode(Boolean.toString(queue.isAnonymousAccessible()).toLowerCase())); queueDescriptionElement.appendChild(isAnonymousAccessibleElement); if (queue.getAuthorizationRules() != null) { if (queue.getAuthorizationRules() instanceof LazyCollection == false || ((LazyCollection) queue.getAuthorizationRules()).isInitialized()) { Element authorizationRulesSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AuthorizationRules"); for (ServiceBusSharedAccessAuthorizationRule authorizationRulesItem : queue .getAuthorizationRules()) { Element authorizationRuleElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AuthorizationRule"); authorizationRulesSequenceElement.appendChild(authorizationRuleElement); Attr typeAttribute2 = requestDoc.createAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "type"); typeAttribute2.setValue("SharedAccessAuthorizationRule"); authorizationRuleElement.setAttributeNode(typeAttribute2); if (authorizationRulesItem.getClaimType() != null) { Element claimTypeElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "ClaimType"); claimTypeElement .appendChild(requestDoc.createTextNode(authorizationRulesItem.getClaimType())); authorizationRuleElement.appendChild(claimTypeElement); } if (authorizationRulesItem.getClaimValue() != null) { Element claimValueElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "ClaimValue"); claimValueElement .appendChild(requestDoc.createTextNode(authorizationRulesItem.getClaimValue())); authorizationRuleElement.appendChild(claimValueElement); } if (authorizationRulesItem.getRights() != null) { if (authorizationRulesItem.getRights() instanceof LazyCollection == false || ((LazyCollection) authorizationRulesItem.getRights()).isInitialized()) { Element rightsSequenceElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "Rights"); for (AccessRight rightsItem : authorizationRulesItem.getRights()) { Element rightsItemElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AccessRights"); rightsItemElement.appendChild(requestDoc.createTextNode(rightsItem.toString())); rightsSequenceElement.appendChild(rightsItemElement); } authorizationRuleElement.appendChild(rightsSequenceElement); } } Element createdTimeElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "CreatedTime"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'"); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); createdTimeElement.appendChild(requestDoc.createTextNode( simpleDateFormat.format(authorizationRulesItem.getCreatedTime().getTime()))); authorizationRuleElement.appendChild(createdTimeElement); if (authorizationRulesItem.getKeyName() != null) { Element keyNameElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "KeyName"); keyNameElement.appendChild(requestDoc.createTextNode(authorizationRulesItem.getKeyName())); authorizationRuleElement.appendChild(keyNameElement); } Element modifiedTimeElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "ModifiedTime"); SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'"); simpleDateFormat2.setTimeZone(TimeZone.getTimeZone("UTC")); modifiedTimeElement.appendChild(requestDoc.createTextNode( simpleDateFormat2.format(authorizationRulesItem.getModifiedTime().getTime()))); authorizationRuleElement.appendChild(modifiedTimeElement); if (authorizationRulesItem.getPrimaryKey() != null) { Element primaryKeyElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "PrimaryKey"); primaryKeyElement .appendChild(requestDoc.createTextNode(authorizationRulesItem.getPrimaryKey())); authorizationRuleElement.appendChild(primaryKeyElement); } if (authorizationRulesItem.getSecondaryKey() != null) { Element secondaryKeyElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "SecondaryKey"); secondaryKeyElement .appendChild(requestDoc.createTextNode(authorizationRulesItem.getSecondaryKey())); authorizationRuleElement.appendChild(secondaryKeyElement); } } queueDescriptionElement.appendChild(authorizationRulesSequenceElement); } } if (queue.getStatus() != null) { Element statusElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "Status"); statusElement.appendChild(requestDoc.createTextNode(queue.getStatus())); queueDescriptionElement.appendChild(statusElement); } Element supportOrderingElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "SupportOrdering"); supportOrderingElement .appendChild(requestDoc.createTextNode(Boolean.toString(queue.isSupportOrdering()).toLowerCase())); queueDescriptionElement.appendChild(supportOrderingElement); if (queue.getCountDetails() != null) { Element countDetailsElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "CountDetails"); queueDescriptionElement.appendChild(countDetailsElement); Element activeMessageCountElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2011/06/servicebus", "ActiveMessageCount"); activeMessageCountElement.appendChild( requestDoc.createTextNode(Integer.toString(queue.getCountDetails().getActiveMessageCount()))); countDetailsElement.appendChild(activeMessageCountElement); Element deadLetterMessageCountElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2011/06/servicebus", "DeadLetterMessageCount"); deadLetterMessageCountElement.appendChild(requestDoc .createTextNode(Integer.toString(queue.getCountDetails().getDeadLetterMessageCount()))); countDetailsElement.appendChild(deadLetterMessageCountElement); Element scheduledMessageCountElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2011/06/servicebus", "ScheduledMessageCount"); scheduledMessageCountElement.appendChild(requestDoc .createTextNode(Integer.toString(queue.getCountDetails().getScheduledMessageCount()))); countDetailsElement.appendChild(scheduledMessageCountElement); Element transferDeadLetterMessageCountElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2011/06/servicebus", "TransferDeadLetterMessageCount"); transferDeadLetterMessageCountElement.appendChild(requestDoc .createTextNode(Integer.toString(queue.getCountDetails().getTransferDeadLetterMessageCount()))); countDetailsElement.appendChild(transferDeadLetterMessageCountElement); Element transferMessageCountElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2011/06/servicebus", "TransferMessageCount"); transferMessageCountElement.appendChild( requestDoc.createTextNode(Integer.toString(queue.getCountDetails().getTransferMessageCount()))); countDetailsElement.appendChild(transferMessageCountElement); } if (queue.getAutoDeleteOnIdle() != null) { Element autoDeleteOnIdleElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AutoDeleteOnIdle"); autoDeleteOnIdleElement.appendChild(requestDoc.createTextNode(queue.getAutoDeleteOnIdle())); queueDescriptionElement.appendChild(autoDeleteOnIdleElement); } if (queue.getEntityAvailabilityStatus() != null) { Element entityAvailabilityStatusElement = requestDoc.createElementNS( "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "EntityAvailabilityStatus"); entityAvailabilityStatusElement .appendChild(requestDoc.createTextNode(queue.getEntityAvailabilityStatus())); queueDescriptionElement.appendChild(entityAvailabilityStatusElement); } 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/atom+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 ServiceBusQueueResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_CREATED) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new ServiceBusQueueResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element entryElement2 = XmlUtility.getElementByTagNameNS(responseDoc, "http://www.w3.org/2005/Atom", "entry"); if (entryElement2 != null) { Element titleElement = XmlUtility.getElementByTagNameNS(entryElement2, "http://www.w3.org/2005/Atom", "title"); if (titleElement != null) { } Element contentElement2 = XmlUtility.getElementByTagNameNS(entryElement2, "http://www.w3.org/2005/Atom", "content"); if (contentElement2 != null) { Element queueDescriptionElement2 = XmlUtility.getElementByTagNameNS(contentElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "QueueDescription"); if (queueDescriptionElement2 != null) { ServiceBusQueue queueDescriptionInstance = new ServiceBusQueue(); result.setQueue(queueDescriptionInstance); Element lockDurationElement2 = XmlUtility.getElementByTagNameNS( queueDescriptionElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "LockDuration"); if (lockDurationElement2 != null) { String lockDurationInstance; lockDurationInstance = lockDurationElement2.getTextContent(); queueDescriptionInstance.setLockDuration(lockDurationInstance); } Element maxSizeInMegabytesElement2 = XmlUtility.getElementByTagNameNS( queueDescriptionElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "MaxSizeInMegabytes"); if (maxSizeInMegabytesElement2 != null) { int maxSizeInMegabytesInstance; maxSizeInMegabytesInstance = DatatypeConverter .parseInt(maxSizeInMegabytesElement2.getTextContent()); queueDescriptionInstance.setMaxSizeInMegabytes(maxSizeInMegabytesInstance); } Element requiresDuplicateDetectionElement2 = XmlUtility.getElementByTagNameNS( queueDescriptionElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "RequiresDuplicateDetection"); if (requiresDuplicateDetectionElement2 != null) { boolean requiresDuplicateDetectionInstance; requiresDuplicateDetectionInstance = DatatypeConverter.parseBoolean( requiresDuplicateDetectionElement2.getTextContent().toLowerCase()); queueDescriptionInstance .setRequiresDuplicateDetection(requiresDuplicateDetectionInstance); } Element requiresSessionElement2 = XmlUtility.getElementByTagNameNS( queueDescriptionElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "RequiresSession"); if (requiresSessionElement2 != null) { boolean requiresSessionInstance; requiresSessionInstance = DatatypeConverter .parseBoolean(requiresSessionElement2.getTextContent().toLowerCase()); queueDescriptionInstance.setRequiresSession(requiresSessionInstance); } Element defaultMessageTimeToLiveElement2 = XmlUtility.getElementByTagNameNS( queueDescriptionElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "DefaultMessageTimeToLive"); if (defaultMessageTimeToLiveElement2 != null) { String defaultMessageTimeToLiveInstance; defaultMessageTimeToLiveInstance = defaultMessageTimeToLiveElement2 .getTextContent(); queueDescriptionInstance .setDefaultMessageTimeToLive(defaultMessageTimeToLiveInstance); } Element deadLetteringOnMessageExpirationElement2 = XmlUtility.getElementByTagNameNS( queueDescriptionElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "DeadLetteringOnMessageExpiration"); if (deadLetteringOnMessageExpirationElement2 != null) { boolean deadLetteringOnMessageExpirationInstance; deadLetteringOnMessageExpirationInstance = DatatypeConverter.parseBoolean( deadLetteringOnMessageExpirationElement2.getTextContent().toLowerCase()); queueDescriptionInstance.setDeadLetteringOnMessageExpiration( deadLetteringOnMessageExpirationInstance); } Element duplicateDetectionHistoryTimeWindowElement2 = XmlUtility.getElementByTagNameNS( queueDescriptionElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "DuplicateDetectionHistoryTimeWindow"); if (duplicateDetectionHistoryTimeWindowElement2 != null) { String duplicateDetectionHistoryTimeWindowInstance; duplicateDetectionHistoryTimeWindowInstance = duplicateDetectionHistoryTimeWindowElement2 .getTextContent(); queueDescriptionInstance.setDuplicateDetectionHistoryTimeWindow( duplicateDetectionHistoryTimeWindowInstance); } Element maxDeliveryCountElement = XmlUtility.getElementByTagNameNS( queueDescriptionElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "MaxDeliveryCount"); if (maxDeliveryCountElement != null) { int maxDeliveryCountInstance; maxDeliveryCountInstance = DatatypeConverter .parseInt(maxDeliveryCountElement.getTextContent()); queueDescriptionInstance.setMaxDeliveryCount(maxDeliveryCountInstance); } Element enableBatchedOperationsElement2 = XmlUtility.getElementByTagNameNS( queueDescriptionElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "EnableBatchedOperations"); if (enableBatchedOperationsElement2 != null) { boolean enableBatchedOperationsInstance; enableBatchedOperationsInstance = DatatypeConverter.parseBoolean( enableBatchedOperationsElement2.getTextContent().toLowerCase()); queueDescriptionInstance .setEnableBatchedOperations(enableBatchedOperationsInstance); } Element sizeInBytesElement2 = XmlUtility.getElementByTagNameNS(queueDescriptionElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "SizeInBytes"); if (sizeInBytesElement2 != null) { int sizeInBytesInstance; sizeInBytesInstance = DatatypeConverter .parseInt(sizeInBytesElement2.getTextContent()); queueDescriptionInstance.setSizeInBytes(sizeInBytesInstance); } Element messageCountElement2 = XmlUtility.getElementByTagNameNS( queueDescriptionElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "MessageCount"); if (messageCountElement2 != null) { int messageCountInstance; messageCountInstance = DatatypeConverter .parseInt(messageCountElement2.getTextContent()); queueDescriptionInstance.setMessageCount(messageCountInstance); } Element isAnonymousAccessibleElement2 = XmlUtility.getElementByTagNameNS( queueDescriptionElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "IsAnonymousAccessible"); if (isAnonymousAccessibleElement2 != null) { boolean isAnonymousAccessibleInstance; isAnonymousAccessibleInstance = DatatypeConverter .parseBoolean(isAnonymousAccessibleElement2.getTextContent().toLowerCase()); queueDescriptionInstance.setIsAnonymousAccessible(isAnonymousAccessibleInstance); } Element authorizationRulesSequenceElement2 = XmlUtility.getElementByTagNameNS( queueDescriptionElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AuthorizationRules"); if (authorizationRulesSequenceElement2 != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(authorizationRulesSequenceElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AuthorizationRule") .size(); i1 = i1 + 1) { org.w3c.dom.Element authorizationRulesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(authorizationRulesSequenceElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AuthorizationRule") .get(i1)); ServiceBusSharedAccessAuthorizationRule authorizationRuleInstance = new ServiceBusSharedAccessAuthorizationRule(); queueDescriptionInstance.getAuthorizationRules().add(authorizationRuleInstance); Element claimTypeElement2 = XmlUtility.getElementByTagNameNS( authorizationRulesElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "ClaimType"); if (claimTypeElement2 != null) { String claimTypeInstance; claimTypeInstance = claimTypeElement2.getTextContent(); authorizationRuleInstance.setClaimType(claimTypeInstance); } Element claimValueElement2 = XmlUtility.getElementByTagNameNS( authorizationRulesElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "ClaimValue"); if (claimValueElement2 != null) { String claimValueInstance; claimValueInstance = claimValueElement2.getTextContent(); authorizationRuleInstance.setClaimValue(claimValueInstance); } Element rightsSequenceElement2 = XmlUtility.getElementByTagNameNS( authorizationRulesElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "Rights"); if (rightsSequenceElement2 != null) { for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(rightsSequenceElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AccessRights") .size(); i2 = i2 + 1) { org.w3c.dom.Element rightsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(rightsSequenceElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AccessRights") .get(i2)); authorizationRuleInstance.getRights() .add(AccessRight.valueOf(rightsElement.getTextContent())); } } Element createdTimeElement2 = XmlUtility.getElementByTagNameNS( authorizationRulesElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "CreatedTime"); if (createdTimeElement2 != null) { Calendar createdTimeInstance; createdTimeInstance = DatatypeConverter .parseDateTime(createdTimeElement2.getTextContent()); authorizationRuleInstance.setCreatedTime(createdTimeInstance); } Element keyNameElement2 = XmlUtility.getElementByTagNameNS( authorizationRulesElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "KeyName"); if (keyNameElement2 != null) { String keyNameInstance; keyNameInstance = keyNameElement2.getTextContent(); authorizationRuleInstance.setKeyName(keyNameInstance); } Element modifiedTimeElement2 = XmlUtility.getElementByTagNameNS( authorizationRulesElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "ModifiedTime"); if (modifiedTimeElement2 != null) { Calendar modifiedTimeInstance; modifiedTimeInstance = DatatypeConverter .parseDateTime(modifiedTimeElement2.getTextContent()); authorizationRuleInstance.setModifiedTime(modifiedTimeInstance); } Element primaryKeyElement2 = XmlUtility.getElementByTagNameNS( authorizationRulesElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "PrimaryKey"); if (primaryKeyElement2 != null) { String primaryKeyInstance; primaryKeyInstance = primaryKeyElement2.getTextContent(); authorizationRuleInstance.setPrimaryKey(primaryKeyInstance); } Element secondaryKeyElement2 = XmlUtility.getElementByTagNameNS( authorizationRulesElement, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "SecondaryKey"); if (secondaryKeyElement2 != null) { String secondaryKeyInstance; secondaryKeyInstance = secondaryKeyElement2.getTextContent(); authorizationRuleInstance.setSecondaryKey(secondaryKeyInstance); } } } Element statusElement2 = XmlUtility.getElementByTagNameNS(queueDescriptionElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "Status"); if (statusElement2 != null) { String statusInstance; statusInstance = statusElement2.getTextContent(); queueDescriptionInstance.setStatus(statusInstance); } Element createdAtElement = XmlUtility.getElementByTagNameNS(queueDescriptionElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "CreatedAt"); if (createdAtElement != null) { Calendar createdAtInstance; createdAtInstance = DatatypeConverter .parseDateTime(createdAtElement.getTextContent()); queueDescriptionInstance.setCreatedAt(createdAtInstance); } Element updatedAtElement = XmlUtility.getElementByTagNameNS(queueDescriptionElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "UpdatedAt"); if (updatedAtElement != null) { Calendar updatedAtInstance; updatedAtInstance = DatatypeConverter .parseDateTime(updatedAtElement.getTextContent()); queueDescriptionInstance.setUpdatedAt(updatedAtInstance); } Element accessedAtElement = XmlUtility.getElementByTagNameNS(queueDescriptionElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AccessedAt"); if (accessedAtElement != null) { Calendar accessedAtInstance; accessedAtInstance = DatatypeConverter .parseDateTime(accessedAtElement.getTextContent()); queueDescriptionInstance.setAccessedAt(accessedAtInstance); } Element supportOrderingElement2 = XmlUtility.getElementByTagNameNS( queueDescriptionElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "SupportOrdering"); if (supportOrderingElement2 != null) { boolean supportOrderingInstance; supportOrderingInstance = DatatypeConverter .parseBoolean(supportOrderingElement2.getTextContent().toLowerCase()); queueDescriptionInstance.setSupportOrdering(supportOrderingInstance); } Element countDetailsElement2 = XmlUtility.getElementByTagNameNS( queueDescriptionElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "CountDetails"); if (countDetailsElement2 != null) { CountDetails countDetailsInstance = new CountDetails(); queueDescriptionInstance.setCountDetails(countDetailsInstance); Element activeMessageCountElement2 = XmlUtility.getElementByTagNameNS( countDetailsElement2, "http://schemas.microsoft.com/netservices/2011/06/servicebus", "ActiveMessageCount"); if (activeMessageCountElement2 != null) { int activeMessageCountInstance; activeMessageCountInstance = DatatypeConverter .parseInt(activeMessageCountElement2.getTextContent()); countDetailsInstance.setActiveMessageCount(activeMessageCountInstance); } Element deadLetterMessageCountElement2 = XmlUtility.getElementByTagNameNS( countDetailsElement2, "http://schemas.microsoft.com/netservices/2011/06/servicebus", "DeadLetterMessageCount"); if (deadLetterMessageCountElement2 != null) { int deadLetterMessageCountInstance; deadLetterMessageCountInstance = DatatypeConverter .parseInt(deadLetterMessageCountElement2.getTextContent()); countDetailsInstance.setDeadLetterMessageCount(deadLetterMessageCountInstance); } Element scheduledMessageCountElement2 = XmlUtility.getElementByTagNameNS( countDetailsElement2, "http://schemas.microsoft.com/netservices/2011/06/servicebus", "ScheduledMessageCount"); if (scheduledMessageCountElement2 != null) { int scheduledMessageCountInstance; scheduledMessageCountInstance = DatatypeConverter .parseInt(scheduledMessageCountElement2.getTextContent()); countDetailsInstance.setScheduledMessageCount(scheduledMessageCountInstance); } Element transferDeadLetterMessageCountElement2 = XmlUtility.getElementByTagNameNS( countDetailsElement2, "http://schemas.microsoft.com/netservices/2011/06/servicebus", "TransferDeadLetterMessageCount"); if (transferDeadLetterMessageCountElement2 != null) { int transferDeadLetterMessageCountInstance; transferDeadLetterMessageCountInstance = DatatypeConverter .parseInt(transferDeadLetterMessageCountElement2.getTextContent()); countDetailsInstance.setTransferDeadLetterMessageCount( transferDeadLetterMessageCountInstance); } Element transferMessageCountElement2 = XmlUtility.getElementByTagNameNS( countDetailsElement2, "http://schemas.microsoft.com/netservices/2011/06/servicebus", "TransferMessageCount"); if (transferMessageCountElement2 != null) { int transferMessageCountInstance; transferMessageCountInstance = DatatypeConverter .parseInt(transferMessageCountElement2.getTextContent()); countDetailsInstance.setTransferMessageCount(transferMessageCountInstance); } } Element autoDeleteOnIdleElement2 = XmlUtility.getElementByTagNameNS( queueDescriptionElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "AutoDeleteOnIdle"); if (autoDeleteOnIdleElement2 != null) { String autoDeleteOnIdleInstance; autoDeleteOnIdleInstance = autoDeleteOnIdleElement2.getTextContent(); queueDescriptionInstance.setAutoDeleteOnIdle(autoDeleteOnIdleInstance); } Element entityAvailabilityStatusElement2 = XmlUtility.getElementByTagNameNS( queueDescriptionElement2, "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", "EntityAvailabilityStatus"); if (entityAvailabilityStatusElement2 != null) { String entityAvailabilityStatusInstance; entityAvailabilityStatusInstance = entityAvailabilityStatusElement2 .getTextContent(); queueDescriptionInstance .setEntityAvailabilityStatus(entityAvailabilityStatusInstance); } } } } } 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.websites.WebSiteOperationsImpl.java
/** * You can update the settings for a web site by using the HTTP PUT method * and by specifying the settings in the request body. (see * http://msdn.microsoft.com/en-us/library/windowsazure/dn167005.aspx for * more information)//from w w w. jav a2s .c o m * * @param webSpaceName Required. The name of the web space. * @param webSiteName Required. The name of the web site. * @param parameters Required. Parameters supplied to the Update Web Site * 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 Update Web Site operation response. */ @Override public WebSiteUpdateResponse update(String webSpaceName, String webSiteName, WebSiteUpdateParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException, URISyntaxException { // Validate if (webSpaceName == null) { throw new NullPointerException("webSpaceName"); } if (webSiteName == null) { throw new NullPointerException("webSiteName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getHostNameSslStates() != null) { for (WebSiteUpdateParameters.WebSiteHostNameSslState hostNameSslStatesParameterItem : parameters .getHostNameSslStates()) { if (hostNameSslStatesParameterItem.getName() == null) { throw new NullPointerException("parameters.HostNameSslStates.Name"); } if (hostNameSslStatesParameterItem.getSslState() == null) { throw new NullPointerException("parameters.HostNameSslStates.SslState"); } } } // 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("webSiteName", webSiteName); 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 + "/sites/"; url = url + URLEncoder.encode(webSiteName, "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 siteElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Site"); requestDoc.appendChild(siteElement); if (parameters.getHostNameSslStates() != null) { if (parameters.getHostNameSslStates() instanceof LazyCollection == false || ((LazyCollection) parameters.getHostNameSslStates()).isInitialized()) { Element hostNameSslStatesSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "HostNameSslStates"); for (WebSiteUpdateParameters.WebSiteHostNameSslState hostNameSslStatesItem : parameters .getHostNameSslStates()) { Element webSiteHostNameSslStateElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "WebSiteHostNameSslState"); hostNameSslStatesSequenceElement.appendChild(webSiteHostNameSslStateElement); Element nameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement.appendChild(requestDoc.createTextNode(hostNameSslStatesItem.getName())); webSiteHostNameSslStateElement.appendChild(nameElement); Element sslStateElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "SslState"); sslStateElement .appendChild(requestDoc.createTextNode(hostNameSslStatesItem.getSslState().toString())); webSiteHostNameSslStateElement.appendChild(sslStateElement); if (hostNameSslStatesItem.getThumbprint() != null) { Element thumbprintElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Thumbprint"); thumbprintElement .appendChild(requestDoc.createTextNode(hostNameSslStatesItem.getThumbprint())); webSiteHostNameSslStateElement.appendChild(thumbprintElement); } else { Element emptyElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "Thumbprint"); Attr nilAttribute = requestDoc .createAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); nilAttribute.setValue("true"); emptyElement.setAttributeNode(nilAttribute); webSiteHostNameSslStateElement.appendChild(emptyElement); } Element toUpdateElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ToUpdate"); toUpdateElement.appendChild(requestDoc.createTextNode("true")); webSiteHostNameSslStateElement.appendChild(toUpdateElement); } siteElement.appendChild(hostNameSslStatesSequenceElement); } } if (parameters.getHostNames() != null) { if (parameters.getHostNames() instanceof LazyCollection == false || ((LazyCollection) parameters.getHostNames()).isInitialized()) { Element hostNamesSequenceElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "HostNames"); for (String hostNamesItem : parameters.getHostNames()) { Element hostNamesItemElement = requestDoc .createElementNS("http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string"); hostNamesItemElement.appendChild(requestDoc.createTextNode(hostNamesItem)); hostNamesSequenceElement.appendChild(hostNamesItemElement); } siteElement.appendChild(hostNamesSequenceElement); } } if (parameters.getServerFarm() != null) { Element serverFarmElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "ServerFarm"); serverFarmElement.appendChild(requestDoc.createTextNode(parameters.getServerFarm())); siteElement.appendChild(serverFarmElement); } if (parameters.getState() != null) { Element stateElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "State"); stateElement.appendChild(requestDoc.createTextNode(parameters.getState())); siteElement.appendChild(stateElement); } 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 WebSiteUpdateResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new WebSiteUpdateResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element siteElement2 = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "Site"); if (siteElement2 != null) { WebSite webSiteInstance = new WebSite(); result.setWebSite(webSiteInstance); Element adminEnabledElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "AdminEnabled"); if (adminEnabledElement != null && adminEnabledElement.getTextContent() != null && !adminEnabledElement.getTextContent().isEmpty()) { boolean adminEnabledInstance; adminEnabledInstance = DatatypeConverter .parseBoolean(adminEnabledElement.getTextContent().toLowerCase()); webSiteInstance.setAdminEnabled(adminEnabledInstance); } Element availabilityStateElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "AvailabilityState"); if (availabilityStateElement != null && availabilityStateElement.getTextContent() != null && !availabilityStateElement.getTextContent().isEmpty()) { WebSpaceAvailabilityState availabilityStateInstance; availabilityStateInstance = WebSpaceAvailabilityState .valueOf(availabilityStateElement.getTextContent()); webSiteInstance.setAvailabilityState(availabilityStateInstance); } Element sKUElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "SKU"); if (sKUElement != null && sKUElement.getTextContent() != null && !sKUElement.getTextContent().isEmpty()) { SkuOptions sKUInstance; sKUInstance = SkuOptions.valueOf(sKUElement.getTextContent()); webSiteInstance.setSku(sKUInstance); } Element enabledElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "Enabled"); if (enabledElement != null && enabledElement.getTextContent() != null && !enabledElement.getTextContent().isEmpty()) { boolean enabledInstance; enabledInstance = DatatypeConverter .parseBoolean(enabledElement.getTextContent().toLowerCase()); webSiteInstance.setEnabled(enabledInstance); } Element enabledHostNamesSequenceElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "EnabledHostNames"); if (enabledHostNamesSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(enabledHostNamesSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .size(); i1 = i1 + 1) { org.w3c.dom.Element enabledHostNamesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(enabledHostNamesSequenceElement, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .get(i1)); webSiteInstance.getEnabledHostNames().add(enabledHostNamesElement.getTextContent()); } } Element hostNameSslStatesSequenceElement2 = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "HostNameSslStates"); if (hostNameSslStatesSequenceElement2 != null) { for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNameSslStatesSequenceElement2, "http://schemas.microsoft.com/windowsazure", "HostNameSslState") .size(); i2 = i2 + 1) { org.w3c.dom.Element hostNameSslStatesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNameSslStatesSequenceElement2, "http://schemas.microsoft.com/windowsazure", "HostNameSslState") .get(i2)); WebSite.WebSiteHostNameSslState hostNameSslStateInstance = new WebSite.WebSiteHostNameSslState(); webSiteInstance.getHostNameSslStates().add(hostNameSslStateInstance); Element nameElement2 = XmlUtility.getElementByTagNameNS(hostNameSslStatesElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement2 != null) { String nameInstance; nameInstance = nameElement2.getTextContent(); hostNameSslStateInstance.setName(nameInstance); } Element sslStateElement2 = XmlUtility.getElementByTagNameNS(hostNameSslStatesElement, "http://schemas.microsoft.com/windowsazure", "SslState"); if (sslStateElement2 != null && sslStateElement2.getTextContent() != null && !sslStateElement2.getTextContent().isEmpty()) { WebSiteSslState sslStateInstance; sslStateInstance = WebSiteSslState.valueOf(sslStateElement2.getTextContent()); hostNameSslStateInstance.setSslState(sslStateInstance); } Element thumbprintElement2 = XmlUtility.getElementByTagNameNS(hostNameSslStatesElement, "http://schemas.microsoft.com/windowsazure", "Thumbprint"); if (thumbprintElement2 != null) { boolean isNil = false; Attr nilAttribute2 = thumbprintElement2 .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute2 != null) { isNil = "true".equals(nilAttribute2.getValue()); } if (isNil == false) { String thumbprintInstance; thumbprintInstance = thumbprintElement2.getTextContent(); hostNameSslStateInstance.setThumbprint(thumbprintInstance); } } Element virtualIPElement = XmlUtility.getElementByTagNameNS(hostNameSslStatesElement, "http://schemas.microsoft.com/windowsazure", "VirtualIP"); if (virtualIPElement != null) { boolean isNil2 = false; Attr nilAttribute3 = virtualIPElement .getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "nil"); if (nilAttribute3 != null) { isNil2 = "true".equals(nilAttribute3.getValue()); } if (isNil2 == false) { InetAddress virtualIPInstance; virtualIPInstance = InetAddress.getByName(virtualIPElement.getTextContent()); hostNameSslStateInstance.setVirtualIP(virtualIPInstance); } } } } Element hostNamesSequenceElement2 = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "HostNames"); if (hostNamesSequenceElement2 != null) { for (int i3 = 0; i3 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNamesSequenceElement2, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .size(); i3 = i3 + 1) { org.w3c.dom.Element hostNamesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(hostNamesSequenceElement2, "http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string") .get(i3)); webSiteInstance.getHostNames().add(hostNamesElement.getTextContent()); } } Element lastModifiedTimeUtcElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "LastModifiedTimeUtc"); if (lastModifiedTimeUtcElement != null && lastModifiedTimeUtcElement.getTextContent() != null && !lastModifiedTimeUtcElement.getTextContent().isEmpty()) { Calendar lastModifiedTimeUtcInstance; lastModifiedTimeUtcInstance = DatatypeConverter .parseDateTime(lastModifiedTimeUtcElement.getTextContent()); webSiteInstance.setLastModifiedTimeUtc(lastModifiedTimeUtcInstance); } Element nameElement3 = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement3 != null) { String nameInstance2; nameInstance2 = nameElement3.getTextContent(); webSiteInstance.setName(nameInstance2); } Element repositorySiteNameElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "RepositorySiteName"); if (repositorySiteNameElement != null) { String repositorySiteNameInstance; repositorySiteNameInstance = repositorySiteNameElement.getTextContent(); webSiteInstance.setRepositorySiteName(repositorySiteNameInstance); } Element runtimeAvailabilityStateElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "RuntimeAvailabilityState"); if (runtimeAvailabilityStateElement != null && runtimeAvailabilityStateElement.getTextContent() != null && !runtimeAvailabilityStateElement.getTextContent().isEmpty()) { WebSiteRuntimeAvailabilityState runtimeAvailabilityStateInstance; runtimeAvailabilityStateInstance = WebSiteRuntimeAvailabilityState .valueOf(runtimeAvailabilityStateElement.getTextContent()); webSiteInstance.setRuntimeAvailabilityState(runtimeAvailabilityStateInstance); } Element selfLinkElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "SelfLink"); if (selfLinkElement != null) { URI selfLinkInstance; selfLinkInstance = new URI(selfLinkElement.getTextContent()); webSiteInstance.setUri(selfLinkInstance); } Element serverFarmElement2 = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "ServerFarm"); if (serverFarmElement2 != null) { String serverFarmInstance; serverFarmInstance = serverFarmElement2.getTextContent(); webSiteInstance.setServerFarm(serverFarmInstance); } Element sitePropertiesElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "SiteProperties"); if (sitePropertiesElement != null) { WebSite.WebSiteProperties sitePropertiesInstance = new WebSite.WebSiteProperties(); webSiteInstance.setSiteProperties(sitePropertiesInstance); Element appSettingsSequenceElement = XmlUtility.getElementByTagNameNS(sitePropertiesElement, "http://schemas.microsoft.com/windowsazure", "AppSettings"); if (appSettingsSequenceElement != null) { for (int i4 = 0; i4 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(appSettingsSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .size(); i4 = i4 + 1) { org.w3c.dom.Element appSettingsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(appSettingsSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .get(i4)); String appSettingsKey = XmlUtility .getElementByTagNameNS(appSettingsElement, "http://schemas.microsoft.com/windowsazure", "Name") .getTextContent(); String appSettingsValue = XmlUtility .getElementByTagNameNS(appSettingsElement, "http://schemas.microsoft.com/windowsazure", "Value") .getTextContent(); sitePropertiesInstance.getAppSettings().put(appSettingsKey, appSettingsValue); } } Element metadataSequenceElement = XmlUtility.getElementByTagNameNS(sitePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Metadata"); if (metadataSequenceElement != null) { for (int i5 = 0; i5 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(metadataSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .size(); i5 = i5 + 1) { org.w3c.dom.Element metadataElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(metadataSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .get(i5)); String metadataKey = XmlUtility .getElementByTagNameNS(metadataElement, "http://schemas.microsoft.com/windowsazure", "Name") .getTextContent(); String metadataValue = XmlUtility .getElementByTagNameNS(metadataElement, "http://schemas.microsoft.com/windowsazure", "Value") .getTextContent(); sitePropertiesInstance.getMetadata().put(metadataKey, metadataValue); } } Element propertiesSequenceElement = XmlUtility.getElementByTagNameNS(sitePropertiesElement, "http://schemas.microsoft.com/windowsazure", "Properties"); if (propertiesSequenceElement != null) { for (int i6 = 0; i6 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(propertiesSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .size(); i6 = i6 + 1) { org.w3c.dom.Element propertiesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(propertiesSequenceElement, "http://schemas.microsoft.com/windowsazure", "NameValuePair") .get(i6)); String propertiesKey = XmlUtility .getElementByTagNameNS(propertiesElement, "http://schemas.microsoft.com/windowsazure", "Name") .getTextContent(); String propertiesValue = XmlUtility .getElementByTagNameNS(propertiesElement, "http://schemas.microsoft.com/windowsazure", "Value") .getTextContent(); sitePropertiesInstance.getProperties().put(propertiesKey, propertiesValue); } } } Element stateElement2 = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement2 != null) { String stateInstance; stateInstance = stateElement2.getTextContent(); webSiteInstance.setState(stateInstance); } Element usageStateElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "UsageState"); if (usageStateElement != null && usageStateElement.getTextContent() != null && !usageStateElement.getTextContent().isEmpty()) { WebSiteUsageState usageStateInstance; usageStateInstance = WebSiteUsageState.valueOf(usageStateElement.getTextContent()); webSiteInstance.setUsageState(usageStateInstance); } Element webSpaceElement = XmlUtility.getElementByTagNameNS(siteElement2, "http://schemas.microsoft.com/windowsazure", "WebSpace"); if (webSpaceElement != null) { String webSpaceInstance; webSpaceInstance = webSpaceElement.getTextContent(); webSiteInstance.setWebSpace(webSpaceInstance); } } } 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.apache.axis.message.NodeImpl.java
/** * The internal representation of Attributes cannot help being changed * It is because Attribute is not immutible Type, so if we keep out value and * just return it in another form, the application may chnae it, which we cannot * detect without some kind back track method (call back notifying the chnage.) * I am not sure which approach is better. */// w ww.j a va 2s . c o m protected NamedNodeMap convertAttrSAXtoDOM(Attributes saxAttr) { try { org.w3c.dom.Document doc = org.apache.axis.utils.XMLUtils.newDocument(); AttributesImpl saxAttrs = (AttributesImpl) saxAttr; NamedNodeMap domAttributes = new NamedNodeMapImpl(); for (int i = 0; i < saxAttrs.getLength(); i++) { String uri = saxAttrs.getURI(i); String qname = saxAttrs.getQName(i); String value = saxAttrs.getValue(i); if (uri != null && uri.trim().length() > 0) { // filterring out the tricky method to differentiate the null namespace // -ware case if (NULL_URI_NAME.equals(uri)) { uri = null; } Attr attr = doc.createAttributeNS(uri, qname); attr.setValue(value); domAttributes.setNamedItemNS(attr); } else { Attr attr = doc.createAttribute(qname); attr.setValue(value); domAttributes.setNamedItem(attr); } } return domAttributes; } catch (Exception ex) { log.error(Messages.getMessage("saxToDomFailed00"), ex); return null; } }
From source file:org.apache.ode.il.OMUtils.java
@SuppressWarnings("unchecked") public static Element toDOM(OMElement element, Document doc, boolean deepNS) { ///* w w w. j a v a2 s . co m*/ // Fix regarding lost qnames on response of invoke activity: // * copy an element including its prefix. // * add all namespase attributes. // String domElementNsUri = element.getQName().getNamespaceURI(); String domElementQName; if (element.getQName().getPrefix() == null || element.getQName().getPrefix().trim().length() == 0) { domElementQName = element.getQName().getLocalPart(); } else { domElementQName = element.getQName().getPrefix() + ":" + element.getQName().getLocalPart(); } if (__log.isTraceEnabled()) __log.trace("toDOM: creating element with nsUri=" + domElementNsUri + " qname=" + domElementQName + " from omElement, name=" + element.getLocalName()); final Element domElement = doc.createElementNS(domElementNsUri, domElementQName); if (deepNS) { NSContext nscontext = new NSContext(); buildNScontext(nscontext, element); DOMUtils.injectNamespacesWithAllPrefixes(domElement, nscontext); } else { if (element.getAllDeclaredNamespaces() != null) { for (Iterator<OMNamespace> i = element.getAllDeclaredNamespaces(); i.hasNext();) { OMNamespace omns = i.next(); if (omns.getPrefix().equals("")) domElement.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns", omns.getNamespaceURI() == null ? "" : omns.getNamespaceURI()); else domElement.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns:" + omns.getPrefix(), omns.getNamespaceURI()); } } } if (__log.isTraceEnabled()) __log.trace("toDOM: created root element (deepNS=" + deepNS + "): " + DOMUtils.domToString(domElement)); for (Iterator i = element.getAllAttributes(); i.hasNext();) { final OMAttribute attr = (OMAttribute) i.next(); Attr newAttr; if (attr.getNamespace() != null) newAttr = doc.createAttributeNS(attr.getNamespace().getNamespaceURI(), attr.getLocalName()); else newAttr = doc.createAttributeNS(null, attr.getLocalName()); newAttr.appendChild(doc.createTextNode(attr.getAttributeValue())); domElement.setAttributeNodeNS(newAttr); // Case of qualified attribute values, we're forced to add corresponding namespace declaration manually... int colonIdx = attr.getAttributeValue().indexOf(":"); if (colonIdx > 0) { OMNamespace attrValNs = element.findNamespaceURI(attr.getAttributeValue().substring(0, colonIdx)); if (attrValNs != null) domElement.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns:" + attrValNs.getPrefix(), attrValNs.getNamespaceURI()); } } for (Iterator<OMNode> i = element.getChildren(); i.hasNext();) { OMNode omn = i.next(); switch (omn.getType()) { case OMNode.CDATA_SECTION_NODE: domElement.appendChild(doc.createCDATASection(((OMText) omn).getText())); break; case OMNode.TEXT_NODE: domElement.appendChild(doc.createTextNode(((OMText) omn).getText())); break; case OMNode.ELEMENT_NODE: domElement.appendChild(toDOM((OMElement) omn, doc, false)); break; } } return domElement; }
From source file:org.apache.ode.utils.DOMUtils.java
/** * @param el//w w w . j a v a2 s . c o m */ public static void pancakeNamespaces(Element el) { Map ns = getParentNamespaces(el); Document d = el.getOwnerDocument(); assert d != null; Iterator it = ns.keySet().iterator(); while (it.hasNext()) { String key = (String) it.next(); String uri = (String) ns.get(key); Attr a = d.createAttributeNS(NS_URI_XMLNS, (key.length() != 0) ? ("xmlns:" + key) : ("xmlns")); a.setValue(uri); el.setAttributeNodeNS(a); } }
From source file:org.apache.ode.utils.DOMUtils.java
private static void parse(XMLStreamReader reader, Document doc, Node parent) throws XMLStreamException { int event = reader.getEventType(); while (reader.hasNext()) { switch (event) { case XMLStreamConstants.START_ELEMENT: // create element Element e = doc.createElementNS(reader.getNamespaceURI(), reader.getLocalName()); if (reader.getPrefix() != null && reader.getPrefix() != "") { e.setPrefix(reader.getPrefix()); }/*w w w . jav a 2s. co m*/ parent.appendChild(e); // copy namespaces for (int ns = 0; ns < reader.getNamespaceCount(); ns++) { String uri = reader.getNamespaceURI(ns); String prefix = reader.getNamespacePrefix(ns); declare(e, uri, prefix); } // copy attributes for (int att = 0; att < reader.getAttributeCount(); att++) { String name = reader.getAttributeLocalName(att); String prefix = reader.getAttributePrefix(att); if (prefix != null && prefix.length() > 0) { name = prefix + ":" + name; } Attr attr = doc.createAttributeNS(reader.getAttributeNamespace(att), name); attr.setValue(reader.getAttributeValue(att)); e.setAttributeNode(attr); } // sub-nodes if (reader.hasNext()) { reader.next(); parse(reader, doc, e); } if (parent instanceof Document) { while (reader.hasNext()) reader.next(); return; } break; case XMLStreamConstants.END_ELEMENT: return; case XMLStreamConstants.CHARACTERS: if (parent != null) { parent.appendChild(doc.createTextNode(reader.getText())); } break; case XMLStreamConstants.COMMENT: if (parent != null) { parent.appendChild(doc.createComment(reader.getText())); } break; case XMLStreamConstants.CDATA: parent.appendChild(doc.createCDATASection(reader.getText())); break; case XMLStreamConstants.PROCESSING_INSTRUCTION: parent.appendChild(doc.createProcessingInstruction(reader.getPITarget(), reader.getPIData())); break; case XMLStreamConstants.ENTITY_REFERENCE: parent.appendChild(doc.createProcessingInstruction(reader.getPITarget(), reader.getPIData())); break; case XMLStreamConstants.NAMESPACE: case XMLStreamConstants.ATTRIBUTE: break; default: break; } if (reader.hasNext()) { event = reader.next(); } } }
From source file:org.apache.ode.utils.DOMUtils.java
/** * Deep clone, but don't fry, the given node in the context of the given document. * For all intents and purposes, the clone is the exact same copy of the node, * except that it might have a different owner document. * * This method is fool-proof, unlike the <code>adoptNode</code> or <code>adoptNode</code> methods, * in that it doesn't assume that the given node has a parent or a owner document. * * @param document/* w ww. j a v a2 s . co m*/ * @param sourceNode * @return a clone of node */ public static Node cloneNode(Document document, Node sourceNode) { Node clonedNode = null; // what is my name? QName sourceQName = getNodeQName(sourceNode); String nodeName = sourceQName.getLocalPart(); String namespaceURI = sourceQName.getNamespaceURI(); // if the node is unqualified, don't assume that it inherits the WS-BPEL target namespace if (Namespaces.WSBPEL2_0_FINAL_EXEC.equals(namespaceURI)) { namespaceURI = null; } switch (sourceNode.getNodeType()) { case Node.ATTRIBUTE_NODE: if (namespaceURI == null) { clonedNode = document.createAttribute(nodeName); } else { String prefix = ((Attr) sourceNode).lookupPrefix(namespaceURI); // the prefix for the XML namespace can't be looked up, hence this... if (prefix == null && namespaceURI.equals(NS_URI_XMLNS)) { prefix = "xmlns"; } // if a prefix exists, qualify the name with it if (prefix != null && !"".equals(prefix)) { nodeName = prefix + ":" + nodeName; } // create the appropriate type of attribute if (prefix != null) { clonedNode = document.createAttributeNS(namespaceURI, nodeName); } else { clonedNode = document.createAttribute(nodeName); } } break; case Node.CDATA_SECTION_NODE: clonedNode = document.createCDATASection(((CDATASection) sourceNode).getData()); break; case Node.COMMENT_NODE: clonedNode = document.createComment(((Comment) sourceNode).getData()); break; case Node.DOCUMENT_FRAGMENT_NODE: clonedNode = document.createDocumentFragment(); break; case Node.DOCUMENT_NODE: clonedNode = document; break; case Node.ELEMENT_NODE: // create the appropriate type of element if (namespaceURI == null) { clonedNode = document.createElement(nodeName); } else { String prefix = namespaceURI.equals(Namespaces.XMLNS_URI) ? "xmlns" : ((Element) sourceNode).lookupPrefix(namespaceURI); if (prefix != null && !"".equals(prefix)) { nodeName = prefix + ":" + nodeName; clonedNode = document.createElementNS(namespaceURI, nodeName); } else { clonedNode = document.createElement(nodeName); } } // attributes are not treated as child nodes, so copy them explicitly NamedNodeMap attributes = ((Element) sourceNode).getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Attr attributeClone = (Attr) cloneNode(document, attributes.item(i)); if (attributeClone.getNamespaceURI() == null) { ((Element) clonedNode).setAttributeNode(attributeClone); } else { ((Element) clonedNode).setAttributeNodeNS(attributeClone); } } break; case Node.ENTITY_NODE: // TODO break; case Node.ENTITY_REFERENCE_NODE: clonedNode = document.createEntityReference(nodeName); // TODO break; case Node.NOTATION_NODE: // TODO break; case Node.PROCESSING_INSTRUCTION_NODE: clonedNode = document.createProcessingInstruction(((ProcessingInstruction) sourceNode).getData(), nodeName); break; case Node.TEXT_NODE: clonedNode = document.createTextNode(((Text) sourceNode).getData()); break; default: break; } // clone children of element and attribute nodes NodeList sourceChildren = sourceNode.getChildNodes(); if (sourceChildren != null) { for (int i = 0; i < sourceChildren.getLength(); i++) { Node sourceChild = sourceChildren.item(i); Node clonedChild = cloneNode(document, sourceChild); clonedNode.appendChild(clonedChild); // if the child has a textual value, parse it for any embedded prefixes if (clonedChild.getNodeType() == Node.TEXT_NODE || clonedChild.getNodeType() == Node.CDATA_SECTION_NODE) { parseEmbeddedPrefixes(sourceNode, clonedNode, clonedChild); } } } return clonedNode; }
From source file:org.firesoa.common.schema.DOMInitializer.java
protected static void createAttribute(Document doc, Element elem, XmlSchemaAttributeGroupMember attrMember) { if (attrMember instanceof XmlSchemaAttribute) { XmlSchemaAttribute attrSchema = (XmlSchemaAttribute) attrMember; XmlSchemaForm attrForm = attrSchema.getForm(); Attr attr = null;//from w w w. jav a 2 s . co m QName attrSchemaQName = attrSchema.getQName(); if (XmlSchemaForm.QUALIFIED.equals(attrForm)) { String attrQualifiedName = getQualifiedName(doc, attrSchemaQName); attr = doc.createAttributeNS(attrSchemaQName.getNamespaceURI(), attrQualifiedName); } else { attr = doc.createAttribute(attrSchema.getName()); } elem.setAttributeNode(attr); String value = ""; if (!StringUtils.isEmpty(attrSchema.getFixedValue())) { value = attrSchema.getFixedValue(); } else if (!StringUtils.isEmpty(attrSchema.getDefaultValue())) { value = attrSchema.getDefaultValue(); } if (!StringUtils.isEmpty(value)) { attr.setValue(value); } } else if (attrMember instanceof XmlSchemaAttributeGroupRef) { XmlSchemaAttributeGroupRef attrGroupRef = (XmlSchemaAttributeGroupRef) attrMember; List<XmlSchemaAttributeGroupMember> groupMembers = attrGroupRef.getRef().getTarget().getAttributes(); for (XmlSchemaAttributeGroupMember groupMember : groupMembers) { createAttribute(doc, elem, groupMember); } } else if (attrMember instanceof XmlSchemaAttributeGroup) { XmlSchemaAttributeGroup attrGroup = (XmlSchemaAttributeGroup) attrMember; List<XmlSchemaAttributeGroupMember> groupMembers = attrGroup.getAttributes(); for (XmlSchemaAttributeGroupMember groupMember : groupMembers) { createAttribute(doc, elem, groupMember); } } }
From source file:org.firesoa.common.schema.DOMInitializer.java
private static String getQualifiedName(Document doc, QName qName) { Element rootElement = (Element) doc.getDocumentElement(); if (rootElement != null && !equalStrings(qName.getNamespaceURI(), rootElement.getNamespaceURI())) { // Attr attrTmp = rootElement.getAttributeNodeNS(Constants.XMLNS_ATTRIBUTE_NS_URI, "ns0"); // System.out.println("===========found attrTmp=="+attrTmp); String nsPrefix = null;/* w ww. j av a 2s . c om*/ nsPrefix = rootElement.lookupPrefix(qName.getNamespaceURI()); if (nsPrefix == null || nsPrefix.trim().equals("")) { int nsNumber = 1; NamedNodeMap attrMap = rootElement.getAttributes(); int length = attrMap.getLength(); for (int i = 0; i < length; i++) { Attr attr = (Attr) attrMap.item(i); String name = attr.getName(); if (name.startsWith(Constants.XMLNS_ATTRIBUTE)) { if (attr.getValue().equals(qName.getNamespaceURI())) { // Namespace? nsPrefix = attr.getLocalName(); break; } nsNumber++; } } if (nsPrefix == null) { nsPrefix = "ns" + nsNumber; } } Attr attr = doc.createAttributeNS(Constants.XMLNS_ATTRIBUTE_NS_URI, Constants.XMLNS_ATTRIBUTE + ":" + nsPrefix); attr.setValue(qName.getNamespaceURI()); rootElement.setAttributeNode(attr); return nsPrefix + ":" + qName.getLocalPart(); } else { return "ns0:" + qName.getLocalPart(); } }
From source file:org.globus.wsrf.tools.wsdl.TypesProcessor.java
private Element getSchema() throws Exception { Types types = this.definition.getTypes(); if (types == null) { types = definition.createTypes(); this.definition.setTypes(types); }// w ww . j a v a2 s .c om Element schema = null; List elementList = types.getExtensibilityElements(); if (elementList.isEmpty()) { UnknownExtensibilityElement extensibilityElement = new UnknownExtensibilityElement(); DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = docBuilder.newDocument(); schema = doc.createElementNS(XSD_NS, "xsd:schema"); Attr nameSpace = doc.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xsd"); nameSpace.setValue(XSD_NS); schema.setAttributeNode(nameSpace); nameSpace = doc.createAttribute("targetNamespace"); nameSpace.setValue(definition.getTargetNamespace()); schema.setAttributeNode(nameSpace); schema.appendChild(doc.createTextNode("\n ")); doc.appendChild(schema); extensibilityElement.setElement(schema); types.addExtensibilityElement(extensibilityElement); } else { schema = ((UnknownExtensibilityElement) elementList.get(0)).getElement(); } return schema; }