Package com.framed.orchestrator
Class Factory
java.lang.Object
com.framed.orchestrator.Factory
The
Factory class provides dynamic instantiation of Service implementations
based on JSON configuration. It uses Java reflection to match constructor parameters with
configuration keys and injects an EventBus where required.
Features:
- Dynamically loads classes by name using
Class.forName(String). - Matches constructor parameters with JSON configuration keys.
- Automatically injects an
EventBusinto constructors.
Matching Logic:
- If a constructor parameter name matches a key in the JSON config, its value is used.
- If a parameter type is
EventBus, the provided event bus is injected. - If no matching constructor is found, a
ClassNotFoundExceptionis thrown.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Serviceinstantiate(org.json.JSONObject config, EventBus eventBus) Instantiates aServiceimplementation based on the provided configuration and event bus.
-
Method Details
-
instantiate
public static Service instantiate(org.json.JSONObject config, EventBus eventBus) throws ClassNotFoundException, InvocationTargetException, InstantiationException, IllegalAccessException Instantiates aServiceimplementation based on the provided configuration and event bus.The method attempts to find a constructor whose parameters match the keys in the JSON config or require an
EventBus. If a match is found, the constructor is invoked with the resolved arguments.- Parameters:
config- the JSON configuration containing the class name and constructor argumentseventBus- the event bus to inject into constructors that require it- Returns:
- a new
Serviceinstance - Throws:
ClassNotFoundException- if no matching constructor is found or the class cannot be loadedInvocationTargetException- if the constructor invocation failsInstantiationException- if the class cannot be instantiatedIllegalAccessException- if the constructor is not accessible
-