Class DefaultBringBeanFactory
java.lang.Object
com.bobocode.bring.core.context.impl.DefaultBringBeanFactory
- All Implemented Interfaces:
BringBeanFactory
- Direct Known Subclasses:
AnnotationBringBeanRegistry
Default implementation of the BringBeanFactory interface providing basic bean management functionalities.
Manages bean definitions, singleton, and prototype beans.
- Since:
- 1.0
- Author:
- Blyzhnytsia Team
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map
<String, BeanDefinition> private String
private TypeResolverFactory
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addBeanDefinition
(String beanName, BeanDefinition beanDefinition) Adds a bean definition to the factory with the given name and definition.(package private) void
addPrototypeBean
(String beanName, Supplier<Object> supplier) Adds a prototype bean to the factory with the given name and supplier.(package private) void
addSingletonBean
(String beanName, Object bean) Adds a singleton bean to the factory with the given name and instance.void
close()
Closes the container.This method is typically called when the container is being shut down to allow beans to perform necessary cleanup operations or release resources before being destroyed.Retrieves a list containing names of all registered bean definitions in the factory.Retrieves all singleton beans registered in the factory.<T> T
Retrieves a bean of the given type from the bean factory.<T> T
Retrieves a bean of the given type and name from the bean factory.getBeanByName
(String beanName) Retrieves a bean instance by its name.getBeanDefinitionByName
(String beanName) Retrieves the bean definition associated with the given bean name.Retrieves all beans of the specified type from the factory.private <T> T
getPrimary
(Map<String, T> beans, Class<T> type) boolean
isBeanCreated
(String beanName) Checks if a bean with the specified name has been created.
-
Field Details
-
beanDefinitionMap
-
typeToBeanNames
-
singletonObjects
-
prototypeSuppliers
-
properties
-
profileName
-
typeResolverFactory
-
-
Constructor Details
-
DefaultBringBeanFactory
public DefaultBringBeanFactory()
-
-
Method Details
-
getBean
Retrieves a bean of the given type from the bean factory. If multiple beans of the same type exist, returns the primary one.- Specified by:
getBean
in interfaceBringBeanFactory
- Type Parameters:
T
- The type of the bean.- Parameters:
type
- The class type of the bean to retrieve.- Returns:
- The bean instance.
- Throws:
NoSuchBeanException
- If no bean of the given type is found.NoUniqueBeanException
- If more than one primary bean of the given type is found.
-
getBean
Retrieves a bean of the given type and name from the bean factory.- Specified by:
getBean
in interfaceBringBeanFactory
- Type Parameters:
T
- The type of the bean.- Parameters:
type
- The class type of the bean to retrieve.name
- The name of the bean.- Returns:
- The bean instance.
- Throws:
NoSuchBeanException
- If no bean of the given type and name is found.
-
getBeans
Retrieves all beans of the specified type from the factory.- Specified by:
getBeans
in interfaceBringBeanFactory
- Type Parameters:
T
- The type of the beans.- Parameters:
type
- The type of the beans to retrieve.- Returns:
- A map of bean names to their respective instances.
-
getBeanByName
Retrieves a bean instance by its name.- Parameters:
beanName
- The name of the bean.- Returns:
- The retrieved bean instance.
-
getAllBeans
Retrieves all singleton beans registered in the factory.- Specified by:
getAllBeans
in interfaceBringBeanFactory
- Type Parameters:
T
- The type of the beans.- Returns:
- A map of singleton bean names to their respective instances.
-
close
public void close()Description copied from interface:BringBeanFactory
Closes the container.This method is typically called when the container is being shut down to allow beans to perform necessary cleanup operations or release resources before being destroyed.- Specified by:
close
in interfaceBringBeanFactory
-
addSingletonBean
Adds a singleton bean to the factory with the given name and instance.- Parameters:
beanName
- The name of the singleton bean.bean
- The instance of the singleton bean to be added.
-
addPrototypeBean
Adds a prototype bean to the factory with the given name and supplier.- Parameters:
beanName
- The name of the prototype bean.supplier
- The supplier supplying instances of the prototype bean.
-
addBeanDefinition
Adds a bean definition to the factory with the given name and definition. Updates the type-to-bean-names mapping accordingly.- Parameters:
beanName
- The name of the bean.beanDefinition
- The definition of the bean to be added.
-
getBeanDefinitionByName
Retrieves the bean definition associated with the given bean name.- Parameters:
beanName
- The name of the bean for which the definition is requested.- Returns:
- The BeanDefinition object associated with the provided bean name.
-
getAllBeanDefinitionNames
Retrieves a list containing names of all registered bean definitions in the factory.- Returns:
- A list containing the names of all registered bean definitions.
-
isBeanCreated
Checks if a bean with the specified name has been created.- Parameters:
beanName
- The name of the bean to check.- Returns:
- true if the bean has been created, false otherwise.
-
getPrimary
-