com.cafesoft.cams.attr.func
Class AbstractFunction

java.lang.Object
  |
  +--com.cafesoft.cams.attr.func.AbstractFunction
All Implemented Interfaces:
Function
Direct Known Subclasses:
MatchFunction

public abstract class AbstractFunction
extends Object
implements Function

AbstractFunction is a superclass containing common implementation code for Functions.

Since:
4/14/2004

Field Summary
static String FUNCTION_NS
          The standard namespace where all the spec-defined functions live
 
Constructor Summary
  AbstractFunction(String functionName, int functionId, String[] argTypes, boolean[] argIsBag, String returnType, boolean returnsBag)
          Constructor that sets up the function as having different types for each given parameter.
  AbstractFunction(String functionName, int functionId, String returnType, boolean returnsBag)
          Constructor that sets up some basic values for functions that will take care of parameter checking on their own.
  AbstractFunction(String functionName, int functionId, String argType, boolean argIsBag, int numArgs, int minArgs, String returnType, boolean returnsBag)
          Constructor that sets up the function as having some number of arguments all of the same given type.
protected AbstractFunction(String functionName, int functionId, String argType, boolean argIsBag, int numArgs, String returnType, boolean returnsBag)
          Constructor for use with functions having any number of arguments, but all of the same type.
 
Method Summary
 void checkArgList(List argList)
          Checks that the given argList contains Evaluatables of the right types, in the right order, and are the right number for this function to evaluate.
 void checkArgListAllowBags(List argList)
          Checks that the given argList contains Evaluatables of the right types, in the right order, and are the right number for this function to evaluate.
protected  EvaluationResult evalArgs(List argList, EvaluationContext evalContext, AttributeValue[] args)
          Evaluates each argument, filling in the argument array with the resulting values.
abstract  EvaluationResult evaluate(List argList, EvaluationContext evalContext)
          Evaluates the Function using the given list of arguments.
 int getFunctionId()
          Get the integer function identifier for this particular object.
 String getFunctionName()
          Get the name of the function for this particular object.
 URI getIdentifier()
          Get the identifier of this function.
 URI getReturnType()
          Get the type of AttributeValue that this function returns from a successful evaluate invocation.
 boolean returnsBag()
          Indicate whether this function will return a bag of values or just a single value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FUNCTION_NS

public static final String FUNCTION_NS
The standard namespace where all the spec-defined functions live

See Also:
Constant Field Values
Constructor Detail

AbstractFunction

protected AbstractFunction(String functionName,
                           int functionId,
                           String argType,
                           boolean argIsBag,
                           int numArgs,
                           String returnType,
                           boolean returnsBag)
                    throws IllegalArgumentException
Constructor for use with functions having any number of arguments, but all of the same type. If numArgs is -1, then the argment list length is variable

Parameters:
functionName - the name of this function as used by the factory and any XACML policies
functionId - an optional identifier that can be used by your code for convenience
argType - the type of all arguments to this function, as used by the factory and any XACML documents
argIsBag - whether or not every parameter is actually a bag of values
numArgs - the number of arguments required by this function, or -1 if any number are allowed
returnType - the type returned by this function, as used by the factory and any XACML documents
returnsBag - whether or not this function returns a bag of values
Throws:
IllegalArgumentException - if the function name is not a valid URI.

AbstractFunction

public AbstractFunction(String functionName,
                        int functionId,
                        String argType,
                        boolean argIsBag,
                        int numArgs,
                        int minArgs,
                        String returnType,
                        boolean returnsBag)
                 throws IllegalArgumentException
Constructor that sets up the function as having some number of arguments all of the same given type. If numArgs is -1, then the length is variable, and then minArgs may be used to specify a minimum number of arguments. If numArgs is not -1, then minArgs is ignored.

Parameters:
functionName - the name of this function as used by the factory and any XACML policies
functionId - an optional identifier that can be used by your code for convenience
argType - the type of all arguments to this function, as used by the factory and any XACML documents
argIsBag - whether or not every parameter is actually a bag of values
numArgs - the number of arguments required by this function, or -1 if any number are allowed
minArgs - the minimum number of arguments required if numArgs is -1
returnType - the type returned by this function, as used by the factory and any XACML documents
returnsBag - whether or not this function returns a bag of values
Throws:
IllegalArgumentException - if the function name is not a valid URI.

AbstractFunction

public AbstractFunction(String functionName,
                        int functionId,
                        String[] argTypes,
                        boolean[] argIsBag,
                        String returnType,
                        boolean returnsBag)
                 throws IllegalArgumentException
