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/InventoryConfiguration.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 | |
23 | using namespace Aws::Utils::Xml; |
24 | using namespace Aws::Utils; |
25 | |
26 | namespace Aws |
27 | { |
28 | namespace S3 |
29 | { |
30 | namespace Model |
31 | { |
32 | |
33 | InventoryConfiguration::InventoryConfiguration() : |
34 | m_destinationHasBeenSet(false), |
35 | m_isEnabled(false), |
36 | m_isEnabledHasBeenSet(false), |
37 | m_filterHasBeenSet(false), |
38 | m_idHasBeenSet(false), |
39 | m_includedObjectVersions(InventoryIncludedObjectVersions::NOT_SET), |
40 | m_includedObjectVersionsHasBeenSet(false), |
41 | m_optionalFieldsHasBeenSet(false), |
42 | m_scheduleHasBeenSet(false) |
43 | { |
44 | } |
45 | |
46 | InventoryConfiguration::InventoryConfiguration(const XmlNode& xmlNode) : |
47 | m_destinationHasBeenSet(false), |
48 | m_isEnabled(false), |
49 | m_isEnabledHasBeenSet(false), |
50 | m_filterHasBeenSet(false), |
51 | m_idHasBeenSet(false), |
52 | m_includedObjectVersions(InventoryIncludedObjectVersions::NOT_SET), |
53 | m_includedObjectVersionsHasBeenSet(false), |
54 | m_optionalFieldsHasBeenSet(false), |
55 | m_scheduleHasBeenSet(false) |
56 | { |
57 | *this = xmlNode; |
58 | } |
59 | |
60 | InventoryConfiguration& InventoryConfiguration::operator =(const XmlNode& xmlNode) |
61 | { |
62 | XmlNode resultNode = xmlNode; |
63 | |
64 | if(!resultNode.IsNull()) |
65 | { |
66 | XmlNode destinationNode = resultNode.FirstChild("Destination" ); |
67 | if(!destinationNode.IsNull()) |
68 | { |
69 | m_destination = destinationNode; |
70 | m_destinationHasBeenSet = true; |
71 | } |
72 | XmlNode isEnabledNode = resultNode.FirstChild("IsEnabled" ); |
73 | if(!isEnabledNode.IsNull()) |
74 | { |
75 | m_isEnabled = StringUtils::ConvertToBool(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(isEnabledNode.GetText()).c_str()).c_str()); |
76 | m_isEnabledHasBeenSet = true; |
77 | } |
78 | XmlNode filterNode = resultNode.FirstChild("Filter" ); |
79 | if(!filterNode.IsNull()) |
80 | { |
81 | m_filter = filterNode; |
82 | m_filterHasBeenSet = true; |
83 | } |
84 | XmlNode idNode = resultNode.FirstChild("Id" ); |
85 | if(!idNode.IsNull()) |
86 | { |
87 | m_id = Aws::Utils::Xml::DecodeEscapedXmlText(idNode.GetText()); |
88 | m_idHasBeenSet = true; |
89 | } |
90 | XmlNode includedObjectVersionsNode = resultNode.FirstChild("IncludedObjectVersions" ); |
91 | if(!includedObjectVersionsNode.IsNull()) |
92 | { |
93 | m_includedObjectVersions = InventoryIncludedObjectVersionsMapper::GetInventoryIncludedObjectVersionsForName(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(includedObjectVersionsNode.GetText()).c_str()).c_str()); |
94 | m_includedObjectVersionsHasBeenSet = true; |
95 | } |
96 | XmlNode optionalFieldsNode = resultNode.FirstChild("OptionalFields" ); |
97 | if(!optionalFieldsNode.IsNull()) |
98 | { |
99 | XmlNode optionalFieldsMember = optionalFieldsNode.FirstChild("Field" ); |
100 | while(!optionalFieldsMember.IsNull()) |
101 | { |
102 | m_optionalFields.push_back(InventoryOptionalFieldMapper::GetInventoryOptionalFieldForName(StringUtils::Trim(optionalFieldsMember.GetText().c_str()))); |
103 | optionalFieldsMember = optionalFieldsMember.NextNode("Field" ); |
104 | } |
105 | |
106 | m_optionalFieldsHasBeenSet = true; |
107 | } |
108 | XmlNode scheduleNode = resultNode.FirstChild("Schedule" ); |
109 | if(!scheduleNode.IsNull()) |
110 | { |
111 | m_schedule = scheduleNode; |
112 | m_scheduleHasBeenSet = true; |
113 | } |
114 | } |
115 | |
116 | return *this; |
117 | } |
118 | |
119 | void InventoryConfiguration::AddToNode(XmlNode& parentNode) const |
120 | { |
121 | Aws::StringStream ss; |
122 | if(m_destinationHasBeenSet) |
123 | { |
124 | XmlNode destinationNode = parentNode.CreateChildElement("Destination" ); |
125 | m_destination.AddToNode(destinationNode); |
126 | } |
127 | |
128 | if(m_isEnabledHasBeenSet) |
129 | { |
130 | XmlNode isEnabledNode = parentNode.CreateChildElement("IsEnabled" ); |
131 | ss << std::boolalpha << m_isEnabled; |
132 | isEnabledNode.SetText(ss.str()); |
133 | ss.str("" ); |
134 | } |
135 | |
136 | if(m_filterHasBeenSet) |
137 | { |
138 | XmlNode filterNode = parentNode.CreateChildElement("Filter" ); |
139 | m_filter.AddToNode(filterNode); |
140 | } |
141 | |
142 | if(m_idHasBeenSet) |
143 | { |
144 | XmlNode idNode = parentNode.CreateChildElement("Id" ); |
145 | idNode.SetText(m_id); |
146 | } |
147 | |
148 | if(m_includedObjectVersionsHasBeenSet) |
149 | { |
150 | XmlNode includedObjectVersionsNode = parentNode.CreateChildElement("IncludedObjectVersions" ); |
151 | includedObjectVersionsNode.SetText(InventoryIncludedObjectVersionsMapper::GetNameForInventoryIncludedObjectVersions(m_includedObjectVersions)); |
152 | } |
153 | |
154 | if(m_optionalFieldsHasBeenSet) |
155 | { |
156 | XmlNode optionalFieldsParentNode = parentNode.CreateChildElement("OptionalFields" ); |
157 | for(const auto& item : m_optionalFields) |
158 | { |
159 | XmlNode optionalFieldsNode = optionalFieldsParentNode.CreateChildElement("InventoryOptionalField" ); |
160 | optionalFieldsNode.SetText(InventoryOptionalFieldMapper::GetNameForInventoryOptionalField(item)); |
161 | } |
162 | } |
163 | |
164 | if(m_scheduleHasBeenSet) |
165 | { |
166 | XmlNode scheduleNode = parentNode.CreateChildElement("Schedule" ); |
167 | m_schedule.AddToNode(scheduleNode); |
168 | } |
169 | |
170 | } |
171 | |
172 | } // namespace Model |
173 | } // namespace S3 |
174 | } // namespace Aws |
175 | |