SalesPoint v3.3 API

users
Interface Capability

All Superinterfaces:
Serializable
All Known Implementing Classes:
AbstractCapability, ActionCapability

public interface Capability
extends Serializable

Capabilities guard activities and restrict the users' options in an application.

A capability is an immutable object associated with a user, that either grants or denies the user a specific service. In an ideal object oriented world each service that is guarded by a specific capability will only be reachable via a method in the capability object. Different implementations (achieved via subclasses) would then either perform the service or take suitable measures to indicate denial.

To achieve immutability it is vital that you do not offer any methods that allow for the state of the capability to be manipulated directly after the object has been created. Capabilities of different state shall only be achieved via the getToggled() method.

For convenience you may want to subclass AbstractCapability rather than implementing Capability directly, as that already takes care of the name management.

Since:
v2.0
Author:
Steffen Zschaler
See Also:
User, UserManager

Method Summary
 String getDisplayName()
          Get the display name for this capability according to the default locale.
 String getDisplayName(Locale l)
          Get the display name for this capability according to a locale.
 String getName()
          Get the name of this capability.
 Capability getToggled()
          Return a capability that is the inverse to this one.
 boolean isGranted()
          Get information whether this capability grants or denies the right for the activity it guards.
 

Method Detail

getName

String getName()
Get the name of this capability. This name will be used to programatically identify the capability. It must not change during the life of the capability object.

Returns:
the name of the capability
Override:
Always

getDisplayName

String getDisplayName()
Get the display name for this capability according to the default locale.

The display name will be used when communicating with the user about the capability.

Returns:
the display name according to the default locale.
Override:
Always

getDisplayName

String getDisplayName(Locale l)
Get the display name for this capability according to a locale.

The display name will be used when communicating with the user about the capability.

Parameters:
l - the locale according to which the display name is to be returned.
Returns:
the display name according to a locale.
Override:
Always

isGranted

boolean isGranted()
Get information whether this capability grants or denies the right for the activity it guards.

This is only informational and should not be used to actually implement the service of guarding activities. Guarding should always be achieved by making the activity only available via methods of the Capability object.

Returns:
true if this Capability grants rights.
Override:
Always

getToggled

Capability getToggled()
Return a capability that is the inverse to this one. If this capability granted rights the returned one should deny them and vice-versa.

This is the only way to toggle the Grant State of a capability as they are immutable ojects. Immutability means in this case that you cannot simply say capability.toggleGranted() but have to create a new object to achieve the purpose. It may help to think of a capability as something like an opera ticket that is given to someone and must be explicitly demanded back to invalidate it.

Returns:
the inverse to this capability.
Override:
Always

SalesPoint v3.3 API