1 /*
2  * Copyright 2010-2020 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 package com.amazonaws.services.s3.model.transform;
16
17 import com.amazonaws.services.s3.internal.Constants;
18 import com.amazonaws.services.s3.internal.XmlWriter;
19 import com.amazonaws.services.s3.model.RequestPaymentConfiguration;
20 import com.amazonaws.services.s3.model.RequestPaymentConfiguration.Payer;
21
22 /**
23  * Converts Request Payment Configuration objects into XML byte arrays.
24  */

25 public class RequestPaymentConfigurationXmlFactory {
26
27     /**
28      * Converts the specified request payment configuration into an XML byte
29      * array to send to Amazon S3.
30      *
31      * Sample XML:
32      * <RequestPaymentConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
33      *         <Payer>Requester</Payer>
34      * </RequestPaymentConfiguration>
35      *
36      * @param requestPaymentConfiguration
37      *            The request payment configuration request to convert..
38      * @return The XML byte array representation.
39      */

40     public byte[] convertToXmlByteArray(
41             RequestPaymentConfiguration requestPaymentConfiguration) {
42         XmlWriter xml = new XmlWriter();
43         xml.start("RequestPaymentConfiguration""xmlns",
44                 Constants.XML_NAMESPACE);
45
46         Payer payer = requestPaymentConfiguration.getPayer();
47         if (payer != null) {
48             XmlWriter payerDocumentElement = xml.start("Payer");
49             payerDocumentElement.value(payer.toString());
50             payerDocumentElement.end();
51         }
52         xml.end();
53         return xml.getBytes();
54     }
55 }
56