Class TenantSpecificResourceLoader
java.lang.Object
org.chenile.utils.tenancy.TenantSpecificResourceLoader
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic URLgetResource(String resourceTemplate) static URLgetResource(String resourceTemplate, String tenantId) Returns a tenant specific resource.static InputStreamgetResourceAsStream(String resourceTemplate) static InputStreamgetResourceAsStream(String resourceTemplate, String tenantId) Looks for a tenant specific resource.protected CachedValueobtainFileName(String name, String tenantId) protected CachedValueobtainValue(String name, String tenantId) protected CachedValuepopulateValue(String filename, URL url) Override this to store cached values that have information specific to the particular sub class By default the Cached Value stores URL and filename.
-
Field Details
-
delimiter
-
tenantSpecificPath
-
genericPath
-
templateStore
-
GENERIC_TENANT_NAME
- See Also:
-
-
Constructor Details
-
TenantSpecificResourceLoader
-
-
Method Details
-
getResource
-
getResourceAsStream
-
getResourceAsStream
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
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
-
obtainFileName
-
obtainValue
-
lookup
- Throws:
Exception
-
populateValue
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 forurl- - URL- Returns:
- the cached value
- Throws:
Exception- if there is a problem
-