|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.oval.Validator
net.sf.oval.guard.Guard
public class Guard
Extended version of the validator to realize programming by contract.
| Nested Class Summary | |
|---|---|
protected static class |
Guard.GuardMethodPreResult
Note: Only required until AspectJ allows throwing of checked exceptions |
| Nested classes/interfaces inherited from class net.sf.oval.Validator |
|---|
Validator.DelegatingParameterNameResolver |
| Field Summary | |
|---|---|
protected static Guard.GuardMethodPreResult |
DO_NOT_PROCEED
Note: Only required until AspectJ allows throwing of checked exceptions |
| Fields inherited from class net.sf.oval.Validator |
|---|
currentlyValidatedObjects, currentViolations, expressionLanguageRegistry, ognRegistry, parameterNameResolver |
| Constructor Summary | |
|---|---|
Guard()
Constructs a new guard object and uses a new instance of AnnotationsConfigurer |
|
Guard(Collection<Configurer> configurers)
|
|
Guard(Configurer... configurers)
|
|
| Method Summary | |
|---|---|
void |
addCheckExclusions(Constructor<?> ctor,
int paramIndex,
CheckExclusion... exclusions)
Registers constraint checks for the given constructor parameter |
void |
addCheckExclusions(Method method,
int paramIndex,
CheckExclusion... exclusions)
Registers constraint checks for the given method parameter |
void |
addChecks(Constructor<?> ctor,
int paramIndex,
Check... checks)
Registers constraint checks for the given constructor parameter |
void |
addChecks(Method method,
Check... checks)
Registers constraint checks for the given method's return value |
void |
addChecks(Method method,
int paramIndex,
Check... checks)
Registers constraint checks for the given method parameter |
void |
addChecks(Method method,
PostCheck... checks)
Registers post condition checks to a method's return value |
void |
addChecks(Method method,
PreCheck... checks)
Registers pre condition checks to a method's return value |
boolean |
addListener(ConstraintsViolatedListener listener)
Registers the given listener for all thrown ConstraintViolationExceptions |
boolean |
addListener(ConstraintsViolatedListener listener,
Class<?> guardedClass)
Registers the given listener for all thrown ConstraintViolationExceptions on objects of the given class |
boolean |
addListener(ConstraintsViolatedListener listener,
Object guardedObject)
Registers the given listener for all thrown ConstraintViolationExceptions on objects of the given object |
protected Map<PostCheck,Object> |
calculateMethodPostOldValues(Object validatedObject,
Method method,
Object[] args)
Evaluates the old expression |
ProbeModeListener |
disableProbeMode(Object guardedObject)
Disables the probe mode for the given object in the current thread. |
void |
enableProbeMode(Object guardedObject)
Enables the probe mode for the given object in the current thread. |
Check[] |
getChecks(Method method,
int paramIndex)
Returns the registers constraint pre condition checks for the given method parameter |
PostCheck[] |
getChecksPost(Method method)
Returns the registered post condition checks for the given method |
PreCheck[] |
getChecksPre(Method method)
Returns the registered pre condition checks for the given method. |
ParameterNameResolver |
getParameterNameResolver()
|
protected void |
guardConstructorPost(Object guardedObject,
Constructor<?> ctor,
Object[] args)
This method is provided for use by guard aspects. |
protected void |
guardConstructorPre(Object guardedObject,
Constructor<?> ctor,
Object[] args)
This method is provided for use by guard aspects. |
protected Object |
guardMethod(Object guardedObject,
Method method,
Object[] args,
Invocable invocable)
This method is provided for use by guard aspects. |
protected void |
guardMethodPost(Object returnValue,
Guard.GuardMethodPreResult preResult)
Note: Only required until AspectJ allows throwing of checked exceptions, then guardMethod(Object, Method, Object[], Invocable) can be used instead
This method is provided for use by guard aspects. |
protected Guard.GuardMethodPreResult |
guardMethodPre(Object guardedObject,
Method method,
Object[] args)
Note: Only required until AspectJ allows throwing of checked exceptions, then guardMethod(Object, Method, Object[], Invocable) can be used instead
This method is provided for use by guard aspects. |
boolean |
hasListener(ConstraintsViolatedListener listener)
|
boolean |
hasListener(ConstraintsViolatedListener listener,
Class<?> guardedClass)
|
boolean |
hasListener(ConstraintsViolatedListener listener,
Object guardedObject)
|
boolean |
isActivated()
|
boolean |
isInProbeMode(Object guardedObject)
Determines if the probe mode is enabled for the given object in the current thread. |
boolean |
isInvariantsEnabled()
Determines if invariants are checked prior and after every call to a non-private method or constructor. |
boolean |
isInvariantsEnabled(Class<?> guardedClass)
Determines if invariants are checked prior and after every call to a non-private method or constructor. |
boolean |
isPostConditionsEnabled()
|
boolean |
isPreConditionsEnabled()
|
protected void |
notifyListeners(Object guardedObject,
ConstraintsViolatedException ex)
notifies all registered validation listener about the occurred constraint violation exception |
void |
removeCheckExclusions(Constructor<?> ctor,
int paramIndex,
CheckExclusion... exclusions)
Removes constraint check exclusions from the given constructor parameter |
void |
removeCheckExclusions(Method method,
int paramIndex,
CheckExclusion... exclusions)
Removes constraint check exclusions from the given method parameter |
void |
removeChecks(Constructor<?> ctor,
int paramIndex,
Check... checks)
Removes constraint checks from the given constructor parameter |
void |
removeChecks(Method method,
int paramIndex,
Check... checks)
Removes constraint checks for the given method parameter |
void |
removeChecks(Method method,
PostCheck... checks)
Registers post condition checks to a method's return value |
void |
removeChecks(Method method,
PreCheck... checks)
Registers pre condition checks to a method's return value |
boolean |
removeListener(ConstraintsViolatedListener listener)
Removes the given listener |
boolean |
removeListener(ConstraintsViolatedListener listener,
Class<?> guardedClass)
Removes the given listener |
boolean |
removeListener(ConstraintsViolatedListener listener,
Object guardedObject)
Removes the given listener |
void |
setActivated(boolean isActivated)
If set to false OVal's programming by contract features are disabled and constraints are not checked automatically during runtime. |
void |
setInvariantsEnabled(boolean isEnabled)
Specifies if invariants are checked prior and after calls to non-private methods and constructors. |
void |
setInvariantsEnabled(Class<?> guardedClass,
boolean isEnabled)
Specifies if invariants are checked prior and after calls to non-private methods and constructors. |
void |
setParameterNameResolver(ParameterNameResolver parameterNameResolver)
|
void |
setPostConditionsEnabled(boolean isEnabled)
|
void |
setPreConditionsEnabled(boolean isEnabled)
|
protected List<ConstraintViolation> |
validateConstructorParameters(Object validatedObject,
Constructor<?> constructor,
Object[] argsToValidate)
Validates the give arguments against the defined constructor parameter constraints. |
protected void |
validateInvariants(Object guardedObject,
List<ConstraintViolation> violations,
String[] profiles)
validates the field and getter constrains of the given object. |
protected void |
validateMethodParameters(Object validatedObject,
Method method,
Object[] args,
List<ConstraintViolation> violations)
Validates the pre conditions for a method call. |
protected void |
validateMethodPost(Object validatedObject,
Method method,
Object[] args,
Object returnValue,
Map<PostCheck,Object> oldValues,
List<ConstraintViolation> violations)
Validates the post conditions for a method call. |
protected void |
validateMethodPre(Object validatedObject,
Method method,
Object[] args,
List<ConstraintViolation> violations)
Validates the @Pre conditions for a method call. |
protected void |
validateMethodReturnValue(Object validatedObject,
Method method,
Object returnValue,
List<ConstraintViolation> violations)
Validates the return value checks for a method call. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final Guard.GuardMethodPreResult DO_NOT_PROCEED
| Constructor Detail |
|---|
public Guard()
public Guard(Collection<Configurer> configurers)
public Guard(Configurer... configurers)
| Method Detail |
|---|
public void addCheckExclusions(Constructor<?> ctor,
int paramIndex,
CheckExclusion... exclusions)
throws IllegalArgumentException,
InvalidConfigurationException
ctor - paramIndex - exclusions -
IllegalArgumentException - if method == null or exclusions == null or exclusions is empty
InvalidConfigurationException - if the declaring class is not guarded or the parameterIndex is out of range
public void addCheckExclusions(Method method,
int paramIndex,
CheckExclusion... exclusions)
throws IllegalArgumentException,
InvalidConfigurationException
method - paramIndex - exclusions -
IllegalArgumentException - if method == null or exclusions == null or exclusions is empty
InvalidConfigurationException - if the declaring class is not guarded or the parameterIndex is out of range
public void addChecks(Constructor<?> ctor,
int paramIndex,
Check... checks)
throws IllegalArgumentException,
InvalidConfigurationException
ctor - paramIndex - checks -
IllegalArgumentException - if constructor == null or checks == null or checks is
empty
InvalidConfigurationException - if the declaring class is not guarded or the parameterIndex is out of range
public void addChecks(Method method,
Check... checks)
throws IllegalArgumentException,
InvalidConfigurationException
addChecks in class Validatormethod - checks -
IllegalArgumentException - if getter == null or checks == null or checks is empty
InvalidConfigurationException - if method does not declare a return type (void), or the declaring class is
not guarded
public void addChecks(Method method,
int paramIndex,
Check... checks)
throws IllegalArgumentException,
InvalidConfigurationException
method - paramIndex - checks -
IllegalArgumentException - if method == null or checks == null or checks is empty
InvalidConfigurationException - if the declaring class is not guarded or the parameterIndex is out of range
public void addChecks(Method method,
PostCheck... checks)
throws IllegalArgumentException,
InvalidConfigurationException
method - checks -
IllegalArgumentException - if method == null or checks == null or checks is empty
InvalidConfigurationException - if the declaring class is not guarded
public void addChecks(Method method,
PreCheck... checks)
throws IllegalArgumentException,
InvalidConfigurationException
method - checks -
IllegalArgumentException - if method == null or checks == null or checks is empty
InvalidConfigurationException - if the declaring class is not guarded
public boolean addListener(ConstraintsViolatedListener listener)
throws IllegalArgumentException
listener - the listener to register
true if the listener was not yet registered
IllegalArgumentException - if listener == null
public boolean addListener(ConstraintsViolatedListener listener,
Class<?> guardedClass)
throws IllegalArgumentException
listener - the listener to registerguardedClass - guarded class or interface
true if the listener was not yet registered
IllegalArgumentException - if listener == null or guardedClass == null
public boolean addListener(ConstraintsViolatedListener listener,
Object guardedObject)
listener - the listener to registerguardedObject -
true if the listener was not yet registered
IllegalArgumentException - if listener == null or guardedObject == null
protected Map<PostCheck,Object> calculateMethodPostOldValues(Object validatedObject,
Method method,
Object[] args)
throws ValidationFailedException
validatedObject - method - args -
ValidationFailedException
public ProbeModeListener disableProbeMode(Object guardedObject)
throws IllegalArgumentException,
IllegalStateException
guardedObject - the object to disable the probe mode for
IllegalArgumentException - if guardedObject == null
IllegalStateException - in case probe mode was not enabled for the given object
public void enableProbeMode(Object guardedObject)
throws IllegalArgumentException,
IllegalStateException
guardedObject - the object to enable the probe mode for
IllegalArgumentException - if guardedObject == null
IllegalStateException - if the probe mode is already enabled
public Check[] getChecks(Method method,
int paramIndex)
throws InvalidConfigurationException
method - paramIndex -
IllegalArgumentException - if method == null
InvalidConfigurationException
public PostCheck[] getChecksPost(Method method)
throws IllegalArgumentException
method -
IllegalArgumentException - if method == null
public PreCheck[] getChecksPre(Method method)
throws IllegalArgumentException
method -
IllegalArgumentException - if method == nullpublic ParameterNameResolver getParameterNameResolver()
protected void guardConstructorPost(Object guardedObject,
Constructor<?> ctor,
Object[] args)
throws ConstraintsViolatedException,
ValidationFailedException
ConstraintsViolatedException
ValidationFailedException
protected void guardConstructorPre(Object guardedObject,
Constructor<?> ctor,
Object[] args)
throws ConstraintsViolatedException,
ValidationFailedException
ConstraintsViolatedException - if anything precondition is not satisfied
ValidationFailedException
protected Object guardMethod(Object guardedObject,
Method method,
Object[] args,
Invocable invocable)
throws Throwable
guardedObject - method - args - invocable -
ConstraintsViolatedException - if an constraint violation occurs and the validated object is not in probe mode.
ValidationFailedException
Throwable
protected void guardMethodPost(Object returnValue,
Guard.GuardMethodPreResult preResult)
throws ConstraintsViolatedException,
ValidationFailedException
guardMethod(Object, Method, Object[], Invocable) can be used instead
This method is provided for use by guard aspects.
returnValue - preResult -
ConstraintsViolatedException - if an constraint violation occurs and the validated object is not in probe
mode.
ValidationFailedException
protected Guard.GuardMethodPreResult guardMethodPre(Object guardedObject,
Method method,
Object[] args)
throws ConstraintsViolatedException,
ValidationFailedException
guardMethod(Object, Method, Object[], Invocable) can be used instead
This method is provided for use by guard aspects.
guardedObject - method - args -
guardMethodPost(Object, GuardMethodPreResult)
ConstraintsViolatedException - if an constraint violation occurs and the validated object is not in probe
mode.
ValidationFailedException
public boolean hasListener(ConstraintsViolatedListener listener)
throws IllegalArgumentException
listener -
true if the listener is registered
IllegalArgumentException - if listener == null
public boolean hasListener(ConstraintsViolatedListener listener,
Class<?> guardedClass)
throws IllegalArgumentException
listener - guardedClass - guarded class or interface
true if the listener is registered
IllegalArgumentException - if listener == null or guardedClass == null
public boolean hasListener(ConstraintsViolatedListener listener,
Object guardedObject)
throws IllegalArgumentException
listener - guardedObject -
true if the listener is registered
IllegalArgumentException - if listener == null or guardedObject == nullpublic boolean isActivated()
public boolean isInProbeMode(Object guardedObject)
guardedObject -
public boolean isInvariantsEnabled()
public boolean isInvariantsEnabled(Class<?> guardedClass)
guardedClass - the guarded class
public boolean isPostConditionsEnabled()
public boolean isPreConditionsEnabled()
protected void notifyListeners(Object guardedObject,
ConstraintsViolatedException ex)
public void removeCheckExclusions(Constructor<?> ctor,
int paramIndex,
CheckExclusion... exclusions)
throws InvalidConfigurationException
ctor - paramIndex - exclusions -
InvalidConfigurationException - if the declaring class is not guarded or the parameterIndex is out of range
public void removeCheckExclusions(Method method,
int paramIndex,
CheckExclusion... exclusions)
throws InvalidConfigurationException
method - paramIndex - exclusions -
InvalidConfigurationException - if the declaring class is not guarded or the parameterIndex is out of range
public void removeChecks(Constructor<?> ctor,
int paramIndex,
Check... checks)
throws InvalidConfigurationException
ctor - paramIndex - checks -
InvalidConfigurationException - if the declaring class is not guarded or the parameterIndex is out of range
public void removeChecks(Method method,
int paramIndex,
Check... checks)
throws InvalidConfigurationException
method - paramIndex - checks -
IllegalArgumentException - if constructor == null or checks == null or checks is
empty
InvalidConfigurationException - if the parameterIndex is out of range
public void removeChecks(Method method,
PostCheck... checks)
throws InvalidConfigurationException
method - checks -
IllegalArgumentException - if method == null or checks == null or checks is empty
InvalidConfigurationException - if the declaring class is not guarded
public void removeChecks(Method method,
PreCheck... checks)
throws InvalidConfigurationException
method - checks -
IllegalArgumentException - if method == null or checks == null or checks is empty
InvalidConfigurationException - if the declaring class is not guarded
public boolean removeListener(ConstraintsViolatedListener listener)
throws IllegalArgumentException
listener -
true if the listener was registered
IllegalArgumentException - if listener == null
public boolean removeListener(ConstraintsViolatedListener listener,
Class<?> guardedClass)
throws IllegalArgumentException
listener - guardedClass - guarded class or interface
true if the listener was registered
IllegalArgumentException - if listener == null or guardedClass == null
public boolean removeListener(ConstraintsViolatedListener listener,
Object guardedObject)
throws IllegalArgumentException
listener - guardedObject -
true if the listener was registered
IllegalArgumentException - if listener == null or guardedObject == nullpublic void setActivated(boolean isActivated)
isActivated - the isActivated to setpublic void setInvariantsEnabled(boolean isEnabled)
isEnabled - the isInvariantsEnabled to set
public void setInvariantsEnabled(Class<?> guardedClass,
boolean isEnabled)
guardedClass - the guarded class to turn on/off the invariant checkingisEnabled - the isEnabled to set
public void setParameterNameResolver(ParameterNameResolver parameterNameResolver)
throws IllegalArgumentException
parameterNameResolver - the parameterNameResolver to set, cannot be null
IllegalArgumentException - if parameterNameResolver == nullpublic void setPostConditionsEnabled(boolean isEnabled)
isEnabled - the isEnabled to setpublic void setPreConditionsEnabled(boolean isEnabled)
isEnabled - the isEnabled to set
protected List<ConstraintViolation> validateConstructorParameters(Object validatedObject,
Constructor<?> constructor,
Object[] argsToValidate)
throws ValidationFailedException
ValidationFailedException
protected void validateInvariants(Object guardedObject,
List<ConstraintViolation> violations,
String[] profiles)
throws IllegalArgumentException,
ValidationFailedException
validateInvariants in class ValidatorguardedObject - the object to validate, cannot be null
IllegalArgumentException - if validatedObject == null
ValidationFailedException
protected void validateMethodParameters(Object validatedObject,
Method method,
Object[] args,
List<ConstraintViolation> violations)
throws ValidationFailedException
ValidationFailedException
protected void validateMethodPost(Object validatedObject,
Method method,
Object[] args,
Object returnValue,
Map<PostCheck,Object> oldValues,
List<ConstraintViolation> violations)
throws ValidationFailedException
ValidationFailedException
protected void validateMethodPre(Object validatedObject,
Method method,
Object[] args,
List<ConstraintViolation> violations)
throws ValidationFailedException
ValidationFailedException
protected void validateMethodReturnValue(Object validatedObject,
Method method,
Object returnValue,
List<ConstraintViolation> violations)
throws ValidationFailedException
ValidationFailedException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||