text: ﻿/*
  * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License").
  * You may not use this file except in compliance with the License.
  * A copy of the License is located at
  *
  *  http://aws.amazon.com/apache2.0
  *
  * or in the "license" file accompanying this file. This file is distributed
  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
  */
  #include <aws/ec2/model/CreateVolumeResponse.h>
  #include <aws/core/utils/xml/XmlSerializer.h>
  #include <aws/core/AmazonWebServiceResult.h>
  #include <aws/core/utils/StringUtils.h>
  #include <aws/core/utils/logging/LogMacros.h>
  
  #include <utility>
  
  using namespace Aws::EC2::Model;
  using namespace Aws::Utils::Xml;
  using namespace Aws::Utils::Logging;
  using namespace Aws::Utils;
  using namespace Aws;
  
  CreateVolumeResponse::CreateVolumeResponse() : 
      m_size(0),
      m_iops(0),
      m_encrypted(false)
  {
  }
  
  CreateVolumeResponse::CreateVolumeResponse(const AmazonWebServiceResult<XmlDocument>& result) : 
      m_size(0),
      m_iops(0),
      m_encrypted(false)
  {
    *this = result;
  }
  
  CreateVolumeResponse& CreateVolumeResponse::operator =(const AmazonWebServiceResult<XmlDocument>& result)
  {
    const XmlDocument& xmlDocument = result.GetPayload();
    XmlNode rootNode = xmlDocument.GetRootElement();
    XmlNode resultNode = rootNode;
    if (rootNode.GetName() != "CreateVolumeResponse")
    {
      resultNode = rootNode.FirstChild("CreateVolumeResponse");
    }
  
    if(!resultNode.IsNull())
    {
      XmlNode volumeIdNode = resultNode.FirstChild("volumeId");
      if(!volumeIdNode.IsNull())
      {
        m_volumeId = StringUtils::Trim(volumeIdNode.GetText().c_str());
      }
      XmlNode sizeNode = resultNode.FirstChild("size");
      if(!sizeNode.IsNull())
      {
        m_size = StringUtils::ConvertToInt32(StringUtils::Trim(sizeNode.GetText().c_str()).c_str());
      }
      XmlNode snapshotIdNode = resultNode.FirstChild("snapshotId");
      if(!snapshotIdNode.IsNull())
      {
        m_snapshotId = StringUtils::Trim(snapshotIdNode.GetText().c_str());
      }
      XmlNode availabilityZoneNode = resultNode.FirstChild("availabilityZone");
      if(!availabilityZoneNode.IsNull())
      {
        m_availabilityZone = StringUtils::Trim(availabilityZoneNode.GetText().c_str());
      }
      XmlNode stateNode = resultNode.FirstChild("status");
      if(!stateNode.IsNull())
      {
        m_state = VolumeStateMapper::GetVolumeStateForName(StringUtils::Trim(stateNode.GetText().c_str()).c_str());
      }
      XmlNode createTimeNode = resultNode.FirstChild("createTime");
      if(!createTimeNode.IsNull())
      {
        m_createTime = DateTime(StringUtils::Trim(createTimeNode.GetText().c_str()).c_str(), DateFormat::ISO_8601);
      }
      XmlNode attachmentsNode = resultNode.FirstChild("attachmentSet");
      if(!attachmentsNode.IsNull())
      {
        XmlNode attachmentsMember = attachmentsNode.FirstChild("item");
        while(!attachmentsMember.IsNull())
        {
          m_attachments.push_back(attachmentsMember);
          attachmentsMember = attachmentsMember.NextNode("item");
        }
  
      }
      XmlNode tagsNode = resultNode.FirstChild("tagSet");
      if(!tagsNode.IsNull())
      {
        XmlNode tagsMember = tagsNode.FirstChild("item");
        while(!tagsMember.IsNull())
        {
          m_tags.push_back(tagsMember);
          tagsMember = tagsMember.NextNode("item");
        }
  
      }
      XmlNode volumeTypeNode = resultNode.FirstChild("volumeType");
      if(!volumeTypeNode.IsNull())
      {
        m_volumeType = VolumeTypeMapper::GetVolumeTypeForName(StringUtils::Trim(volumeTypeNode.GetText().c_str()).c_str());
      }
      XmlNode iopsNode = resultNode.FirstChild("iops");
      if(!iopsNode.IsNull())
      {
        m_iops = StringUtils::ConvertToInt32(StringUtils::Trim(iopsNode.GetText().c_str()).c_str());
      }
      XmlNode encryptedNode = resultNode.FirstChild("encrypted");
      if(!encryptedNode.IsNull())
      {
        m_encrypted = StringUtils::ConvertToBool(StringUtils::Trim(encryptedNode.GetText().c_str()).c_str());
      }
      XmlNode kmsKeyIdNode = resultNode.FirstChild("kmsKeyId");
      if(!kmsKeyIdNode.IsNull())
      {
        m_kmsKeyId = StringUtils::Trim(kmsKeyIdNode.GetText().c_str());
      }
    }
  
    XmlNode responseMetadataNode = rootNode.FirstChild("ResponseMetadata");
    m_responseMetadata = responseMetadataNode;
    AWS_LOGSTREAM_DEBUG("Aws::EC2::Model::CreateVolumeResponse", "x-amzn-request-id: " << m_responseMetadata.GetRequestId() );
  
    return *this;
  }
  