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/ReplicationRule.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
33ReplicationRule::ReplicationRule() :
34 m_iDHasBeenSet(false),
35 m_priority(0),
36 m_priorityHasBeenSet(false),
37 m_filterHasBeenSet(false),
38 m_status(ReplicationRuleStatus::NOT_SET),
39 m_statusHasBeenSet(false),
40 m_sourceSelectionCriteriaHasBeenSet(false),
41 m_existingObjectReplicationHasBeenSet(false),
42 m_destinationHasBeenSet(false),
43 m_deleteMarkerReplicationHasBeenSet(false)
44{
45}
46
47ReplicationRule::ReplicationRule(const XmlNode& xmlNode) :
48 m_iDHasBeenSet(false),
49 m_priority(0),
50 m_priorityHasBeenSet(false),
51 m_filterHasBeenSet(false),
52 m_status(ReplicationRuleStatus::NOT_SET),
53 m_statusHasBeenSet(false),
54 m_sourceSelectionCriteriaHasBeenSet(false),
55 m_existingObjectReplicationHasBeenSet(false),
56 m_destinationHasBeenSet(false),
57 m_deleteMarkerReplicationHasBeenSet(false)
58{
59 *this = xmlNode;
60}
61
62ReplicationRule& ReplicationRule::operator =(const XmlNode& xmlNode)
63{
64 XmlNode resultNode = xmlNode;
65
66 if(!resultNode.IsNull())
67 {
68 XmlNode iDNode = resultNode.FirstChild("ID");
69 if(!iDNode.IsNull())
70 {
71 m_iD = Aws::Utils::Xml::DecodeEscapedXmlText(iDNode.GetText());
72 m_iDHasBeenSet = true;
73 }
74 XmlNode priorityNode = resultNode.FirstChild("Priority");
75 if(!priorityNode.IsNull())
76 {
77 m_priority = StringUtils::ConvertToInt32(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(priorityNode.GetText()).c_str()).c_str());
78 m_priorityHasBeenSet = true;
79 }
80 XmlNode filterNode = resultNode.FirstChild("Filter");
81 if(!filterNode.IsNull())
82 {
83 m_filter = filterNode;
84 m_filterHasBeenSet = true;
85 }
86 XmlNode statusNode = resultNode.FirstChild("Status");
87 if(!statusNode.IsNull())
88 {
89 m_status = ReplicationRuleStatusMapper::GetReplicationRuleStatusForName(StringUtils::Trim(Aws::Utils::Xml::DecodeEscapedXmlText(statusNode.GetText()).c_str()).c_str());
90 m_statusHasBeenSet = true;
91 }
92 XmlNode sourceSelectionCriteriaNode = resultNode.FirstChild("SourceSelectionCriteria");
93 if(!sourceSelectionCriteriaNode.IsNull())
94 {
95 m_sourceSelectionCriteria = sourceSelectionCriteriaNode;
96 m_sourceSelectionCriteriaHasBeenSet = true;
97 }
98 XmlNode existingObjectReplicationNode = resultNode.FirstChild("ExistingObjectReplication");
99 if(!existingObjectReplicationNode.IsNull())
100 {
101 m_existingObjectReplication = existingObjectReplicationNode;
102 m_existingObjectReplicationHasBeenSet = true;
103 }
104 XmlNode destinationNode = resultNode.FirstChild("Destination");
105 if(!destinationNode.IsNull())
106 {
107 m_destination = destinationNode;
108 m_destinationHasBeenSet = true;
109 }
110 XmlNode deleteMarkerReplicationNode = resultNode.FirstChild("DeleteMarkerReplication");
111 if(!deleteMarkerReplicationNode.IsNull())
112 {
113 m_deleteMarkerReplication = deleteMarkerReplicationNode;
114 m_deleteMarkerReplicationHasBeenSet = true;
115 }
116 }
117
118 return *this;
119}
120
121void ReplicationRule::AddToNode(XmlNode& parentNode) const
122{
123 Aws::StringStream ss;
124 if(m_iDHasBeenSet)
125 {
126 XmlNode iDNode = parentNode.CreateChildElement("ID");
127 iDNode.SetText(m_iD);
128 }
129
130 if(m_priorityHasBeenSet)
131 {
132 XmlNode priorityNode = parentNode.CreateChildElement("Priority");
133 ss << m_priority;
134 priorityNode.SetText(ss.str());
135 ss.str("");
136 }
137
138 if(m_filterHasBeenSet)
139 {
140 XmlNode filterNode = parentNode.CreateChildElement("Filter");
141 m_filter.AddToNode(filterNode);
142 }
143
144 if(m_statusHasBeenSet)
145 {
146 XmlNode statusNode = parentNode.CreateChildElement("Status");
147 statusNode.SetText(ReplicationRuleStatusMapper::GetNameForReplicationRuleStatus(m_status));
148 }
149
150 if(m_sourceSelectionCriteriaHasBeenSet)
151 {
152 XmlNode sourceSelectionCriteriaNode = parentNode.CreateChildElement("SourceSelectionCriteria");
153 m_sourceSelectionCriteria.AddToNode(sourceSelectionCriteriaNode);
154 }
155
156 if(m_existingObjectReplicationHasBeenSet)
157 {
158 XmlNode existingObjectReplicationNode = parentNode.CreateChildElement("ExistingObjectReplication");
159 m_existingObjectReplication.AddToNode(existingObjectReplicationNode);
160 }
161
162 if(m_destinationHasBeenSet)
163 {
164 XmlNode destinationNode = parentNode.CreateChildElement("Destination");
165 m_destination.AddToNode(destinationNode);
166 }
167
168 if(m_deleteMarkerReplicationHasBeenSet)
169 {
170 XmlNode deleteMarkerReplicationNode = parentNode.CreateChildElement("DeleteMarkerReplication");
171 m_deleteMarkerReplication.AddToNode(deleteMarkerReplicationNode);
172 }
173
174}
175
176} // namespace Model
177} // namespace S3
178} // namespace Aws
179