Constructor that sets up the function as having different types for each given parameter.

Parameters:
functionName - the name of this function as used by the factory and any XACML policies
functionId - an optional identifier that can be used by your code for convenience
argTypes - the type of each parameter, in order, required by this function, as used by the factory and any XACML documents
argIsBag - whether or not each parameter is actually a bag of values
returnType - the type returned by this function, as used by the factory and any XACML documents
returnsBag - whether or not this function returns a bag of values
Throws:
IllegalArgumentException - if the function name is not a valid URI.

AbstractFunction

public AbstractFunction(String functionName,
                        int functionId,
                        String returnType,
                        boolean returnsBag)
                 throws IllegalArgumentException
Constructor that sets up some basic values for functions that will take care of parameter checking on their own. If you use this constructor for your function class, then you must override the two check methods to make sure that arguments are correct.

Parameters:
functionName - the name of this function as used by the factory and any XACML policies
functionId - an optional identifier that can be used by your code for convenience
returnType - the type returned by this function, as used by the factory and any XACML documents
returnsBag - whether or not this function returns a bag of values
Throws:
IllegalArgumentException - if the function name and/or the return type is not a valid URI.
Method Detail

evaluate

public abstract EvaluationResult evaluate(List argList,
                                          EvaluationContext evalContext)
Evaluates the Function using the given list of arguments. The List contains Evaluatables which must be of the correct type. Each parameter should be evaluated by the Function, unless it does not need to evaluate all inputs to determine a result.

Specified by:
evaluate in interface Function
Parameters:
argList - the List of arguments for the function, which must be the appropriate number of Evaluatables of the correct type.
evalContext - the representation of the request
Returns:
a result containing the AttributeValue computed when evaluating the function, or Status specifying some error condition

getIdentifier

public URI getIdentifier()
Get the identifier of this function.

Specified by:
getIdentifier in interface Function
Returns:
the function's identifier as a URI.

getFunctionName

public String getFunctionName()
Get the name of the function for this particular object.

Specified by:
getFunctionName in interface Function
Returns:
the function name.

getFunctionId

public int getFunctionId()
Get the integer function identifier for this particular object.

Specified by:
getFunctionId in interface Function
Returns:
the integer function identifier.

getReturnType

public URI getReturnType()
Get the type of AttributeValue that this function returns from a successful evaluate invocation.

Specified by:
getReturnType in interface Function
Returns:
the type returned by this function

returnsBag

public boolean returnsBag()
Indicate whether this function will return a bag of values or just a single value.

Specified by:
returnsBag in interface Function
Returns:
true if evaluation will return a bag, else false.

checkArgList

public void checkArgList(List argList)
                  throws IllegalArgumentException
Checks that the given argList contains Evaluatables of the right types, in the right order, and are the right number for this function to evaluate. If the function cannot accept the inputs for evaluation, an IllegalArgumentException is thrown.

Specified by:
checkArgList in interface Function
Parameters:
argList - a List of Evaluatables
Throws:
IllegalArgumentException - if the arguments do match what the function accepts for evaluation

checkArgListAllowBags

public void checkArgListAllowBags(List argList)
                           throws IllegalArgumentException
Checks that the given argList contains Evaluatables of the right types, in the right order, and are the right number for this function to evaluate. If the function cannot accept the arguments for evaluation, an IllegalArgumentException is thrown. This check allows arguments that evaluate to a bag and must be invoked by callers that invoke the function over a bag of arguments.

Specified by:
checkArgListAllowBags in interface Function
Parameters:
argList - a List of Evaluatables
Throws:
IllegalArgumentException - if the arguments do match what the function accepts for evaluation

evalArgs

protected EvaluationResult evalArgs(List argList,
                                    EvaluationContext evalContext,
                                    AttributeValue[] args)
Evaluates each argument, filling in the argument array with the resulting values. If an error occurs, this method returns the error, otherwise null is returned, indicating that evaluation was successful for all inputs, and the resulting argument list can be used.

Parameters:
argList - a List of Evaluatable objects representing the parameters to evaluate
evalContext - the representation of the request
args - an array as long as the argument List that will, on return, contain the AttributeValues generated from evaluating all arguments.
Returns:
null if no errors were encountered, otherwise an EvaluationResult representing the error


Generated on 5:16:42 PM May 12, 2008, © 1996-2005 Cafésoft LLC. All rights reserved.