Class CustomLayer

java.lang.Object
overit.geocall.platform.CustomLayer
All Implemented Interfaces:
Serializable

public class CustomLayer extends Object implements Serializable
This class allows easy access to the application layers, i.e. the software layer that will contain the various application components (Task, DAO, graphics components, ...) and any customizations that will help to create the solution for the customer.
It is possible to define a layer by creating a Layer extension by assigning it a name and, eventually, a domain in case the layer root does not match the package in which the class is located.
Or you can define a layer programmatically by creating a new instance of Layer and registering it by calling the addLayer(Layer) method.

 Layer layer = new Layer("name", "layer/domain/path");
 CustomLayer.addLayer(layer);
 

Registering a layer and correctly defining its name and domain is essential for correct resolution of the components. Failure to register may result in several problems; a reference to a component defined in an unregistered layer will not take into account any customizations, or worse, may raise an exception if the referenced component is not contained in any of the other layers.
See Also:
  • Field Details

    • BASIC_LAYER_NAME

      public static final String BASIC_LAYER_NAME
      The name under which the base layer was registered and under which it can be retrieved
      See Also:
    • layer

      protected final Layer layer
      this instance contains the layer information as well as allowing the actual registration of ScriptPackage, LangPackage and ThemePackage
    • customTree

      protected final CustomTree customTree
      this instance is used to search for resources within the various custom layers
    • overLayers

      protected final Lazy<LinkedHashSet<CustomLayer>> overLayers
      this object allows you to retrieve, on demand, the list of dependent layers
    • permissions

      protected final Lazy<Permissions> permissions
    • grants

      protected final Lazy<Grants> grants
  • Method Details

    • getByName

      public static CustomLayer getByName(String name)
      Retrieves the instance of the layer from its name.
      Parameters:
      name - name of the layer you want to get the instance of
      Returns:
      the instance of the layer or null in case there is no layer associated with this name
    • getByClass

      public static CustomLayer getByClass(Class<Layer> cls)
      Retrieves the instance of the layer from its class.
      Parameters:
      cls - class of the layer you want to get the instance of
      Returns:
      the instance of the layer or null in case there is no layer associated with this class
      Throws:
      IllegalArgumentException - in case there are multiple layers registered with this class
    • getOriginal

      public static CustomLayer getOriginal()
      Returns:
      the basic application layer
    • addLayer

      public static void addLayer(Layer layer)
      Allows you to record a new layer among those registered.
      Parameters:
      layer - instance of the layer to be registered. Null value will throws a precondition exception.
      Throws:
      IllegalArgumentException - in case another layer with the same name has already been registered
    • clearLayers

      protected static void clearLayers()
    • getLayers

      public static List<CustomLayer> getLayers()
      Returns:
      the list of the registered layer
    • getSortedLayers

      public static List<CustomLayer> getSortedLayers()
      Returns:
      the list of registered layers sorted by dependencies between layers. First the over layers, i.e. those on which other layers depend.
    • getLayerIndex

      public static Integer getLayerIndex(CustomLayer customLayer)
      Returns the index of the current layer from a static table of layers in which the lower layers represent the layers imported as dependency.
      Parameters:
      customLayer - The CustomLayer
      Returns:
      the index of the current layer from a static table of layers in which the lower layers represent the layers imported as dependency.
    • getOwnerLayer

      public static CustomLayer getOwnerLayer(JavaResource pos)
      Deducts the layer to which the resource passed as a parameter, belongs
      Parameters:
      pos - the resource
      Returns:
      the instance of the layer to which the component, associated with the class passed to input, belongs or null in case there is no layer associated with that class
    • getOwnerLayer

      public static CustomLayer getOwnerLayer(Class clz)
      Deducts the layer to which the class, passed as a parameter, belongs
      Parameters:
      clz - the class
      Returns:
      the instance of the layer to which the component, associated with the class passed to input, belongs or null in case there is no layer associated with that class
    • collectResources

      public static Set<JavaResource> collectResources(JavaResource resource)
      Method that collects all the customizations of a given JavaResource by searching within all the registered CustomLayer. The order of the resources contained into the result set depends by the dependencies between the registered layers; the customized resources will be the first ones.
      Parameters:
      resource - the resource to collect
      Returns:
      the set of the collected resources
    • getName

      public String getName()
      Returns the layer's name
      Returns:
      the layer's name
    • getAlias

      public String getAlias()
      Returns the layer's alias
      Returns:
      the layer's alias or null if not defined
    • getLibraryComponent

      public Class<?> getLibraryComponent(String name)
      Method used to retrieve the class of a library component (e.g. a graphics component)
      Parameters:
      name - the name of the component
      Returns:
      the class of the registered component whose name match with the name passed in or null if the name is not associated with any component
    • getOverLayers

      public Set<CustomLayer> getOverLayers()
      Method used to obtain dependent layers The order depends on the dependencies between the registered layers; the customized resources will be the first ones.
      Returns:
      the dependent layer list. The empty list means that this layer has no dependency from any other layer.
    • getScriptPackages

      public Set<ScriptPackage> getScriptPackages()
      Method used to retrieve the packages containing the SQL script that belong to this layer
      Returns:
      the script packages of this layer. The empty list means that this layer has no sql script packages.
    • getSortedScriptPackages

      public List<ScriptPackage> getSortedScriptPackages()
      Method used to retrieve the packages containing the SQL script that belong to this layer, sorted by dependencies between packages
      Returns:
      the script packages of this layer. The empty list means that this layer has no sql script packages.
    • getCustomPackages

      public Set<CustomPackage> getCustomPackages()
      Method used to retrieve the packages containing the resources that will customize the ones refered by the original position
      Returns:
      the custom packages of this layer. The empty list means that this layer has no custom packages.
    • getThemePackage

      public ThemePackage getThemePackage()
      Method used to retrieve the package containing the themes that belong to this layer
      Returns:
      the theme package of this layer or null if this layer has no themes.
    • getLangPackage

      public LangPackage getLangPackage()
      Method used to retrieve the package containing the translation files that belong to this layer
      Returns:
      the language package of this layer or null if this layer has no translation.
    • getAllPermissions

      public Permissions getAllPermissions()
      Method used to retrieve the permissions defined in the current layer and all the 'over' layers.
      Returns:
      the permissions defined in this layer and all the 'over' layers. The union is computed matching the permission name and with priority for the customizing layer.
    • getAllGrants

      public Grants getAllGrants()
      Method used to retrieve the grants defined in the current layer and all the 'over' layers.
      Returns:
      the grants defined in this layer and all the 'over' layers. All the grants must be namespaced so that there will be non conflicts.
    • getPosition

      public String getPosition()
    • isOriginal

      public boolean isOriginal()
      Returns:
      true if the layer is the basic framework layer, false otherwise
    • isOwner

      public boolean isOwner(JavaResource pos)
      Checks if the class, passed to input, belongs to the current layer or not
      Parameters:
      pos - the class object
      Returns:
      true if the class belongs to the current layer, false otherwise.
    • loadClass

      public Class loadClass(JavaResource resource)
      This method looks for the resource passed in input by searching through the various custom layers, and returns the reference to its class, or null in case the resource does not exist in any of the registered layers.
      Parameters:
      resource - the resource to find
      Returns:
      the class of the real resource or null if the resource does not exist in any of the registered layers.
    • getURL

      public URL getURL(JavaResource resource)
      This method looks for the resource passed in input by searching through the various custom layers, and returns the URL of the real resource, or null in case the resource does not exist in any of the registered layers.
      Parameters:
      resource - the resource to find
      Returns:
      the URL of the real resource or null if the resource does not exist in any of the registered layers.
    • getSubstitute

      protected JavaResource getSubstitute(JavaResource resource)
      Search if there is a direct customization (by annotation) of the resource passed in input. The search is done only within the current layer, not in the overlayers.
      Parameters:
      resource - the resource to find
      Returns:
      the customized resource or null it it doesn't exists whitin the current layer
    • onCustom

      protected void onCustom(JavaResource resource, BiConsumer<JavaResource,CustomPackage> register)
      search if there is a customization of the resource passed in input. the search is done only within the custom packages of the current layer, not in the over layers. the found resources are hypothetical, no test is done on the actual existence of the resource in the classpath
      Parameters:
      resource - the resource to find
      register - object used to record the custom resources found
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • main

      public static void main(String[] args)
    • getLanding

      public Landing getLanding(String name, String params)