Package org.contextfx.components
Class Container
- java.lang.Object
-
- org.contextfx.components.Container
-
- Direct Known Subclasses:
ReactiveContainer
public class Container extends Object
This class is used to manage the components of the Java function.- Version:
- 1.0.0
- Author:
- Ramon Rangel Osorio <ramon.rangel@protonmail.com>
-
-
Field Summary
Fields Modifier and Type Field Description protected static ContainerCONTAINERstatic StringDEFAULT_IDENTIFIERprotected static Predicate<Constructor<?>>IS_DEFAULT_CONSTRUCTORprotected static Predicate<Constructor<?>>IS_PARAMETERIZED_CONSTRUCTOR
-
Constructor Summary
Constructors Modifier Constructor Description protectedContainer()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ObjectcreateInstance(Class<?> clazz)Creates an instance of the specified class using either the default constructor or the parameterized constructor.protected ObjectcreateInstanceByDefaultConstructor(Constructor<?> constructor)Creates an instance of an object using the default constructor.protected ObjectcreateInstanceByParameterizedConstructor(Constructor<?> constructor)Creates an instance using the provided parameterized constructor.protected Object[]createParametersInstances(Parameter... parameters)Creates instances for the given parameters.static ObjectgetComponent(Class<?> clazz)Retrieves the component of the specified class from the components map.static ObjectgetComponent(String identifier)Retrieves a component based on the given identifier.Map<Class<?>,Map<String,Object>>getComponents()Retrieves the components of the Java function.static ContainergetInstance()Returns an instance of the Container class.voidregister(Class<?> clazz, String identifier)Registers an instance of a class with an identifier.protected voidregister(Class<?> clazz, String identifier, Object instance)Registers a class with its identifier and instance in the component registry.voidreplace(Class<?> clazz, String identifier, Object instance)Replaces an instance in the component map with the given class, identifier, and instance.<T> Tresolver(Class<T> clazz, String identifier)Resolves and returns an instance of the specified class based on the given identifier.protected voidvalidateClasNameAndIdentifier(Class<?> clazz, String identifier)Validates the class name and identifier.
-
-
-
Field Detail
-
DEFAULT_IDENTIFIER
public static final String DEFAULT_IDENTIFIER
- See Also:
- Constant Field Values
-
IS_DEFAULT_CONSTRUCTOR
protected static final Predicate<Constructor<?>> IS_DEFAULT_CONSTRUCTOR
-
IS_PARAMETERIZED_CONSTRUCTOR
protected static final Predicate<Constructor<?>> IS_PARAMETERIZED_CONSTRUCTOR
-
CONTAINER
protected static final Container CONTAINER
-
-
Method Detail
-
getInstance
public static Container getInstance()
Returns an instance of the Container class.- Returns:
- an instance of the Container class
-
getComponents
public Map<Class<?>,Map<String,Object>> getComponents()
Retrieves the components of the Java function.- Returns:
- a map containing the components of the function, where the keys are the classes and the values are maps containing the component names and their corresponding values
-
getComponent
public static Object getComponent(Class<?> clazz)
Retrieves the component of the specified class from the components map.- Parameters:
clazz- the class of the component to retrieve- Returns:
- the component of the specified class
-
getComponent
public static Object getComponent(String identifier)
Retrieves a component based on the given identifier.- Parameters:
identifier- the identifier of the component- Returns:
- the retrieved component
-
register
public final void register(Class<?> clazz, String identifier)
Registers an instance of a class with an identifier.- Parameters:
clazz- the class to be registeredidentifier- the identifier for the instance (optional)
-
replace
public final void replace(Class<?> clazz, String identifier, Object instance)
Replaces an instance in the component map with the given class, identifier, and instance.- Parameters:
clazz- the class of the instance to replaceidentifier- the identifier of the instance to replaceinstance- the new instance to replace the existing one
-
resolver
public final <T> T resolver(Class<T> clazz, String identifier)
Resolves and returns an instance of the specified class based on the given identifier.- Type Parameters:
T- the class type returned- Parameters:
clazz- the class type of the instance to be resolvedidentifier- the identifier used to lookup the instance (can be blank)- Returns:
- the resolved instance of the specified class
- Throws:
IllegalArgumentException- if the class or identifier is not registered as components
-
register
protected final void register(Class<?> clazz, String identifier, Object instance)
Registers a class with its identifier and instance in the component registry.- Parameters:
clazz- the class to be registeredidentifier- the identifier of the classinstance- the instance of the class
-
validateClasNameAndIdentifier
protected void validateClasNameAndIdentifier(Class<?> clazz, String identifier)
Validates the class name and identifier.- Parameters:
clazz- the class to validateidentifier- the identifier to validate
-
createInstance
protected Object createInstance(Class<?> clazz)
Creates an instance of the specified class using either the default constructor or the parameterized constructor.- Parameters:
clazz- the class to create an instance of- Returns:
- the created instance
-
createInstanceByDefaultConstructor
protected Object createInstanceByDefaultConstructor(Constructor<?> constructor)
Creates an instance of an object using the default constructor.- Parameters:
constructor- the constructor used to create the instance- Returns:
- the created instance
-
createInstanceByParameterizedConstructor
protected Object createInstanceByParameterizedConstructor(Constructor<?> constructor)
Creates an instance using the provided parameterized constructor.- Parameters:
constructor- the constructor to be used for creating the instance- Returns:
- the created instance
-
-