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.codegen.model.config.customization; 17 18 import software.amazon.awssdk.codegen.model.intermediate.MemberModel; 19 import software.amazon.awssdk.codegen.model.intermediate.ShapeModel; 20 21 /** 22 * Customization to allow generation of additional setter overloads for a 'convenience' type (i.e. a 23 * different type then what the member actually is but a more convenient representation to work 24 * with, I.E. String rather than SdkBytes). Customization is configured with an adapter that knows 25 * how to convert the 'convenience' type to the actual member type 26 * <p> 27 * Note - This customization is not directly exposed through {@link CustomizationConfig} at the 28 * moment. Instead several pre-canned customizations use this under the hood but expose limited 29 * functionality for overloading setters. This decision was made to discourage use of overloaded 30 * types and instead model the member in a more natural way to begin with. In the future we may 31 * either decide to fully expose this customization or just add more pre-canned settings as the need 32 * arises 33 * </p> 34 * <p> 35 * Currently this does not support overloads for List or Map types but it could be easily 36 * implemented in the Generator. 37 * </p> 38 */ 39 public class ConvenienceTypeOverload { 40 41 /** 42 * Name of the shape this customization applies to 43 */ 44 private String shapeName; 45 46 /** 47 * Name of the member this customization applies to 48 */ 49 private String memberName; 50 51 /** 52 * Convenience type to generate an overload for 53 */ 54 private String convenienceType; 55 56 /** 57 * Fully qualified adapter class that can convert from the convenience type to the actual type 58 */ 59 private String typeAdapterFqcn; 60 getShapeName()61 public String getShapeName() { 62 return shapeName; 63 } 64 setShapeName(String shapeName)65 public void setShapeName(String shapeName) { 66 this.shapeName = shapeName; 67 } 68 withShapeName(String shapeName)69 public ConvenienceTypeOverload withShapeName(String shapeName) { 70 this.shapeName = shapeName; 71 return this; 72 } 73 getMemberName()74 public String getMemberName() { 75 return memberName; 76 } 77 setMemberName(String memberName)78 public void setMemberName(String memberName) { 79 this.memberName = memberName; 80 } 81 withMemberName(String memberName)82 public ConvenienceTypeOverload withMemberName(String memberName) { 83 this.memberName = memberName; 84 return this; 85 } 86 getConvenienceType()87 public String getConvenienceType() { 88 return convenienceType; 89 } 90 setConvenienceType(String convenienceType)91 public void setConvenienceType(String convenienceType) { 92 this.convenienceType = convenienceType; 93 } 94 withConvenienceType(String convenienceType)95 public ConvenienceTypeOverload withConvenienceType(String convenienceType) { 96 this.convenienceType = convenienceType; 97 return this; 98 } 99 getTypeAdapterFqcn()100 public String getTypeAdapterFqcn() { 101 return typeAdapterFqcn; 102 } 103 setTypeAdapterFqcn(String typeAdapterFqcn)104 public void setTypeAdapterFqcn(String typeAdapterFqcn) { 105 this.typeAdapterFqcn = typeAdapterFqcn; 106 } 107 withTypeAdapterFqcn(String typeAdapterFqcn)108 public ConvenienceTypeOverload withTypeAdapterFqcn(String typeAdapterFqcn) { 109 this.typeAdapterFqcn = typeAdapterFqcn; 110 return this; 111 } 112 113 /** 114 * @param shape 115 * Current shape 116 * @param member 117 * Current member 118 * @return True if the {@link ConvenienceTypeOverload} applies. False otherwise 119 */ accepts(ShapeModel shape, MemberModel member)120 public boolean accepts(ShapeModel shape, MemberModel member) { 121 return shape.getC2jName().equals(shapeName) && member.getC2jName().equals(memberName); 122 } 123 } 124