1 /*
2  * Copyright 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 package software.amazon.awssdk.protocols.xml.internal.unmarshall;
17
18 import software.amazon.awssdk.annotations.SdkInternalApi;
19 import software.amazon.awssdk.core.protocol.MarshallLocation;
20 import software.amazon.awssdk.core.protocol.MarshallingType;
21 import software.amazon.awssdk.protocols.core.AbstractMarshallingRegistry;
22
23 @SdkInternalApi
24 public final class XmlUnmarshallerRegistry extends AbstractMarshallingRegistry {
25
26     private XmlUnmarshallerRegistry(Builder builder) {
27         super(builder);
28     }
29
30     @SuppressWarnings("unchecked")
31     public <T> XmlUnmarshaller<Object> getUnmarshaller(MarshallLocation marshallLocation, MarshallingType<T> marshallingType) {
32         return (XmlUnmarshaller<Object>) get(marshallLocation, marshallingType);
33     }
34
35     /**
36      * @return Builder instance to construct a {@link XmlUnmarshallerRegistry}.
37      */

38     public static Builder builder() {
39         return new Builder();
40     }
41
42     /**
43      * Builder for a {@link XmlUnmarshallerRegistry}.
44      */

45     public static final class Builder extends AbstractMarshallingRegistry.Builder {
46
47         private Builder() {
48         }
49
50         public <T> Builder payloadUnmarshaller(MarshallingType<T> marshallingType,
51                                                XmlUnmarshaller<T> marshaller) {
52             register(MarshallLocation.PAYLOAD, marshallingType, marshaller);
53             return this;
54         }
55
56         public <T> Builder headerUnmarshaller(MarshallingType<T> marshallingType,
57                                               XmlUnmarshaller<T> marshaller) {
58             register(MarshallLocation.HEADER, marshallingType, marshaller);
59             return this;
60         }
61
62         public <T> Builder statusCodeUnmarshaller(MarshallingType<T> marshallingType,
63                                                   XmlUnmarshaller<T> marshaller) {
64             register(MarshallLocation.STATUS_CODE, marshallingType, marshaller);
65             return this;
66         }
67
68         /**
69          * @return An immutable {@link XmlUnmarshallerRegistry} object.
70          */

71         public XmlUnmarshallerRegistry build() {
72             return new XmlUnmarshallerRegistry(this);
73         }
74     }
75 }
76