Home / Class/ ValueObject Class — spring-boot Architecture

ValueObject Class — spring-boot Architecture

Architecture documentation for the ValueObject class in ValueObjectBinder.java from the spring-boot codebase.

Entity Profile

Relationship Graph

Source Code

core/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/ValueObjectBinder.java lines 197–261

	private abstract static class ValueObject<T> {

		private static final Object NONE = new Object();

		private final Constructor<T> constructor;

		protected ValueObject(Constructor<T> constructor) {
			this.constructor = constructor;
		}

		T instantiate(List<@Nullable Object> args) {
			return BeanUtils.instantiateClass(this.constructor, args.toArray());
		}

		abstract List<ConstructorParameter> getConstructorParameters();

		@SuppressWarnings("unchecked")
		static <T> @Nullable ValueObject<T> get(Bindable<T> bindable, Binder.Context context,
				BindConstructorProvider constructorProvider, ParameterNameDiscoverer parameterNameDiscoverer) {
			Class<T> resolvedType = (Class<T>) bindable.getType().resolve();
			if (resolvedType == null || resolvedType.isEnum() || Modifier.isAbstract(resolvedType.getModifiers())) {
				return null;
			}
			Map<CacheKey, Object> cache = getCache(context);
			CacheKey cacheKey = new CacheKey(bindable, constructorProvider, parameterNameDiscoverer);
			Object valueObject = cache.get(cacheKey);
			if (valueObject == null) {
				valueObject = get(bindable, context, constructorProvider, parameterNameDiscoverer, resolvedType);
				cache.put(cacheKey, (valueObject != null) ? valueObject : NONE);
			}
			return (valueObject != NONE) ? (ValueObject<T>) valueObject : null;
		}

		@SuppressWarnings("unchecked")
		private static <T> @Nullable ValueObject<T> get(Bindable<T> bindable, Binder.Context context,
				BindConstructorProvider constructorProvider, ParameterNameDiscoverer parameterNameDiscoverer,
				Class<T> resolvedType) {
			Constructor<?> bindConstructor = constructorProvider.getBindConstructor(bindable,
					context.isNestedConstructorBinding());
			if (bindConstructor == null) {
				return null;
			}
			if (KotlinDetector.isKotlinType(resolvedType)) {
				return KotlinValueObject.get((Constructor<T>) bindConstructor, bindable.getType(),
						parameterNameDiscoverer);
			}
			return DefaultValueObject.get(bindConstructor, bindable.getType(), parameterNameDiscoverer);
		}

		@SuppressWarnings("unchecked")
		private static Map<CacheKey, Object> getCache(Context context) {
			Map<CacheKey, Object> cache = (Map<CacheKey, Object>) context.getCache().get(ValueObject.class);
			if (cache == null) {
				cache = new ConcurrentHashMap<>();
				context.getCache().put(ValueObject.class, cache);
			}
			return cache;
		}

		private record CacheKey(Bindable<?> bindable, BindConstructorProvider constructorProvider,
				ParameterNameDiscoverer parameterNameDiscoverer) {

		}

	}

Domain

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free