
infra.beans.factory.aot.AutowiredArguments Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2017 - 2024 the original author or authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see [https://www.gnu.org/licenses/]
*/
package infra.beans.factory.aot;
import infra.lang.Assert;
import infra.lang.Nullable;
import infra.util.ClassUtils;
/**
* Resolved arguments to be autowired.
*
* @author Phillip Webb
* @author Stephane Nicoll
* @see BeanInstanceSupplier
* @see AutowiredMethodArgumentsResolver
* @since 4.0
*/
@FunctionalInterface
public interface AutowiredArguments {
/**
* Return the resolved argument at the specified index.
*
* @param the type of the argument
* @param index the argument index
* @param requiredType the required argument type
* @return the argument
*/
@SuppressWarnings("unchecked")
@Nullable
default T get(int index, Class requiredType) {
Object value = getObject(index);
if (!ClassUtils.isAssignableValue(requiredType, value)) {
throw new IllegalArgumentException("Argument type mismatch: expected '" +
ClassUtils.getQualifiedName(requiredType) + "' for value [" + value + "]");
}
return (T) value;
}
/**
* Return the resolved argument at the specified index.
*
* @param the type of the argument
* @param index the argument index
* @return the argument
*/
@SuppressWarnings("unchecked")
@Nullable
default T get(int index) {
return (T) getObject(index);
}
/**
* Return the resolved argument at the specified index.
*
* @param index the argument index
* @return the argument
*/
@Nullable
default Object getObject(int index) {
return toArray()[index];
}
/**
* Return the arguments as an object array.
*
* @return the arguments as an object array
*/
Object[] toArray();
/**
* Factory method to create a new {@link AutowiredArguments} instance from
* the given object array.
*
* @param arguments the arguments
* @return a new {@link AutowiredArguments} instance
*/
static AutowiredArguments of(Object[] arguments) {
Assert.notNull(arguments, "'arguments' is required");
return () -> arguments;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy