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.core.traits;
17
18 import software.amazon.awssdk.annotations.SdkProtectedApi;
19 import software.amazon.awssdk.core.protocol.MarshallLocation;
20
21 /**
22 * Trait to include metadata about the marshalling/unmarshalling location (i.e. headers/payload/etc).
23 */
24 @SdkProtectedApi
25 public final class LocationTrait implements Trait {
26
27 private final MarshallLocation location;
28 private final String locationName;
29 private final String unmarshallLocationName;
30
31 private LocationTrait(Builder builder) {
32 this.location = builder.location;
33 this.locationName = builder.locationName;
34 this.unmarshallLocationName = builder.unmarshallLocationName == null ?
35 builder.locationName : builder.unmarshallLocationName;
36 }
37
38 /**
39 * @return Location of member (i.e. headers/query/path/payload).
40 */
41 public MarshallLocation location() {
42 return location;
43 }
44
45 /**
46 * @return Location name of member. I.E. the header or query param name, or the JSON field name, etc.
47 */
48 public String locationName() {
49 return locationName;
50 }
51
52 /**
53 * @return Location name for unmarshalling. This is only needed for the legacy EC2 protocol which has
54 * different serialization/deserialization for the same fields.
55 */
56 public String unmarshallLocationName() {
57 return unmarshallLocationName;
58 }
59
60 /**
61 * @return Builder instance.
62 */
63 public static Builder builder() {
64 return new Builder();
65 }
66
67 /**
68 * Builder for {@link LocationTrait}.
69 */
70 public static final class Builder {
71
72 private MarshallLocation location;
73 private String locationName;
74 private String unmarshallLocationName;
75
76 private Builder() {
77 }
78
79 public Builder location(MarshallLocation location) {
80 this.location = location;
81 return this;
82 }
83
84 public Builder locationName(String locationName) {
85 this.locationName = locationName;
86 return this;
87 }
88
89 public Builder unmarshallLocationName(String unmarshallLocationName) {
90 this.unmarshallLocationName = unmarshallLocationName;
91 return this;
92 }
93
94 public LocationTrait build() {
95 return new LocationTrait(this);
96 }
97
98 }
99 }
100