org.apache.wicket
Class ResourceReference

java.lang.Object
  extended by org.apache.wicket.ResourceReference
All Implemented Interfaces:
Serializable, IClusterable
Direct Known Subclasses:
AbstractResourceDependentResourceReference, CompressedResourceReference, JavascriptResourceReference, PackageResourceReference, TextTemplateResourceReference

public class ResourceReference
extends Object
implements IClusterable

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.

Author:
Jonathan Locke
See Also:
Serialized Form

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

locale

protected Locale locale
The locale of the resource

Constructor Detail

ResourceReference

public ResourceReference(Class<?> scope,
                         String name)
Constructs a ResourceReference with the given scope and name. The scope is used as a namespace and the scope together with the name must uniquely identify the reference.

Parameters:
scope - The scope of the name
name - The name of the resource

ResourceReference

public ResourceReference(Class<?> scope,
                         String name,
                         Locale locale,
                         String style)
Constructs a ResourceReference with the given scope and name. The scope is used as a namespace and the scope together with the name must uniquely identify the reference. This constructor takes in the locale and style arguments. The locale might be overruled if this resource resolves to a package resource.

Parameters:
scope - The scope of the name
name - The name of the resource
locale - The Locale from which the search for the PackageResource must start
style - The Style of the PackageResource

ResourceReference

public ResourceReference(String name)
Constructs a resource reference with Application.class scope and the given name. All resource references constructed with this constructor must have unique names since they all have the same Application-wide scope that is the org.apache.wicket.Application.class

Parameters:
name - The name of the resource
Method Detail

bind

public final void bind(Application application)
Binds this shared resource to the given application.

Parameters:
application - The application which holds the shared resource

equals

public boolean equals(Object obj)
Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

getLocale

public final Locale getLocale()
Returns:
Returns the locale.

getName

public final String getName()
Returns:
Name

getResource

public final Resource getResource()
Gets the resource for this resource reference. If the ResourceReference has not yet been bound to the application via bind(Application)this method may return null.

Returns:
The resource, or null if the ResourceReference has not yet been bound.

getScope

public final Class<?> getScope()
Returns:
Scope

getSharedResourceKey

public final String getSharedResourceKey()
Returns:
the shared resource key for this resource reference.

getStyle

public final String getStyle()
Returns:
Returns the style. (see Session)

hashCode

public int hashCode()
Overrides:
hashCode in class Object
See Also:
Object.hashCode()

invalidate

public final void invalidate()
Sets any loaded resource to null, thus forcing a reload on the next request.


setLocale

public final void setLocale(Locale locale)
Parameters:
locale - The locale to set.

setStyle

public final void setStyle(String style)
Parameters:
style - The style to set (see Session).

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()

newResource

protected Resource newResource()
Factory method for lazy initialization of shared resources.

Returns:
The resource

lastModifiedTime

public Time lastModifiedTime()
Returns the last modified time of resource referenced by this reference.

Returns:
last modified time or null if the time couldn't have been determined

isStateless

public boolean isStateless()
Returns:
stateless falg
See Also:
setStateless(boolean)

setStateless

public void setStateless(boolean stateless)
Sets whether or not the resource pointed to by this reference requires a session. Urls to resources that do not require a session will have their jsessionid stripped.

Parameters:
stateless -


Copyright © 2004-2011 Apache Software Foundation. All Rights Reserved.