org.wicketstuff.security.swarm.actions
Class SwarmActionFactory

java.lang.Object
  extended by org.wicketstuff.security.swarm.actions.SwarmActionFactory
All Implemented Interfaces:
org.wicketstuff.security.actions.ActionFactory, org.wicketstuff.security.actions.WaspActionFactory

public class SwarmActionFactory
extends Object
implements org.wicketstuff.security.actions.WaspActionFactory

Default implementation of an action factory. It handles access, inherit, render and enable actions. Because actions are immutable and in order to improve performance, generated actions are cached.

Author:
marrink

Nested Class Summary
protected static class SwarmActionFactory.ImpliesOtherAction
          Any class that implies another action.
 
Field Summary
protected static int maxAssingableAction
          Maximum power of 2 that can be used to assign to an action.
 
Constructor Summary
SwarmActionFactory(Object key)
          Registers the default actions: access, inherit, render and enable.
 
Method Summary
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.
 org.wicketstuff.security.actions.WaspAction getAction(org.apache.wicket.authorization.Action action)
           
 SwarmAction getAction(Class<? extends org.wicketstuff.security.actions.WaspAction> waspActionClass)
           
 SwarmAction getAction(int actions)
          Returns an action based on its int value.
 org.wicketstuff.security.actions.WaspAction getAction(String actions)
           
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<org.wicketstuff.security.actions.WaspAction> getRegisteredActions()
           
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 org.wicketstuff.security.actions.WaspAction> waspActionClass, String name)
           
protected  SwarmAction register(Class<? extends org.wicketstuff.security.actions.WaspAction> waspActionClass, SwarmAction action)
          Registers a new action.
protected  String valueOf(Integer action)
          Returns the registered string value of the given action.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maxAssingableAction

protected static final int maxAssingableAction
Maximum power of 2 that can be used to assign to an action.

Constructor Detail

SwarmActionFactory

public SwarmActionFactory(Object key)
Registers the default actions: access, inherit, render and enable.

Parameters:
key - using this key the factory registers itself to the Actions object.
Method Detail

getAction

public org.wicketstuff.security.actions.WaspAction getAction(org.apache.wicket.authorization.Action action)
Specified by:
getAction in interface org.wicketstuff.security.actions.WaspActionFactory
See Also:
WaspActionFactory.getAction(org.apache.wicket.authorization.Action)

getAction

public org.wicketstuff.security.actions.WaspAction getAction(String actions)
Specified by:
getAction in interface org.wicketstuff.security.actions.ActionFactory
Parameters:
actions - empty string means Access
See Also:
ActionFactory.getAction(String)

cacheAction

protected final void cacheAction(String name,
                                 SwarmAction action)
Caches an action under its string form.

Parameters:
name -
action -

getCachedAction

protected final SwarmAction getCachedAction(String name)
Returns a cached action.

Parameters:
name -
Returns:
the cached action or null.

getAction

public SwarmAction getAction(int actions)
Returns an action based on its int value.

Parameters:
actions -
Returns:
the action
Throws:
IllegalArgumentException - if no action can be formed based on the input

cacheAction

protected final void cacheAction(Integer actions,
                                 SwarmAction ja)
Caches an action under its int form.

Parameters:
actions -
ja -

getCachedAction

protected final SwarmAction getCachedAction(int actions)
Returns a cached action.

Parameters:
actions -
Returns:
the cached action or null.

valueOf

protected final String valueOf(Integer action)
Returns the registered string value of the given action.

Parameters:
action - the internal value of the action
Returns:
the registered string or null if no string value was registered for this action.

buildActionString

protected String buildActionString(int actions)
Builds a logically ordered comma separated string of all the actions this permission has. Based on the logical and of the supplied actions. Subclasses should always return the same string (action order) for the same action.

Parameters:
actions - the internal action value
Returns:
string containing all the actions.

appendActionString

protected final 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

Parameters:
buff - where the string will be appended to.
actions - the available actions
waspAction - the action it should imply in order to append the string

implies

protected final boolean implies(int actions,
                                int action)
Check if the action is available in the actions. This performs a bitwise check.

Parameters:
actions - the actions that might contain action
action - the action we check for in actions
Returns:
true if actions contains action

parseActions

protected int parseActions(String actions)
Parses a comma separated String containing actions. Access is the default and will also be substituted for any empty or null String. using a string like 'render, render' is pointless but does not brake anything. Order of the actions is also not important.

Parameters:
actions -
Returns:
a logical and of the actions.
Throws:
IllegalArgumentException - if (one of) the action(s) is not recognized.

getAction

public SwarmAction getAction(Class<? extends org.wicketstuff.security.actions.WaspAction> waspActionClass)
Specified by:
getAction in interface org.wicketstuff.security.actions.ActionFactory
See Also:
ActionFactory.getAction(java.lang.Class)

register

public SwarmAction register(Class<? extends org.wicketstuff.security.actions.WaspAction> waspActionClass,
                            String name)
                     throws org.wicketstuff.security.actions.RegistrationException
Specified by:
register in interface org.wicketstuff.security.actions.ActionFactory
Throws:
org.wicketstuff.security.actions.RegistrationException
See Also:
ActionFactory.register(java.lang.Class, java.lang.String)

getNumberOfRegisteredClasses

public final int getNumberOfRegisteredClasses()
Returns the number of registered classes. By default there are 4 classes registered.

Returns:
the number of registered classes.

nextPowerOf2

protected final int nextPowerOf2()
The next action value. Note that you can only register classes while this is < Integer.MAX_VALUE

Returns:
the int value of 2^(numberOfRegisteredClasses()-1)

convertWicket2Wasp

protected final String convertWicket2Wasp(String name)
Renames build in wicket actions to there wasp counterpart. more specifically it converts the string to lowercase.

Parameters:
name - the name of the action
Returns:
the converted name of the action.

register

protected final SwarmAction register(Class<? extends org.wicketstuff.security.actions.WaspAction> waspActionClass,
                                     SwarmAction action)
                              throws org.wicketstuff.security.actions.RegistrationException
Registers a new action. Use this in combination with 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.

Parameters:
waspActionClass - the class under which to register the action
action - the actual implementation (note that it does not need to implement the supplied waspActionClass)
Returns:
the action
Throws:
org.wicketstuff.security.actions.RegistrationException - if the action can not be registered.
See Also:
nextPowerOf2(), SwarmAction#SwarmAction(int, String, ActionFactory)

getRegisteredActions

public List<org.wicketstuff.security.actions.WaspAction> getRegisteredActions()
Specified by:
getRegisteredActions in interface org.wicketstuff.security.actions.ActionFactory
See Also:
ActionFactory.getRegisteredActions()

destroy

public void destroy()
Clears registration and cached values. After you destroy this factory you must not use it again.

Specified by:
destroy in interface org.wicketstuff.security.actions.ActionFactory
See Also:
ActionFactory.destroy()

getFactoryKey

protected final Object getFactoryKey()
Gets key.

Returns:
key


Copyright © 2006–2018 Apache Software Foundation. All rights reserved.