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/DefaultRetention.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
33DefaultRetention::DefaultRetention() :
34 m_mode(ObjectLockRetentionMode::NOT_SET),
35 m_modeHasBeenSet(false),
36 m_days(0),
37 m_daysHasBeenSet(false),
38 m_years(0),
39 m_yearsHasBeenSet(false)
40{
41}
42
43DefaultRetention::DefaultRetention(const XmlNode& xmlNode) :
44 m_mode(ObjectLockRetentionMode::NOT_SET),
45 m_modeHasBeenSet(false),
46 m_days(0),
47 m_daysHasBeenSet(false),
48 m_years(0),
49 m_yearsHasBeenSet(false)
50{
51 *this = xmlNode;
52}
53
54DefaultRetention& DefaultRetention::operator =(const XmlNode& xmlNode)
55{
56 XmlNode resultNode = xmlNode;
57
58 if(!resultNode.IsNull())
59 {
60 XmlNode modeNode = resultNode.FirstChild("Mode");
61 if(!modeNode.IsNull())
62 {
63 m_mode = ObjectLockRetentionModeMapper::GetObjectLockRetentionModeForName(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(modeNode.GetText()).c_str()).c_str());
64 m_modeHasBeenSet = true;
65 }
66 XmlNode daysNode = resultNode.FirstChild("Days");
67 if(!daysNode.IsNull())
68 {
69 m_days = StringUtils::ConvertToInt32(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(daysNode.GetText()).c_str()).c_str());
70 m_daysHasBeenSet = true;
71 }
72 XmlNode yearsNode = resultNode.FirstChild("Years");
73 if(!yearsNode.IsNull())
74 {
75 m_years = StringUtils::ConvertToInt32(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(yearsNode.GetText()).c_str()).c_str());
76 m_yearsHasBeenSet = true;
77 }
78 }
79
80 return *this;
81}
82
83void DefaultRetention::AddToNode(XmlNode& parentNode) const
84{
85 Aws::StringStream ss;
86 if(m_modeHasBeenSet)
87 {
88 XmlNode modeNode = parentNode.CreateChildElement("Mode");
89 modeNode.SetText(ObjectLockRetentionModeMapper::GetNameForObjectLockRetentionMode(m_mode));
90 }
91
92 if(m_daysHasBeenSet)
93 {
94 XmlNode daysNode = parentNode.CreateChildElement("Days");
95 ss << m_days;
96 daysNode.SetText(ss.str());
97 ss.str("");
98 }
99
100 if(m_yearsHasBeenSet)
101 {
102 XmlNode yearsNode = parentNode.CreateChildElement("Years");
103 ss << m_years;
104 yearsNode.SetText(ss.str());
105 ss.str("");
106 }
107
108}
109
110} // namespace Model
111} // namespace S3
112} // namespace Aws
113