Class Factory

java.lang.Object
overit.geocall.platform.Factory

public class Factory extends Object
Utility class used to create an instance of an another class. This utility class is very important because it allows to get an instance of another class by passing the name of the class or directly the class itself. The name of the class can be passed if the class lies in the same package of the caller, otherwise it must have the relative path starting from the layer root. The resolution of the class depends from the identity package, that can be deducted automatically or can be explicity passed with a caller .The searching logic is: search inside the package of the identity and then in all the other levels, the order of the levels depends from the layers. This allows the possibility to extends other classes with some specific logic inside that may differ from project to project assuring the creation of the right class.
  • Field Details

  • Method Details

    • getCacheDimension

      public static int getCacheDimension()
      Returns the cache dimension
      Returns:
      The cache dimension
    • invalidateCache

      public static void invalidateCache()
      Invalidates the cache
    • packageFromObject

      public static String packageFromObject(Object o)
      Calculates the absolute package of a class of this object
      Parameters:
      o - the object
      Returns:
      null if the object parameter is null, otherwise the package of the class
    • packageFromClass

      public static String packageFromClass(Class<?> c)
      Calculates the absolute package of a class
      Parameters:
      c - the class
      Returns:
      null if the class parameter is null, otherwise the package of the class
    • packageFromPath

      public static String packageFromPath(String path)
      Calculates the absolute package of a resource's path
      Parameters:
      path - the path of a resource (it can reference whatever resource within the classpath)
      Returns:
      the package of the resource
    • getSubstituted

      public static Class<?> getSubstituted(Class<?> c)
      Calculate the original class reference in case the class passed as a parameter is a Platform.Substitute.
      Parameters:
      c - the class
      Returns:
      the original class or the class passed in if it is not annotated with the Platform.Substitute.
    • findLibraryComponent

      protected static Class<?> findLibraryComponent(String path, CustomLayer cl)
    • realPath

      public static String realPath(String path, Object caller)
      Returns the physical position of a logical resource searching all across the layer customizations.
      Parameters:
      path - the path. It can be relative to the caller or absolute depending by the path format. A path starting with // is absolute and already resolved. It will not be changed. A path starting with + will be translated to overit/geocall/basic/ and will be resolved. Otherwise the path will be searched all across all the layer customizations relatively to the position of the caller If the caller is null, the path is meant to be absolute, otherwise the path could meant to be absolute if it starts with leading /, or could be referred to the caller position. In both cases the path will be resolved
      caller - the object requesting the path used as a starting position. If it is null, the path is meant to be absolute
      Returns:
      the canonical form for the path with reference to the caller position.
    • realPath

      public static JavaResource realPath(String path, Class<?> from)
      Returns the physical position of a logical resource searching all across the layer customizations.
      Parameters:
      path - the path. It can be absolute or relative, depending on from A path starting with // is absolute and already resolved and will not be changed. A path starting with + wil be translated to overit/geocall/basic/ and will be resolved. Otherwise the path will be searched all across all the layer customizations relatively to the position of the from If the from is null, the path is meant to be absolute, otherwise the path could meant to be absolute if it starts with leading /, or could be referred to the caller position. In both cases the path will be resolved
      from - the starting position. If it is null, the path is meant to be absolute
      Returns:
      the resource form for the path with reference to the caller position.
    • realPath

      public static JavaResource realPath(String path, String from)
      Returns the physical position of a logical resource searching all across the layer customizations.
      Parameters:
      path - the path. It can be absolute or relative, depending on from A path starting with // is absolute and already resolved and will not be changed. A path starting with + wil be translated to overit/geocall/basic/ and will be resolved as an absolute path. Otherwise the path will be searched all across all the layer customizations. If the from position is null, the path is ment to be absolute, otherwise the path is meant with reference to the from position, and will be resolved
      from - the starting position. If it is null, the path is meant to be absolute
      Returns:
      the resource form for the path inside the from position, with a leading "/" to indicate that the resource is already resolved.
    • workingLayer

      public static CustomLayer workingLayer(String from)
      Extract the identity's layer from the one bind to the thread, otherwise try to infer it by the from path
      Parameters:
      from - the path used to infer the layer belongs to
      Returns:
      the layer of the current identity
    • make

      public static <T> T make(String path)
      Creates an instance of an object defined and compatible with the class parameter. The best implementation will be searched all across the layer customizations and Platform.Substitute.
      Type Parameters:
      T - the desired type for the object
      Parameters:
      path - the absolute path defining the desired resource. The object will be searched all across all the layer customizations and substitutes driven by the current Identity and the relative CustomLayer
      Returns:
      the best instance for the requested object.
    • make

      public static <T> T make(Class<T> clz)
      Creates an instance of an object defined and compatible with the class parameter. The best implementation will be searched all across the layer customizations and Platform.Substitute.
      Type Parameters:
      T - the desired type for the object
      Parameters:
      clz - the class defining the desired instance. The object will be searched all across all the layer customizations and substitutes driven by the current Identity and the relative CustomLayer
      Returns:
      the best instance for the requested object.
    • make

      @Deprecated public static <T> T make(Class<T> clz, Object caller)
      Deprecated.
      Creates an instance of an object defined and compatible with the class parameter. The best implementation will be searched all across the layer customizations and Platform.Substitute.
      Type Parameters:
      T - the desired type for the object
      Parameters:
      clz - the class defining the desired instance The object will be searched all across all the layer customizations and substitutes driven by the current Identity and the relative CustomLayer
      caller - useless parameter
      Returns:
      the best instance for the requested object
    • make

      public static <T> T make(String path, Object caller)
      Creates an instance of an object defined by a logical position. The best implementation will be searched all across the layer customizations and Platform.Substitute.
      Type Parameters:
      T - the desired type for the object
      Parameters:
      path - the path. It can be relative to the caller or absolute depending by the path format. A path starting with // is absolute and already resolved. It will not be changed. A path starting with + wil be translated to overit/geocall/basic/ and will be resolved as an absolute path. Otherwise the path will be searched all across all the layer customizations relatively to the position of the caller. If the caller is null, the path is meant to be absolute, otherwise the path is meant with reference to the caller position, and will be resolved
      caller - the object requesting the the starting position. If it is null, the path is meant to be absolute
      Returns:
      the best instance for the requested object.
    • make

      public static <T> T make(String path, Class<?> from)
      Creates an instance of an object defined by a logical position. The best implementatio will be searched all across the layer customizations.
      Type Parameters:
      T - the desired type for the object
      Parameters:
      path - the path. It can be relative to the from or absolute depending by the path format. A path starting with // is absolute and already resolved. It will not be changed. A path starting with + wil be translated to overit/geocall/basic/ and will be resolved as an absolute path. Otherwise the path will be searched all across all the layer customizations relatively to the position of the from If the from is null, the path is meant to be absolute, otherwise the path could meant to be absolute if it starts with leading /, or could be referred to the from position. In both cases the path will be resolved
      from - the starting position. If it is null, the path is meant to be absolute
      Returns:
      the best instance for the requested object.
    • makeClass

      public static <T> Class<T> makeClass(Class<T> clz)
      Identifies and returns a Class defined and compatible with the class parameter. It can be the same class or an extension.
      Type Parameters:
      T - the desired type for the object
      Parameters:
      clz - the class defining the desired instance
      Returns:
      the best class for the requested object
    • makeClass

      public static <T> Class<T> makeClass(Type type)
      Identifies and returns a Class defined and compatible with the type parameter. It can be the same type or an extension.
      Type Parameters:
      T - the desired type for the object
      Parameters:
      type - the type defining the desired instance
      Returns:
      the best class for the requested object
    • makeClass

      public static <T> Class<T> makeClass(String path)
      Identifies and returns a Class defined and compatible with the path parameter.
      Type Parameters:
      T - the desired class for the object
      Parameters:
      path - the absolute path of the class. A path starting with / is already resolved and will not be changed. A path starting with + will be translated to overit/geocall/basic/ and will be resolved as an absolute path. Otherwise the path will be searched all across all the layer customizations.
      Returns:
      the best class for the requested object
    • makeClass

      public static <T> Class<T> makeClass(String path, Class<?> from)
      Identifies and returns a Class defined and compatible with the path parameter.
      Type Parameters:
      T - the desired class for the object
      Parameters:
      path - the path of the class. It can be absolute or relative, depending on from A path starting with // is absolute and already resolved. It will not be changed. A path starting with + will be translated to overit/geocall/basic/ and will be resolved as an absolute path. Otherwise the path will be searched all across all the layer customizations and Platform.Substitute. If the from position is null, the path is meant to be absolute, otherwise the path is meant with reference to the from position, and will be resolved
      from - the starting position. If it is null, the path is meant to be absolute
      Returns:
      the best class for the requested object
    • makeClass

      public static <T> Class<T> makeClass(String path, String from)
      Identifies and returns a Class defined and compatible with the path parameter.
      Type Parameters:
      T - the desired class for the object
      Parameters:
      path - the path of the class. It can be absolute or relative, depending on from A path starting with // is absolute and already resolved. It will not be changed. A path starting with + will be translated to overit/geocall/basic/ and will be resolved as an absolute path. Otherwise the path will be searched all across all the layer customizations and Platform.Substitute. If the from position is null, the path is meant to be absolute, otherwise the path is meant with reference to the from position, and will be resolved
      from - the starting position. If it is null, the path is meant to be absolute
      Returns:
      the best class for the requested object
    • newInstance

      public static <T> T newInstance(JavaResource res)
      creates an instance of a defined path possibly transmitting Identity information
      Type Parameters:
      T - the desired class for the object
      Parameters:
      res - the path for the requested class
      Returns:
      the instance of the requested class
    • newInstance

      public static <T> T newInstance(Class<T> realClz)
      creates an instance of the class possibly transmitting Identity information
      Type Parameters:
      T - the desired class for the object
      Parameters:
      realClz - the requested class
      Returns:
      the instance of the requested class
    • getStream

      public static InputStream getStream(String realpath)
      open a stream to the resource object expressed in the parameter.
      Parameters:
      realpath - the absolute path to the resource
      Returns:
      the stream to the resource object
    • collect

      public static List<JavaResource> collect(String res, Class<?> from)
      Returns a list containing the matched resources, searching all across the layer customizations.
      Parameters:
      res - the requested resource. It can be absolute or relative, depending on from A path starting with // is absolute and already resolved and will not be changed. A path starting with + wil be translated to overit/geocall/basic/ and will be resolved as an absolute path. Otherwise the path will be searched all across all the layer customizations. If the from position is null, the res is meant to be absolute, otherwise the res is meant with reference to the from position, and will be resolved
      from - the starting position. If it is null, the path is meant to be absolute
      Returns:
      a list containing the resolved resources
    • collect

      public static List<JavaResource> collect(String res, String from)
      Returns a list containing the matched resources, searching all across the layer customizations.
      Parameters:
      res - the requested resource. It can be absolute or relative, depending on from A path starting with // is absolute and already resolved and will not be changed. A path starting with + wil be translated to overit/geocall/basic/ and will be resolved as an absolute path. Otherwise the path will be searched all across all the layer customizations. If the from position is null, the res is meant to be absolute, otherwise the res is meant with reference to the from position, and will be resolved
      from - the starting position. If it is null, the res is meant to be absolute
      Returns:
      a list containing the resolved resources
    • collectResources

      @Deprecated public static List<JavaResource> collectResources(String res)
      Deprecated.
      Returns a list containing the matched resources, searching all across the layer customizations.
      Parameters:
      res - the requested resource. It must be relative to the root of the layer.
      Returns:
      a list containing the resolved resources