org.salespointframework.core.users
Class AbstractCapability

java.lang.Object
  extended by org.salespointframework.core.users.AbstractCapability
All Implemented Interfaces:
Capability
Direct Known Subclasses:
ActionCapability, NameCapability

public abstract class AbstractCapability
extends java.lang.Object
implements Capability

Convenience class implementing basic capability behavior.

For convenience you can derive all your capability classes from AbstractCapability, which will manage names and display names.

Since:
v2.0
Version:
2.0 05/05/1999
Author:
Steffen Zschaler

Field Summary
private  java.lang.String m_sName
          The name of the capability.
private static java.util.Locale s_lLRU
          The least recently used locale for looking up display names.
private static java.util.ResourceBundle s_rbDisplayNames
          The resource bundle that contains the display names for the capabilities.
private static java.lang.String s_sBaseName
          The base name for the resource bundles containing the capabilities' display names.
 
Constructor Summary
AbstractCapability(java.lang.String sName)
          Create a new capability with a given name.
 
Method Summary
private static java.lang.String getCapabilityDisplayName(java.lang.String sName, java.util.Locale l)
          Get a capabilities display name depending on a locale.
 java.lang.String getDisplayName()
          Get the display name of this capability using the default locale.
 java.lang.String getDisplayName(java.util.Locale l)
          Get the display name of this capability according to a locale.
 java.lang.String getName()
          Get the capability's name.
abstract  Capability getToggled()
          Get the capability that is the inverse to this one.
abstract  boolean isGranted()
          Return the grant state of this capability.
static void setDisplayNameResourceBundleName(java.lang.String sBaseName)
          Set the base name for the resouce bundle that contains the capabilities' display names.
 java.lang.String toString()
          Return a string representation of this capability.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_sName

private final java.lang.String m_sName
The name of the capability.

IMMUTABLE


s_rbDisplayNames

private static java.util.ResourceBundle s_rbDisplayNames
The resource bundle that contains the display names for the capabilities. CACHE.


s_lLRU

private static java.util.Locale s_lLRU
The least recently used locale for looking up display names.


s_sBaseName

private static java.lang.String s_sBaseName
The base name for the resource bundles containing the capabilities' display names.

Constructor Detail

AbstractCapability

public AbstractCapability(java.lang.String sName)
Create a new capability with a given name.

Parameters:
sName - the name of the capability.
Method Detail

getName

public java.lang.String getName()
Get the capability's name.

Specified by:
getName in interface Capability
Returns:
the capability's name.

getDisplayName

public java.lang.String getDisplayName()
Get the display name of this capability using the default locale.

This is identical to

   getDisplayName (Locale.getDefault());
 

Specified by:
getDisplayName in interface Capability
Returns:
the display name of this capability according to the default locale.

getDisplayName

public java.lang.String getDisplayName(java.util.Locale l)
Get the display name of this capability according to a locale. You can set the base name of the resource bundle to be used by calling setDisplayNameResourceBundleName(java.lang.String).

Specified by:
getDisplayName in interface Capability
Parameters:
l - the locale according to which to get the display name
Returns:
the display name according to the locale.

isGranted

public abstract boolean isGranted()
Return the grant state of this capability. This method is abstract and you'll have to redefine it in subclasses.

Specified by:
isGranted in interface Capability
Returns:
true if this capability grants rights.

getToggled

public abstract Capability getToggled()
Get the capability that is the inverse to this one. This method is abstract and you'll have to redefine it in subclasses.

Specified by:
getToggled in interface Capability
Returns:
the capability that is the inverse to this one.

toString

public java.lang.String toString()
Return a string representation of this capability.

The format of the returned string is:

display name <name>: grant state

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this capability.

getCapabilityDisplayName

private static final java.lang.String getCapabilityDisplayName(java.lang.String sName,
                                                               java.util.Locale l)
Get a capabilities display name depending on a locale. This will lookup the capability's display name in the resource bundle specified through setDisplayNameResourceBundleName(java.lang.String) and the locale. The key will be:
capabilities.display_names.sName

Parameters:
sName - the programmatical name of the capability
l - the locale that determines which resource bundle to use.
See Also:
ResourceBundle

setDisplayNameResourceBundleName

public static final void setDisplayNameResourceBundleName(java.lang.String sBaseName)
Set the base name for the resouce bundle that contains the capabilities' display names. The resource must contain a String for each Capability. The key for the String must be: capabilities.display_names.capability_name