|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.wicket.ResourceReference
public class ResourceReference
ResourceReference is essentially a reference to an actual resource which is shared through the Application. A ResourceReference has a name and a scope (within which the name must be unique). It may also have a locale or style. The locale and/or style do not need to be set on a resource reference because those values will automatically be determined based on the context in which the resource is being used. For example, if a ResourceReference is attached to an Image component, when the locale for the page switches, the Image component will notice this and automatically change the locale for the referenced resource as appropriate. It's for this reason that you don't typically have to use the constructor overloads taking a Locale or style (these details are essentially internal and so the framework uses setLocale/setStyle internally so you don't have to worry about it).
Package resources (resources which can be pulled from the classpath) do not have to be
pre-registered. For custom situations though, resources may be added to the Application when the
Application is constructed using Application.getSharedResources()
followed by
SharedResources.add(Class, String, Locale, String, Resource)
,
SharedResources.add(String, Locale, Resource)
or
SharedResources.add(String, Resource)
.
If a component has its own shared resource which should not be added to the application
construction logic in this way, it can lazy-initialize the resource by overriding the
newResource()
method. In this method, the component should supply logic that creates the
shared resource. By default the newResource()
method tries to resolve to a package
resource.
Field Summary | |
---|---|
protected Locale |
locale
The locale of the resource |
Constructor Summary | |
---|---|
ResourceReference(Class<?> scope,
String name)
Constructs a ResourceReference with the given scope and name. |
|
ResourceReference(Class<?> scope,
String name,
Locale locale,
String style)
Constructs a ResourceReference with the given scope and name. |
|
ResourceReference(String name)
Constructs a resource reference with Application.class scope and the given name. |
Method Summary | |
---|---|
void |
bind(Application application)
Binds this shared resource to the given application. |
boolean |
equals(Object obj)
|
Locale |
getLocale()
|
String |
getName()
|
Resource |
getResource()
Gets the resource for this resource reference. |
Class<?> |
getScope()
|
String |
getSharedResourceKey()
|
String |
getStyle()
|
int |
hashCode()
|
void |
invalidate()
Sets any loaded resource to null, thus forcing a reload on the next request. |
boolean |
isStateless()
|
Time |
lastModifiedTime()
Returns the last modified time of resource referenced by this reference. |
protected Resource |
newResource()
Factory method for lazy initialization of shared resources. |
void |
setLocale(Locale locale)
|
void |
setStateless(boolean stateless)
Sets whether or not the resource pointed to by this reference requires a session. |
void |
setStyle(String style)
|
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected Locale locale
Constructor Detail |
---|
public ResourceReference(Class<?> scope, String name)
scope
- The scope of the namename
- The name of the resourcepublic ResourceReference(Class<?> scope, String name, Locale locale, String style)
scope
- The scope of the namename
- The name of the resourcelocale
- The Locale from which the search for the PackageResource must startstyle
- The Style of the PackageResourcepublic ResourceReference(String name)
name
- The name of the resourceMethod Detail |
---|
public final void bind(Application application)
application
- The application which holds the shared resourcepublic boolean equals(Object obj)
equals
in class Object
Object.equals(java.lang.Object)
public final Locale getLocale()
public final String getName()
public final Resource getResource()
bind(Application)
this method may
return null.
public final Class<?> getScope()
public final String getSharedResourceKey()
public final String getStyle()
Session
)public int hashCode()
hashCode
in class Object
Object.hashCode()
public final void invalidate()
public final void setLocale(Locale locale)
locale
- The locale to set.public final void setStyle(String style)
style
- The style to set (see Session
).public String toString()
toString
in class Object
Object.toString()
protected Resource newResource()
public Time lastModifiedTime()
public boolean isStateless()
setStateless(boolean)
public void setStateless(boolean stateless)
stateless
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |