Class TenantSpecificResourceLoader

java.lang.Object
org.chenile.utils.tenancy.TenantSpecificResourceLoader

public class TenantSpecificResourceLoader extends Object
A class that looks for a specific resource (using tenantSpecificPath) from the class path. If the tenant specific resource is not found then a generic path (genericPath is used. The resource is then opened and the name and URL are returned by calling obtainFileName(String, String) and obtainURL(String, String) Variable %{name} and %{tenantId} can be used for finding the name of the resource in both the generic and tenant specific paths.
Author:
Raja Shankar Kolluru
  • Field Details

  • Constructor Details

    • TenantSpecificResourceLoader

      public TenantSpecificResourceLoader(String tenantSpecificPath, String genericPath)
  • Method Details

    • getResource

      public static URL getResource(String resourceTemplate)
    • getResourceAsStream

      public static InputStream getResourceAsStream(String resourceTemplate)
    • getResourceAsStream

      public static InputStream getResourceAsStream(String resourceTemplate, String tenantId)
      Looks for a tenant specific resource. If tenant specific resource is not present, looks for a generic resource by skipping the tenant specific part.
      For example, consider a resource template "org/chenile/%{tenantId}/a.json". Let us say we have a tenant "abc". This returns org/chenile/abc/a.json if it is present. Else it will return org/chenile/a.json if that is present. Else it will return null.
      Parameters:
      resourceTemplate - - resource name with tenantId in it of the form stated above.
      Returns:
      the input stream of the discovered resource. null if absent.
    • getResource

      public static URL getResource(String resourceTemplate, String tenantId)
      Returns a tenant specific resource. If tenant specific resource is not present, return a generic resource by skipping the tenant specific part.
      For example, consider a resource template "org/chenile/%{tenantId}/a.json". Let us say we have a tenant "abc". This returns org/chenile/abc/a.json if it is present. Else it will return org/chanile/a.json if that is present. Else it will return null.
      Parameters:
      resourceTemplate - - resource name with tenantId in it of the form stated above.
      Returns:
      the URL of the discovered resource or null if not available.
    • obtainURL

      public URL obtainURL(String name, String tenantId)
    • obtainFileName

      public String obtainFileName(String name, String tenantId)
    • obtainValue

      protected CachedValue obtainValue(String name, String tenantId)
    • lookup

      protected CachedValue lookup(Key key) throws Exception
      Throws:
      Exception
    • populateValue

      protected CachedValue populateValue(String filename, URL url) throws Exception
      Override this to store cached values that have information specific to the particular sub class By default the Cached Value stores URL and filename. But the specific sub class might choose to cache additional resources.
      Parameters:
      filename - the filename to look for
      url - - URL
      Returns:
      the cached value
      Throws:
      Exception - if there is a problem