public class SwarmActionFactory extends Object implements WaspActionFactory
Modifier and Type | Class and Description |
---|---|
protected static class |
SwarmActionFactory.ImpliesOtherAction
Any class that implies another action.
|
Modifier and Type | Field and Description |
---|---|
protected static int |
maxAssingableAction
Maximum power of 2 that can be used to assign to an action.
|
Constructor and Description |
---|
SwarmActionFactory(Object key)
Registers the default actions: access, inherit, render and enable.
|
Modifier and Type | Method and Description |
---|---|
protected void |
appendActionString(org.apache.wicket.util.string.AppendingStringBuffer buff,
int actions,
int waspAction)
Appends the string value of the action only if the actions imply the waspAction
|
protected String |
buildActionString(int actions)
Builds a logically ordered comma separated string of all the actions this permission has.
|
protected void |
cacheAction(Integer actions,
SwarmAction ja)
Caches an action under its int form.
|
protected void |
cacheAction(String name,
SwarmAction action)
Caches an action under its string form.
|
protected String |
convertWicket2Wasp(String name)
Renames build in wicket actions to there wasp counterpart.
|
void |
destroy()
Clears registration and cached values.
|
WaspAction |
getAction(org.apache.wicket.authorization.Action action)
Translates a wicket action to a wasp action.
|
SwarmAction |
getAction(Class<? extends WaspAction> waspActionClass)
Returns the registered action of this class.
|
SwarmAction |
getAction(int actions)
Returns an action based on its int value.
|
WaspAction |
getAction(String actions)
Creates or reuses a WaspAction based on string values.
|
protected SwarmAction |
getCachedAction(int actions)
Returns a cached action.
|
protected SwarmAction |
getCachedAction(String name)
Returns a cached action.
|
protected Object |
getFactoryKey()
Gets key.
|
int |
getNumberOfRegisteredClasses()
Returns the number of registered classes.
|
List<WaspAction> |
getRegisteredActions()
Returns a list of all the registered actions at the time of the invocation.
|
protected boolean |
implies(int actions,
int action)
Check if the action is available in the actions.
|
protected int |
nextPowerOf2()
The next action value.
|
protected int |
parseActions(String actions)
Parses a comma separated String containing actions.
|
SwarmAction |
register(Class<? extends WaspAction> waspActionClass,
String name)
Register a new action.
|
protected SwarmAction |
register(Class<? extends WaspAction> waspActionClass,
SwarmAction action)
Registers a new action.
|
protected String |
valueOf(Integer action)
Returns the registered string value of the given action.
|
protected static final int maxAssingableAction
public WaspAction getAction(org.apache.wicket.authorization.Action action)
WaspActionFactory
getAction
in interface WaspActionFactory
action
- a wicket actionWaspActionFactory.getAction(org.apache.wicket.authorization.Action)
public WaspAction getAction(String actions)
ActionFactory
getAction
in interface ActionFactory
actions
- empty string means AccessActionFactory.getAction(String)
protected final void cacheAction(String name, SwarmAction action)
name
- action
- protected final SwarmAction getCachedAction(String name)
name
- public SwarmAction getAction(int actions)
actions
- IllegalArgumentException
- if no action can be formed based on the inputprotected final void cacheAction(Integer actions, SwarmAction ja)
actions
- ja
- protected final SwarmAction getCachedAction(int actions)
actions
- protected final String valueOf(Integer action)
action
- the internal value of the actionprotected String buildActionString(int actions)
actions
- the internal action valueprotected final void appendActionString(org.apache.wicket.util.string.AppendingStringBuffer buff, int actions, int waspAction)
buff
- where the string will be appended to.actions
- the available actionswaspAction
- the action it should imply in order to append the stringprotected final boolean implies(int actions, int action)
actions
- the actions that might contain actionaction
- the action we check for in actionsprotected int parseActions(String actions)
actions
- IllegalArgumentException
- if (one of) the action(s) is not recognized.public SwarmAction getAction(Class<? extends WaspAction> waspActionClass)
ActionFactory
getAction
in interface ActionFactory
waspActionClass
- a subclass of WaspAction
ActionFactory.getAction(java.lang.Class)
public SwarmAction register(Class<? extends WaspAction> waspActionClass, String name) throws RegistrationException
ActionFactory
register
in interface ActionFactory
waspActionClass
- the class of the action to register (must be subclass of WaspAction
name
- the name to register the action withRegistrationException
- if the action cannot be registeredActionFactory.register(java.lang.Class,
java.lang.String)
public final int getNumberOfRegisteredClasses()
protected final int nextPowerOf2()
Integer.MAX_VALUE
protected final String convertWicket2Wasp(String name)
name
- the name of the actionprotected final SwarmAction register(Class<? extends WaspAction> waspActionClass, SwarmAction action) throws RegistrationException
SwarmAction#SwarmAction(int, String, ActionFactory)
. Example:
register(Enable.class, new ImpliesReadAction(nextPowerOf2(), "enable", this));
class ImpliesReadAction extends SwarmAction
{
public ImpliesReadAction(int actions, String name, ActionFactory factory)
{
super(actions
| ((SwarmAction)factory.getAction(org.wicketstuff.security.actions.Render.class))
.actions(), name);
}
}
Note all actions registered in this way must use nextPowerOf2() and then immediately register
the action to preserve consistency.waspActionClass
- the class under which to register the actionaction
- the actual implementation (note that it does not need to implement the supplied
waspActionClass)RegistrationException
- if the action can not be registered.nextPowerOf2()
,
SwarmAction#SwarmAction(int, String, ActionFactory)
public List<WaspAction> getRegisteredActions()
ActionFactory
getRegisteredActions
in interface ActionFactory
ActionFactory.getRegisteredActions()
public void destroy()
destroy
in interface ActionFactory
ActionFactory.destroy()
protected final Object getFactoryKey()
Copyright © 2015. All rights reserved.