Class AbstractTokenizedActivationStrategy
- java.lang.Object
-
- org.togglz.core.activation.AbstractTokenizedActivationStrategy
-
- All Implemented Interfaces:
ActivationStrategy
public abstract class AbstractTokenizedActivationStrategy extends Object implements ActivationStrategy
An abstract activation strategy that is designed to support cases where a specific parameter contains comma-separated tokens that can be negated by prefixing the value with the NOT operator (
!).AbstractTokenizedActivationStrategymakes no real assumptions on how implementations will use the tokens to determine whether the feature is active and, instead, simply tokenizes the parameter value. It even allows for the token values to be transformed during this process by specifying aAbstractTokenizedActivationStrategy.TokenTransformer.Implementations are responsible for honoring the negated state of any tokens. Fortunately, this is very simple to do:
@Override protected boolean isActive(FeatureState featureState, FeatureUser user, List<Token> tokens) { for (Token token : tokens) { boolean active = doSomeCheckOnTokenValue(token.getValue()); if (active != token.isNegated()) { return true; } } return false; }- Author:
- Alasdair Mercer
- See Also:
getTokenParameterName(),getTokenParameterTransformer()
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractTokenizedActivationStrategy.TokenContains information for a specific token including the token value and whether it has been negated.static interfaceAbstractTokenizedActivationStrategy.TokenTransformerUsed to transform a givenAbstractTokenizedActivationStrategy.Tokenvalue.
-
Constructor Summary
Constructors Constructor Description AbstractTokenizedActivationStrategy()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract StringgetTokenParameterName()Returns the name of the parameter whose value is to be tokenized.AbstractTokenizedActivationStrategy.TokenTransformergetTokenParameterTransformer()Returns the transformer to be used to transform the value of eachAbstractTokenizedActivationStrategy.Token.booleanisActive(FeatureState featureState, FeatureUser user)This method is responsible to decide whether a feature is active or not.protected abstract booleanisActive(FeatureState featureState, FeatureUser user, List<AbstractTokenizedActivationStrategy.Token> tokens)This method is called byisActive(FeatureState, FeatureUser)with the parsedtokensto make the decision as to whether the feature is active.protected List<AbstractTokenizedActivationStrategy.Token>tokenize(FeatureState featureState, String parameterName, AbstractTokenizedActivationStrategy.TokenTransformer transformer)Looks up and tokenizes the value of the parameter with the given name on the feature.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.togglz.core.spi.ActivationStrategy
getId, getName, getParameters
-
-
-
-
Method Detail
-
isActive
public final boolean isActive(FeatureState featureState, FeatureUser user)
Description copied from interface:ActivationStrategyThis method is responsible to decide whether a feature is active or not. The implementation can use the custom configuration parameters of the strategy stored in the feature state and information from the currently acting user to find a decision.- Specified by:
isActivein interfaceActivationStrategy- Parameters:
featureState- The feature state which represents the current configuration of the feature. The implementation of the method typically usesFeatureState.getParameter(String)to access custom configuration parameter values.user- The user for which to decide whether the feature is active. May benullif the user could not be identified by theUserProvider.- Returns:
trueif the feature should be active, elsefalse
-
isActive
protected abstract boolean isActive(FeatureState featureState, FeatureUser user, List<AbstractTokenizedActivationStrategy.Token> tokens)
This method is called by
isActive(FeatureState, FeatureUser)with the parsedtokensto make the decision as to whether the feature is active.- Parameters:
featureState- theFeatureStatewhich represents the current configuration of the featureuser- theuserfor which to decide whether the feature is active (may be null)tokens- theListofTokensparsed from the parameter value- Returns:
- true if the feature should be active; otherwise false.
-
tokenize
protected List<AbstractTokenizedActivationStrategy.Token> tokenize(FeatureState featureState, String parameterName, AbstractTokenizedActivationStrategy.TokenTransformer transformer)
Looks up and tokenizes the value of the parameter with the given name on the feature.
If
transformeris not null, it will be asked to transform each individual token value.- Parameters:
featureState- theFeatureStatewhich represents the current configuration of the featureparameterName- the name of the parameter whose value is to be tokenizedtransformer- theAbstractTokenizedActivationStrategy.TokenTransformerto be used to transform the value of each token (may be null to use the token values as-provided)- Returns:
- A
ListofTokensextracted from the value of the parameter with the specified name.
-
getTokenParameterName
public abstract String getTokenParameterName()
Returns the name of the parameter whose value is to be tokenized.
- Returns:
- The name of the parameter containing tokens.
-
getTokenParameterTransformer
public AbstractTokenizedActivationStrategy.TokenTransformer getTokenParameterTransformer()
Returns the transformer to be used to transform the value of each
AbstractTokenizedActivationStrategy.Token.By default, this method returns null, meaning that the token values are used as-provided.
- Returns:
- The
AbstractTokenizedActivationStrategy.TokenTransformerto be used to transform token values or null to use the original values.
-
-