Package org.chenile.core.transform
Class SubclassRegistry
java.lang.Object
org.chenile.core.transform.SubclassRegistry
This is a registry of mapping base classes to the appropriate subclasses.
For example, if there is a base class
This registry maintains these relationships.
It maintains a map of maps. The first map points to the second map and is indexed by the baseclass. The second map links the string type to the subclass. In the example below, you will find the JSON representation of the maps as follows
This is used by the
Subclass registration is done in the modules that own the subclass to preserve modularity.
For example, if there is a base class
Vehicle
which is subclassed by Car. The base
car may have a type parameter based on which the subclass exists. So if vehicle.type == 'CAR'
then it might belong to a subclass Car. On the other hand, if vehicle.type == 'BUS'
then it might belong the Bus subclass. This registry maintains these relationships.
It maintains a map of maps. The first map points to the second map and is indexed by the baseclass. The second map links the string type to the subclass. In the example below, you will find the JSON representation of the maps as follows
{
"Vehicle.class": {
"CAR" : "Car.class",
"BUS" : "Bus.class"
}
}
This is used by the
TransformationClassSelector
for determining the appropriate
subtypes for a given typeSubclass registration is done in the modules that own the subclass to preserve modularity.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription<T> void
addSubclass
(Class<?> superClass, String type, Class<? extends T> subClass) Class<?>
determineSubClass
(String jsonString, Class<?> superClass) This class looks at a JSON representation of a superclass and based on the type found in the JSON, determines the corresponding subclass.
-
Field Details
-
logger
org.slf4j.Logger logger -
objectMapper
-
registry
-
-
Constructor Details
-
SubclassRegistry
public SubclassRegistry()
-
-
Method Details
-
addSubclass
-
determineSubClass
This class looks at a JSON representation of a superclass and based on the type found in the JSON, determines the corresponding subclass.
ASSUMPTION: The class has a type field that is used to determine the subclass.- Parameters:
jsonString
- the Input JSON String that has the type.superClass
- the superClass hierarchy to look at to determine the correct subclass.- Returns:
- the correct subclass if it exists in the registry
- Throws:
Exception
-