com.sun.rave.web.ui.util
Class PermissionChecker

java.lang.Object
  extended by com.sun.rave.web.ui.util.PermissionChecker

public class PermissionChecker
extends java.lang.Object

This class takes a "Permission String" and is cabable of determining if a user passes the permission check. Supported "checks" are:

The format of the "Permission String" must be an equation that results in a boolean answer. The supported functions/operators are: -- Operator Precedence (for infix notation) is:

See Also:
VariableResolver

Nested Class Summary
protected static class PermissionChecker.BooleanFunction
          BooleanFunction is either true or false.
static interface PermissionChecker.Function
          This class must be implemented by all user defined Functions.
protected  class PermissionChecker.StringFunction
          StringFunction implements Function and serves as the default function.
 
Field Summary
static char AND_OPERATOR
           
static char ARGUMENT_SEPARATOR
           
static char EQUALS_OPERATOR
           
static java.lang.String FALSE
           
static PermissionChecker.BooleanFunction FALSE_BOOLEAN_FUNCTION
          This variable represents a "false" BooleanFunction.
static char FUNCTION_MARKER
           
static char LEFT_PAREN
           
static char LESS_THAN_OPERATOR
           
static char MODULUS_OPERATOR
           
static char MORE_THAN_OPERATOR
           
static char NOT_OPERATOR
           
static char OR_OPERATOR
           
protected static char POST_FALSE
           
protected static char POST_FALSE_CAP
           
protected static char POST_TRUE
           
protected static char POST_TRUE_CAP
           
static char RIGHT_PAREN
           
static java.lang.String TRUE
           
static PermissionChecker.BooleanFunction TRUE_BOOLEAN_FUNCTION
          This variable represents a "true" BooleanFunction.
 
Constructor Summary
PermissionChecker(LayoutElement desc, javax.faces.component.UIComponent component, java.lang.String infixStr)
          This is the constructor method that is required to create this object.
 
Method Summary
protected  char[] generatePostfix(java.lang.String infixStr)
          This method calculates the postfix representation of the infix equation passed in.
protected static PermissionChecker.Function getFunction(java.lang.String functionName)
          This method is a factory method for constructing a new function based on the function name passed in.
 java.lang.String getInfix()
          This method returns the infix representation of the equation, in other words: the original String passed in.
 LayoutElement getLayoutElement()
          Retreives the LayoutElement associated with this PermissionChecker (only needed in cases where a expression requires a LayoutElement for evaluation).
 java.lang.String getPostfix()
           
protected  char[] getPostfixArr()
           
 javax.faces.component.UIComponent getUIComponent()
          Retreives the LayoutElement associated with this PermissionChecker (only needed in cases where a expression requires a LayoutElement for evaluation).
 boolean hasPermission()
          This method is invoked to determine if the equation evaluates to true or false.
static boolean isOperator(char ch)
          This method returns true if the given character is a valid operator.
static void main(java.lang.String[] args)
          This is here to provide some test cases.
protected  char[] preProcessString(java.lang.String source)
          This method replaces all "true" / "false" strings w/ 't'/'f'.
static void registerFunction(java.lang.String functionName, java.lang.Class function)
          This method allows arbitrary functions to be registered.
 void setInfix(java.lang.String equation)
          This method sets the equation and forces a re-evaluation of the equation.
protected  void setLayoutElement(LayoutElement desc)
          This method sets the LayoutElement that is associated with the 'if' check being evaluated.
protected  void setPostfixArr(char[] postfix)
           
protected  void setUIComponent(javax.faces.component.UIComponent component)
          This method sets the LayoutElement that is associated with the 'if' check being evaluated.
protected  int storeFunction(char[] arr, int idx)
          This method looks at the given char array starting at index and continues until an operator (or end of String) is encountered.
static java.lang.String stripWhiteSpace(java.lang.String input)
          This method removes all whitespace from the given String
 java.lang.String toString()
          Displays the infix and postfix version of the equation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FALSE_BOOLEAN_FUNCTION

public static final PermissionChecker.BooleanFunction FALSE_BOOLEAN_FUNCTION
This variable represents a "false" BooleanFunction.


TRUE_BOOLEAN_FUNCTION

public static final PermissionChecker.BooleanFunction TRUE_BOOLEAN_FUNCTION
This variable represents a "true" BooleanFunction.


POST_TRUE

protected static final char POST_TRUE
See Also:
Constant Field Values

POST_FALSE

protected static final char POST_FALSE
See Also:
Constant Field Values

POST_TRUE_CAP

protected static final char POST_TRUE_CAP
See Also:
Constant Field Values

POST_FALSE_CAP

protected static final char POST_FALSE_CAP
See Also:
Constant Field Values

TRUE

public static final java.lang.String TRUE
See Also:
Constant Field Values

FALSE

public static final java.lang.String FALSE
See Also:
Constant Field Values

