1/*
2* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3*
4* Licensed under the Apache License, Version 2.0 (the "License").
5* You may not use this file except in compliance with the License.
6* A copy of the License is located at
7*
8* http://aws.amazon.com/apache2.0
9*
10* or in the "license" file accompanying this file. This file is distributed
11* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12* express or implied. See the License for the specific language governing
13* permissions and limitations under the License.
14*/
15
16#include <aws/s3/model/Transition.h>
17#include <aws/core/utils/xml/XmlSerializer.h>
18#include <aws/core/utils/StringUtils.h>
19#include <aws/core/utils/memory/stl/AWSStringStream.h>
20
21#include <utility>
22
23using namespace Aws::Utils::Xml;
24using namespace Aws::Utils;
25
26namespace Aws
27{
28namespace S3
29{
30namespace Model
31{
32
33Transition::Transition() :
34 m_dateHasBeenSet(false),
35 m_days(0),
36 m_daysHasBeenSet(false),
37 m_storageClass(TransitionStorageClass::NOT_SET),
38 m_storageClassHasBeenSet(false)
39{
40}
41
42Transition::Transition(const XmlNode& xmlNode) :
43 m_dateHasBeenSet(false),
44 m_days(0),
45 m_daysHasBeenSet(false),
46 m_storageClass(TransitionStorageClass::NOT_SET),
47 m_storageClassHasBeenSet(false)
48{
49 *this = xmlNode;
50}
51
52Transition& Transition::operator =(const XmlNode& xmlNode)
53{
54 XmlNode resultNode = xmlNode;
55
56 if(!resultNode.IsNull())
57 {
58 XmlNode dateNode = resultNode.FirstChild("Date");
59 if(!dateNode.IsNull())
60 {
61 m_date = DateTime(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(dateNode.GetText()).c_str()).c_str(), DateFormat::ISO_8601);
62 m_dateHasBeenSet = true;
63 }
64 XmlNode daysNode = resultNode.FirstChild("Days");
65 if(!daysNode.IsNull())
66 {
67 m_days = StringUtils::ConvertToInt32(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(daysNode.GetText()).c_str()).c_str());
68 m_daysHasBeenSet = true;
69 }
70 XmlNode storageClassNode = resultNode.FirstChild("StorageClass");
71 if(!storageClassNode.IsNull())
72 {
73 m_storageClass = TransitionStorageClassMapper::GetTransitionStorageClassForName(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(storageClassNode.GetText()).c_str()).c_str());
74 m_storageClassHasBeenSet = true;
75 }
76 }
77
78 return *this;
79}
80
81void Transition::AddToNode(XmlNode& parentNode) const
82{
83 Aws::StringStream ss;
84 if(m_dateHasBeenSet)
85 {
86 XmlNode dateNode = parentNode.CreateChildElement("Date");
87 dateNode.SetText(m_date.ToGmtString(DateFormat::ISO_8601));
88 }
89
90 if(m_daysHasBeenSet)
91 {
92 XmlNode daysNode = parentNode.CreateChildElement("Days");
93 ss << m_days;
94 daysNode.SetText(ss.str());
95 ss.str("");
96 }
97
98 if(m_storageClassHasBeenSet)
99 {
100 XmlNode storageClassNode = parentNode.CreateChildElement("StorageClass");
101 storageClassNode.SetText(TransitionStorageClassMapper::GetNameForTransitionStorageClass(m_storageClass));
102 }
103
104}
105
106} // namespace Model
107} // namespace S3
108} // namespace Aws
109