|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object 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 java.util.Locale |
locale
The locale of the resource |
Constructor Summary | |
---|---|
ResourceReference(java.lang.Class scope,
java.lang.String name)
Constructs a ResourceReference with the given scope and name. |
|
ResourceReference(java.lang.Class scope,
java.lang.String name,
java.util.Locale locale,
java.lang.String style)
Constructs a ResourceReference with the given scope and name. |
|
ResourceReference(java.lang.String name)
Contructs 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(java.lang.Object obj)
|
java.util.Locale |
getLocale()
|
java.lang.String |
getName()
|
Resource |
getResource()
Gets the resource for this resource reference. |
java.lang.Class |
getScope()
|
java.lang.String |
getSharedResourceKey()
|
java.lang.String |
getStyle()
|
int |
hashCode()
|
void |
invalidate()
Sets any loaded resource to null, thus forcing a reload on the next request. |
protected Resource |
newResource()
Factory method for lazy initialization of shared resources. |
void |
setLocale(java.util.Locale locale)
|
void |
setStyle(java.lang.String style)
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.util.Locale locale
Constructor Detail |
---|
public ResourceReference(java.lang.Class scope, java.lang.String name)
scope
- The scope of the namename
- The name of the resourcepublic ResourceReference(java.lang.Class scope, java.lang.String name, java.util.Locale locale, java.lang.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(java.lang.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(java.lang.Object obj)
equals
in class java.lang.Object
Object.equals(java.lang.Object)
public final java.util.Locale getLocale()
public final java.lang.String getName()
public final Resource getResource()
bind(Application)
this method may return null.
public final java.lang.Class getScope()
public final java.lang.String getSharedResourceKey()
public final java.lang.String getStyle()
Session
)public int hashCode()
hashCode
in class java.lang.Object
Object.hashCode()
public final void invalidate()
public final void setLocale(java.util.Locale locale)
locale
- The locale to set.public final void setStyle(java.lang.String style)
style
- The style to set (see Session
).public java.lang.String toString()
toString
in class java.lang.Object
Object.toString()
protected Resource newResource()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |