Class BeanStore
- Direct Known Subclasses:
- BeanStore.Void,- SpringBeanStore
A simple storage database for beans keyed by type and name. Used to retrieve and instantiate beans using an injection-like API. It's similar in concept to the injection framework of Spring but greatly simplified in function and not intended to implement a full-fledged injection framework.
 Beans can be stored with or without names.  Named beans are typically resolved using
 the 
Beans are added through the following methods:
- add(Class,Object)
- add(Class,Object,String)
- addBean(Class,Object)
- addBean(Class,Object,String)
- addSupplier(Class,Supplier)
- addSupplier(Class,Supplier,String)
Beans are retrieved through the following methods:
Beans are created through the following methods:
- createBean(Class)
- createMethodFinder(Class)
- createMethodFinder(Class,Class)
- createMethodFinder(Class,Object)
Notes:
- Bean stores can be nested using BeanStore.Builder.parent(BeanStore).
- Bean stores can be made read-only using BeanStore.Builder.readOnly().
- Bean stores can be made thread-safe using BeanStore.Builder.threadSafe().
See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classBuilder class.static final classNon-existent bean store.
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescription<T> TSame asaddBean(Class,Object)but returns the bean instead of this object for fluent calls.<T> TSame asaddBean(Class,Object,String)but returns the bean instead of this object for fluent calls.<T> BeanStoreAdds an unnamed bean of the specified type to this factory.<T> BeanStoreAdds a named bean of the specified type to this factory.<T> BeanStoreaddSupplier(Class<T> beanType, Supplier<T> bean) Adds a supplier for an unnamed bean of the specified type to this factory.<T> BeanStoreaddSupplier(Class<T> beanType, Supplier<T> bean, String name) Adds a supplier for a named bean of the specified type to this factory.clear()Clears out all bean in this bean store.static BeanStore.Buildercreate()Static creator.<T> BeanCreator<T>createBean(Class<T> beanType) Instantiates a bean creator.protected <T> BeanStoreEntry<T>createEntry(Class<T> type, Supplier<T> bean, String name) Creates an entry in this store for the specified bean.<T> BeanCreateMethodFinder<T>createMethodFinder(Class<T> beanType) Create a method finder for finding bean creation methods.<T> BeanCreateMethodFinder<T>createMethodFinder(Class<T> beanType, Class<?> resourceClass) Create a method finder for finding bean creation methods.<T> BeanCreateMethodFinder<T>createMethodFinder(Class<T> beanType, Object resource) Create a method finder for finding bean creation methods.<T> Optional<T>Returns the unnamed bean of the specified type.<T> Optional<T>Returns the named bean of the specified type.getMissingParams(ExecutableInfo executable) Given an executable, returns a list of types that are missing from this factory.Object[]getParams(ExecutableInfo executable) Returns the corresponding beans in this factory for the specified param types.booleanhasAllParams(ExecutableInfo executable) Given the list of param types, returnstrue if this factory has all the parameters for the specified executable.booleanReturnstrue if this store contains the specified unnamed bean type.booleanReturnstrue if this store contains the specified named bean type.static BeanStoreStatic creator.static BeanStoreStatic creator.removeBean(Class<?> beanType) Removes an unnamed bean from this store.removeBean(Class<?> beanType, String name) Removes a named bean from this store.<T> Stream<BeanStoreEntry<T>>Returns all the beans in this store of the specified type.toString()
- 
Field Details- 
INSTANCEStatic read-only reusable instance.
 
- 
- 
Constructor Details- 
BeanStoreConstructor.- Parameters:
- builder- The builder containing the settings for this bean.
 
 
- 
- 
Method Details- 
createStatic creator.- Returns:
- A new BeanStore.Builderobject.
 
- 
ofStatic creator.- Parameters:
- parent- Parent bean store. Can be- null if this is the root resource.
- Returns:
- A new BeanStoreobject.
 
- 
ofStatic creator.- Parameters:
- parent- Parent bean store. Can be- null if this is the root resource.
- outer- The outer bean used when instantiating inner classes. Can be- null .
- Returns:
- A new BeanStoreobject.
 
- 
addBeanAdds an unnamed bean of the specified type to this factory.- Type Parameters:
- T- The class to associate this bean with.
- Parameters:
- beanType- The class to associate this bean with.
- bean- The bean. Can be- null .
- Returns:
- This object.
 
- 
addBeanAdds a named bean of the specified type to this factory.- Type Parameters:
- T- The class to associate this bean with.
- Parameters:
- beanType- The class to associate this bean with.
- bean- The bean. Can be- null .
- name- The bean name if this is a named bean. Can be- null .
- Returns:
- This object.
 
- 
addSupplierAdds a supplier for an unnamed bean of the specified type to this factory.- Type Parameters:
- T- The class to associate this bean with.
- Parameters:
- beanType- The class to associate this bean with.
- bean- The bean supplier.
- Returns:
- This object.
 