FUNCTION_MARKER

public static final char FUNCTION_MARKER
See Also:
Constant Field Values

LEFT_PAREN

public static final char LEFT_PAREN
See Also:
Constant Field Values

RIGHT_PAREN

public static final char RIGHT_PAREN
See Also:
Constant Field Values

EQUALS_OPERATOR

public static final char EQUALS_OPERATOR
See Also:
Constant Field Values

OR_OPERATOR

public static final char OR_OPERATOR
See Also:
Constant Field Values

AND_OPERATOR

public static final char AND_OPERATOR
See Also:
Constant Field Values

NOT_OPERATOR

public static final char NOT_OPERATOR
See Also:
Constant Field Values

LESS_THAN_OPERATOR

public static final char LESS_THAN_OPERATOR
See Also:
Constant Field Values

MORE_THAN_OPERATOR

public static final char MORE_THAN_OPERATOR
See Also:
Constant Field Values

MODULUS_OPERATOR

public static final char MODULUS_OPERATOR
See Also:
Constant Field Values

ARGUMENT_SEPARATOR

public static final char ARGUMENT_SEPARATOR
See Also:
Constant Field Values
Constructor Detail

PermissionChecker

public PermissionChecker(LayoutElement desc,
                         javax.faces.component.UIComponent component,
                         java.lang.String infixStr)
This is the constructor method that is required to create this object.

Method Detail

setUIComponent

protected void setUIComponent(javax.faces.component.UIComponent component)

This method sets the LayoutElement that is associated with the 'if' check being evaluated. This is not normally needed, it is only needed if the 'if' check contains an expression which requires a LayoutElement to be properly evaluated.


getUIComponent

public javax.faces.component.UIComponent getUIComponent()

Retreives the LayoutElement associated with this PermissionChecker (only needed in cases where a expression requires a LayoutElement for evaluation).


setLayoutElement

protected void setLayoutElement(LayoutElement desc)

This method sets the LayoutElement that is associated with the 'if' check being evaluated. This is not normally needed, it is only needed if the 'if' check contains an expression which requires a LayoutElement to be properly evaluated.


getLayoutElement

public LayoutElement getLayoutElement()

Retreives the LayoutElement associated with this PermissionChecker (only needed in cases where a expression requires a LayoutElement for evaluation).


preProcessString

protected char[] preProcessString(java.lang.String source)
This method replaces all "true" / "false" strings w/ 't'/'f'. It converts the String into a char[]. It replaces all user defined functions w/ 'F' and places a Function in a list per the registered user-defined function. All other strings are converted to an 'F' and a StringFunction is added to the function list.


storeFunction

protected int storeFunction(char[] arr,
                            int idx)

This method looks at the given char array starting at index and continues until an operator (or end of String) is encountered. It then uses this string to lookup a registered function (if any), it stores that function (with parameters)... or if the function is not found, it registers a "String function" (which always returns true).


getFunction

protected static PermissionChecker.Function getFunction(java.lang.String functionName)
This method is a factory method for constructing a new function based on the function name passed in. The function must be registered prior to invoking this method.


registerFunction

public static void registerFunction(java.lang.String functionName,
                                    java.lang.Class function)

This method allows arbitrary functions to be registered. Function names should only contain letters or numbers, other characters or whitespace may cause problems. No checking is done to ensure this, however.

Functions will be expressed in an equation as follows:

Function parameters also should only contain alpha-numeric characters.

Functions must implement PermissionChecker.Function interface


isOperator

public static boolean isOperator(char ch)
This method returns true if the given character is a valid operator.


generatePostfix

protected char[] generatePostfix(java.lang.String infixStr)
This method calculates the postfix representation of the infix equation passed in. It returns the postfix equation as a char[].

Parameters:
infixStr - The infix representation of the equation.
Returns:
postfix representation of the equation as a char[] (the f()'s are removed and stored in _functionList).

hasPermission

public boolean hasPermission()
This method is invoked to determine if the equation evaluates to true or false.


getInfix

public java.lang.String getInfix()
This method returns the infix representation of the equation, in other words: the original String passed in.


setInfix

public void setInfix(java.lang.String equation)
This method sets the equation and forces a re-evaluation of the equation. It returns the postfix representation of the equation.

Parameters:
equation - The infix equation to use

getPostfixArr

protected char[] getPostfixArr()

setPostfixArr

protected void setPostfixArr(char[] postfix)

getPostfix

public java.lang.String getPostfix()

toString

public java.lang.String toString()
Displays the infix and postfix version of the equation.

Overrides:
toString in class java.lang.Object

stripWhiteSpace

public static java.lang.String stripWhiteSpace(java.lang.String input)
This method removes all whitespace from the given String


main

public static void main(java.lang.String[] args)
This is here to provide some test cases. It only tests the conversion to postfix notation.