Class ResourceReferenceRegistry
- java.lang.Object
-
- org.apache.wicket.request.resource.ResourceReferenceRegistry
-
public class ResourceReferenceRegistry extends Object
Allows to register and lookupResourceReference
s per Application.- Author:
- Matej Knopp, Juergen Donnerstag
- See Also:
Application.getResourceReferenceRegistry()
,Application.newResourceReferenceRegistry()
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ResourceReferenceRegistry.DefaultResourceReferenceFactory
A simple implementation ofIResourceReferenceFactory
that createsPackageResourceReference
-
Constructor Summary
Constructors Constructor Description ResourceReferenceRegistry()
Constructor.ResourceReferenceRegistry(IResourceReferenceFactory resourceReferenceFactory)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearAutoAddedEntries()
Unregisters all auto-added Resource Referencesprotected ResourceReference
createDefaultResourceReference(ResourceReference.Key key)
Creates a default resource reference in case no registry entry and it was requested to create one.int
getAutoAddedCacheSize()
int
getAutoAddedCapacity()
Gets cache size in number of entriesResourceReference
getResourceReference(Class<?> scope, String name, Locale locale, String style, String variation, boolean strict, boolean createIfNotFound)
Get a resource reference matching the parameters from the registry or if not found and requested, create an default resource reference and add it to the registry.ResourceReference
getResourceReference(ResourceReference.Key key, boolean strict, boolean createIfNotFound)
Get a resource reference matching the parameters from the registry or if not found and requested, create an default resource reference and add it to the registry.IResourceReferenceFactory
getResourceReferenceFactory()
int
getSize()
boolean
registerResourceReference(ResourceReference reference)
Registers the givenResourceReference
.void
setAutoAddedCapacity(int autoAddedCapacity)
Set the cache size in number of entriesvoid
setResourceReferenceFactory(IResourceReferenceFactory resourceReferenceFactory)
Sets the factory to use when a ResourceReference is not previously registered and a new instance should be createdResourceReference
unregisterResourceReference(ResourceReference.Key key)
Unregisters aResourceReference
by its identifier.
-
-
-
Constructor Detail
-
ResourceReferenceRegistry
public ResourceReferenceRegistry()
Constructor.Uses DefaultResourceReferenceFactory to create ResourceReference when there is no registered one for the requested attributes
-
ResourceReferenceRegistry
public ResourceReferenceRegistry(IResourceReferenceFactory resourceReferenceFactory)
Constructor- Parameters:
resourceReferenceFactory
- The factory that will create ResourceReference by Key when there is no registered one
-
-
Method Detail
-
registerResourceReference
public final boolean registerResourceReference(ResourceReference reference)
Registers the givenResourceReference
.ResourceReference.canBeRegistered()
must returntrue
. Else, the resource reference will not be registered.- Parameters:
reference
- the reference to register- Returns:
true
if the resource was registered successfully or has been registered previously already.
-
unregisterResourceReference
public final ResourceReference unregisterResourceReference(ResourceReference.Key key)
Unregisters aResourceReference
by its identifier.- Parameters:
key
- theResourceReference
's identifier- Returns:
- The removed ResourceReference or
null
if the registry did not contain an entry for this key.
-
getResourceReference
public final ResourceReference getResourceReference(Class<?> scope, String name, Locale locale, String style, String variation, boolean strict, boolean createIfNotFound)
Get a resource reference matching the parameters from the registry or if not found and requested, create an default resource reference and add it to the registry.Part of the search is scanning the class (scope) and it's superclass for static ResourceReference fields. Found fields get registered automatically (but are different from auto-generated ResourceReferences).
- Parameters:
scope
- The scope of resource reference (e.g. the Component's class)name
- The name of resource reference (e.g. filename)locale
- see Componentstyle
- see Componentvariation
- see Componentstrict
- If true, "weaker" combination of scope, name, locale etc. are not testedcreateIfNotFound
- If true a default resource reference is created if no entry can be found in the registry. The newly created resource reference will be added to the registry.- Returns:
- Either the resource reference found in the registry or, if requested, a resource reference automatically created based on the parameters provided. The automatically created resource reference will automatically be added to the registry.
- See Also:
createDefaultResourceReference(org.apache.wicket.request.resource.ResourceReference.Key)
,ClassScanner
-
getResourceReference
public final ResourceReference getResourceReference(ResourceReference.Key key, boolean strict, boolean createIfNotFound)
Get a resource reference matching the parameters from the registry or if not found and requested, create an default resource reference and add it to the registry.Part of the search is scanning the class (scope) and it's superclass for static ResourceReference fields. Found fields get registered automatically (but are different from auto-generated ResourceReferences).
- Parameters:
key
- The data making up the resource referencestrict
- If true, "weaker" combination of scope, name, locale etc. are not testedcreateIfNotFound
- If true a default resource reference is created if no entry can be found in the registry. The newly created resource reference will be added to the registry.- Returns:
- Either the resource reference found in the registry or, if requested, a resource reference automatically created based on the parameters provided. The automatically created resource reference will automatically be added to the registry.
- See Also:
createDefaultResourceReference(org.apache.wicket.request.resource.ResourceReference.Key)
,ClassScanner
-
createDefaultResourceReference
protected ResourceReference createDefaultResourceReference(ResourceReference.Key key)
Creates a default resource reference in case no registry entry and it was requested to create one.A
PackageResourceReference
will be created by default- Parameters:
key
- the data making up the resource reference- Returns:
- The
ResourceReference
created ornull
if not successful
-
setAutoAddedCapacity
public final void setAutoAddedCapacity(int autoAddedCapacity)
Set the cache size in number of entries- Parameters:
autoAddedCapacity
- A value < 0 will disable aging of auto-create resource references. They will be created, added to the registry and live their until manually removed or the application shuts down.
-
getAutoAddedCapacity
public final int getAutoAddedCapacity()
Gets cache size in number of entries- Returns:
- capacity
-
clearAutoAddedEntries
public final void clearAutoAddedEntries()
Unregisters all auto-added Resource References
-
getAutoAddedCacheSize
public final int getAutoAddedCacheSize()
- Returns:
- Number of auto-generated (and registered) resource references.
-
getSize
public final int getSize()
- Returns:
- Number of registered resource references (normal and auto-generated)
-
getResourceReferenceFactory
public IResourceReferenceFactory getResourceReferenceFactory()
- Returns:
- the factory that will create the resource reference by using the parsed
ResourceReference.Key
-
setResourceReferenceFactory
public void setResourceReferenceFactory(IResourceReferenceFactory resourceReferenceFactory)
Sets the factory to use when a ResourceReference is not previously registered and a new instance should be created- Parameters:
resourceReferenceFactory
- the factory that will create the resource reference by using the parsedResourceReference.Key
-
-