Class SubclassRegistry

java.lang.Object
org.chenile.core.transform.SubclassRegistry

public class SubclassRegistry extends Object
This is a registry of mapping base classes to the appropriate subclasses.
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 type
Subclass registration is done in the modules that own the subclass to preserve modularity.
  • Field Details

  • Constructor Details

    • SubclassRegistry

      public SubclassRegistry()
  • Method Details

    • addSubclass

      public <T> void addSubclass(Class<?> superClass, String type, Class<? extends T> subClass)
    • determineSubClass

      public Class<?> determineSubClass(String jsonString, Class<?> superClass) throws Exception
      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