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.enhanced.dynamodb.internal.converter; 17 18 import java.util.List; 19 import software.amazon.awssdk.annotations.SdkInternalApi; 20 import software.amazon.awssdk.enhanced.dynamodb.AttributeConverterProvider; 21 import software.amazon.awssdk.enhanced.dynamodb.DefaultAttributeConverterProvider; 22 23 /** 24 * Static module to assist with the initialization of attribute converter providers for a StaticTableSchema. 25 */ 26 @SdkInternalApi 27 public final class ConverterProviderResolver { 28 29 private static final AttributeConverterProvider DEFAULT_ATTRIBUTE_CONVERTER = 30 DefaultAttributeConverterProvider.create(); 31 ConverterProviderResolver()32 private ConverterProviderResolver() { 33 } 34 35 /** 36 * Static provider for the default attribute converters that are bundled with the DynamoDB Enhanced Client. 37 * This provider will be used by default unless overridden in the static table schema builder or using bean 38 * annotations. 39 */ defaultConverterProvider()40 public static AttributeConverterProvider defaultConverterProvider() { 41 return DEFAULT_ATTRIBUTE_CONVERTER; 42 } 43 44 /** 45 * Resolves a list of attribute converter providers into a single provider. If the list is a singleton, 46 * it will just return that provider, otherwise it will combine them into a 47 * {@link ChainConverterProvider} using the order provided in the list. 48 * 49 * @param providers A list of providers to be combined in strict order 50 * @return A single provider that combines all the supplied providers or null if no providers were supplied 51 */ resolveProviders(List<AttributeConverterProvider> providers)52 public static AttributeConverterProvider resolveProviders(List<AttributeConverterProvider> providers) { 53 if (providers == null || providers.isEmpty()) { 54 return null; 55 } 56 57 if (providers.size() == 1) { 58 return providers.get(0); 59 } 60 61 return ChainConverterProvider.create(providers); 62 } 63 } 64