- 
addSupplierAdds a supplier for a named bean of the specified type to this factory.- Type Parameters:
- T- The class to associate this bean with.
- Parameters:
- beanType- The class to associate this bean with.
- bean- The bean supplier.
- name- The bean name if this is a named bean. Can be- null .
- Returns:
- This object.
 
- 
addSame asaddBean(Class,Object)but returns the bean instead of this object for fluent calls.- Type Parameters:
- T- The class to associate this bean with.
- Parameters:
- beanType- The class to associate this bean with.
- bean- The bean. Can be- null .
- Returns:
- The bean.
 
- 
addSame asaddBean(Class,Object,String)but returns the bean instead of this object for fluent calls.- Type Parameters:
- T- The class to associate this bean with.
- Parameters:
- beanType- The class to associate this bean with.
- bean- The bean. Can be- null .
- name- The bean name if this is a named bean. Can be- null .
- Returns:
- The bean.
 
- 
clearClears out all bean in this bean store.Does not affect the parent bean store. - Returns:
- This object.
 
- 
getBeanReturns the unnamed bean of the specified type.- Type Parameters:
- T- The type of bean to return.
- Parameters:
- beanType- The type of bean to return.
- Returns:
- The bean.
 
- 
getBeanReturns the named bean of the specified type.- Type Parameters:
- T- The type of bean to return.
- Parameters:
- beanType- The type of bean to return.
- name- The bean name. Can be- null .
- Returns:
- The bean.
 
- 
streamReturns all the beans in this store of the specified type.Returns both named and unnamed beans. The results from the parent bean store are appended to the list of beans from this beans store. - Type Parameters:
- T- The bean type to return.
- Parameters:
- beanType- The bean type to return.
- Returns:
- The bean entries.  Never null .
 
- 
removeBeanRemoves an unnamed bean from this store.- Parameters:
- beanType- The bean type being removed.
- Returns:
- This object.
 
- 
removeBeanRemoves a named bean from this store.- Parameters:
- beanType- The bean type being removed.
- name- The bean name to remove.
- Returns:
- This object.
 
- 
hasBeanReturnstrue if this store contains the specified unnamed bean type.- Parameters:
- beanType- The bean type to check.
- Returns:
- true if this store contains the specified unnamed bean type.
 
- 
hasBeanReturnstrue if this store contains the specified named bean type.- Parameters:
- beanType- The bean type to check.
- name- The bean name.
- Returns:
- true if this store contains the specified named bean type.
 
- 
createBeanInstantiates a bean creator.See Also:- BeanCreatorfor usage.
 - Type Parameters:
- T- The bean type to create.
- Parameters:
- beanType- The bean type to create.
- Returns:
- A new bean creator.
 
- 
createMethodFinderCreate a method finder for finding bean creation methods.See Also:- BeanCreateMethodFinderfor usage.
 - Type Parameters:
- T- The bean type to create.
- Parameters:
- beanType- The bean type to create.
- resource- The class containing the bean creator method.
- Returns:
- The method finder.  Never null .
 
- 
createMethodFinderCreate a method finder for finding bean creation methods.Same as createMethodFinder(Class,Class)but looks for only static methods on the specified resource class and not also instance methods within the context of a bean.See Also:- BeanCreateMethodFinderfor usage.
 - Type Parameters:
- T- The bean type to create.
- Parameters:
- beanType- The bean type to create.
- resourceClass- The class containing the bean creator method.
- Returns:
- The method finder.  Never null .
 
- 
createMethodFinderCreate a method finder for finding bean creation methods.Same as createMethodFinder(Class,Object)but usesBeanStore.Builder.outer(Object)as the resource bean.See Also:- BeanCreateMethodFinderfor usage.
 - Type Parameters:
- T- The bean type to create.
- Parameters:
- beanType- The bean type to create.
- Returns:
- The method finder.  Never null .
 
- 
getMissingParamsGiven an executable, returns a list of types that are missing from this factory.- Parameters:
- executable- The constructor or method to get the params for.
- Returns:
- A comma-delimited list of types that are missing from this factory, or null if none are missing.
 
- 
hasAllParamsGiven the list of param types, returnstrue if this factory has all the parameters for the specified executable.- Parameters:
- executable- The constructor or method to get the params for.
- Returns:
- A comma-delimited list of types that are missing from this factory.
 
- 
getParamsReturns the corresponding beans in this factory for the specified param types.- Parameters:
- executable- The constructor or method to get the params for.
- Returns:
- The corresponding beans in this factory for the specified param types.
 
- 
toString
- 
createEntryCreates an entry in this store for the specified bean.Subclasses can override this method to create their own entry subtypes. - Type Parameters:
- T- The class type to associate with the bean.
- Parameters:
- type- The class type to associate with the bean.
- bean- The bean supplier.
- name- Optional name to associate with the bean. Can be- null .
- Returns:
- A new bean store entry.
 
 
-