Class CachingLocaleUrlDefinitionDAO
java.lang.Object
org.apache.tiles.core.definition.dao.BaseLocaleUrlDefinitionDAO
org.apache.tiles.core.definition.dao.CachingLocaleUrlDefinitionDAO
- All Implemented Interfaces:
DefinitionDAO<Locale>,PatternDefinitionResolverAware<Locale>,RefreshMonitor
- Direct Known Subclasses:
ResolvingLocaleUrlDefinitionDAO
public class CachingLocaleUrlDefinitionDAO
extends BaseLocaleUrlDefinitionDAO
implements PatternDefinitionResolverAware<Locale>
A definitions DAO (loading URLs and using Locale as a customization key) that caches definitions that have been loaded in a raw way (i.e. with inheritance that is not resolved).
It can check if the URLs change, but by default this feature is turned off.
- Since:
- 2.1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringInitialization parameter to set whether we want to refresh URLs when they change.protected booleanFlag that, whentrue, enables automatic checking of URLs changing.static final intDefault upper bound on the number of customization keys (locales) whose definitions are cached at once.protected PatternDefinitionResolver<Locale>Resolves definitions using patterns.protected Map<Locale,Map<String, Definition>> The locale-specific set of definitions objects.protected intMaximum number of customization keys (locales) retained inlocale2definitionMap.Fields inherited from class org.apache.tiles.core.definition.dao.BaseLocaleUrlDefinitionDAO
applicationContext, lastModifiedDates, reader, sources -
Constructor Summary
ConstructorsConstructorDescriptionCachingLocaleUrlDefinitionDAO(ApplicationContext applicationContext) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected Map<String,Definition> checkAndloadDefinitions(Locale customizationKey) Checks if sources have changed.protected Map<String,Definition> copyDefinitionMap(Map<String, Definition> localeDefsMap) Copies the definition map to be passed to a higher level of customization key.getDefinition(String name, Locale customizationKey) Returns a definition, given its name and the customization key.protected DefinitiongetDefinitionFromResolver(String name, Locale customizationKey) Returns a definition from the definition resolver.getDefinitions(Locale customizationKey) Returns all the definitions used of a customization key.protected Map<String,Definition> loadDefinitions(Locale customizationKey) Tries to load definitions if necessary.protected Map<String,Definition> loadDefinitionsFromResources(Locale customizationKey) Loads definitions from the sources.protected Map<String,Definition> loadParentDefinitions(Locale parentLocale) Loads parent definitions, i.e. definitions mapped to a parent locale.protected Map<String,Definition> loadRawDefinitionsFromResources(Locale customizationKey) Loads the raw definitions from the sources associated with a locale.voidsetCheckRefresh(boolean checkRefresh) Sets the flag to check source refresh.voidsetMaxCachedLocales(int maxCachedLocales) Sets the maximum number of customization keys (locales) whose definitions are cached.voidsetPatternDefinitionResolver(PatternDefinitionResolver<Locale> definitionResolver) Sets the pattern definition resolver to use.Methods inherited from class org.apache.tiles.core.definition.dao.BaseLocaleUrlDefinitionDAO
loadDefinitionsFromResource, refreshRequired, setReader, setSources
-
Field Details
-
CHECK_REFRESH_INIT_PARAMETER
Initialization parameter to set whether we want to refresh URLs when they change.- Since:
- 2.1.0
- See Also:
-
DEFAULT_MAX_CACHED_LOCALES
public static final int DEFAULT_MAX_CACHED_LOCALESDefault upper bound on the number of customization keys (locales) whose definitions are cached at once. Since the customization key is derived from the request locale, this bounds the cache so it cannot grow without limit as distinct locales are encountered.- See Also:
-
locale2definitionMap
The locale-specific set of definitions objects.- Since:
- 2.1.0
-
maxCachedLocales
protected int maxCachedLocalesMaximum number of customization keys (locales) retained inlocale2definitionMap. When exceeded, the eldest entry is evicted (and reloaded on demand if requested again). -
checkRefresh
protected boolean checkRefreshFlag that, whentrue, enables automatic checking of URLs changing.- Since:
- 2.1.0
-
definitionResolver
Resolves definitions using patterns.- Since:
- 2.2.0
-
-
Constructor Details
-
CachingLocaleUrlDefinitionDAO
Constructor.- Since:
- 2.1.0
-
-
Method Details
-
setMaxCachedLocales
public void setMaxCachedLocales(int maxCachedLocales) Sets the maximum number of customization keys (locales) whose definitions are cached. When more distinct keys are requested, the eldest cached entry is evicted so the cache cannot grow without bound. Evicted entries are reloaded on demand if requested again, so eviction never changes rendering, only re-incurs a load.- Parameters:
maxCachedLocales- the maximum number of cached customization keys; values below 1 are treated as 1
-
setPatternDefinitionResolver
Sets the pattern definition resolver to use.- Specified by:
setPatternDefinitionResolverin interfacePatternDefinitionResolverAware<Locale>- Parameters:
definitionResolver- The pattern definition resolver.
-
getDefinition
Returns a definition, given its name and the customization key.- Specified by:
getDefinitionin interfaceDefinitionDAO<Locale>- Parameters:
name- The name of the definition.customizationKey- The customization key.- Returns:
- The requested definition, if found, otherwise
null. The inheritance of the definition must not be resolved.
-
getDefinitions
Returns all the definitions used of a customization key.- Specified by:
getDefinitionsin interfaceDefinitionDAO<Locale>- Parameters:
customizationKey- The customization key.- Returns:
- All the definitions that are connected to the customization key. The inheritance of the definitions must not be resolved.
-
setCheckRefresh
public void setCheckRefresh(boolean checkRefresh) Sets the flag to check source refresh. If not called, the default isfalse.- Parameters:
checkRefresh- Whentrue, enables automatic checking of sources changing.- Since:
- 2.1.0
-
getDefinitionFromResolver
Returns a definition from the definition resolver.- Parameters:
name- The name of the definition.customizationKey- The customization key to use.- Returns:
- The resolved definition.
-
checkAndloadDefinitions
Checks if sources have changed. If yes, it clears the cache. Then continues loading definitions.- Parameters:
customizationKey- The locale to use when loading sources.- Returns:
- The loaded definitions.
- Since:
- 2.1.0
-
loadDefinitions
Tries to load definitions if necessary.- Parameters:
customizationKey- The locale to use when loading sources.- Returns:
- The loaded definitions.
- Since:
- 2.1.0
-
loadDefinitionsFromResources
Loads definitions from the sources.- Parameters:
customizationKey- The locale to use when loading Resources.- Returns:
- The loaded definitions.
- Since:
- 2.1.0
-
loadRawDefinitionsFromResources
Loads the raw definitions from the sources associated with a locale.- Parameters:
customizationKey- The locale to use when loading Resources.- Returns:
- The loaded definitions.
- Since:
- 2.1.3
-
loadParentDefinitions
Loads parent definitions, i.e. definitions mapped to a parent locale.- Parameters:
parentLocale- The locale to use when loading URLs.- Returns:
- The loaded parent definitions.
- Since:
- 2.1.0
-
copyDefinitionMap
Copies the definition map to be passed to a higher level of customization key.- Parameters:
localeDefsMap- The map of definition to be copied.- Returns:
- The copy of the definition map. This particular implementation
return the
localeDefsMapitself. - Since:
- 2.1.4
-