org.springframework.rules.constraint
Class MethodInvokingConstraint

java.lang.Object
  extended by org.springframework.rules.constraint.MethodInvokingConstraint
All Implemented Interfaces:
Constraint, TypeResolvable

public class MethodInvokingConstraint
extends Object
implements Constraint, TypeResolvable

A adapter that can adapt a method on an object that accepts a single argument and returns a boolean result a UnaryPredicate. For example, a DAO might have the method isUnique(String objectName) that tests whether not a name parameter is unique. To adapt that method as a UnaryPredicate, use this class.

Author:
Keith Donald

Constructor Summary
MethodInvokingConstraint(Object targetObject, String methodName)
          Creates a MethodInvokingConstraint for the provided target object - the constraint logic is encapsulated within the specified method name.
MethodInvokingConstraint(Object targetObject, String methodName, Class parameterType)
           
MethodInvokingConstraint(Object targetObject, String methodName, Class parameterType, String constraintType)
           
MethodInvokingConstraint(Object targetObject, String methodName, String constraintType)
           
 
Method Summary
 String getType()
          Returns this object's logical type identifier.
 void setType(String type)
           
 boolean test(Object argument)
          Test the provided argument against this predicate's condition.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MethodInvokingConstraint

public MethodInvokingConstraint(Object targetObject,
                                String methodName)
Creates a MethodInvokingConstraint for the provided target object - the constraint logic is encapsulated within the specified method name. Note: this constructor will attempt to guess the parameter type for the method as it accept a single unary argument and return a boolean result.

Parameters:
targetObject - The target object
methodName - The method name

MethodInvokingConstraint

public MethodInvokingConstraint(Object targetObject,
                                String methodName,
                                String constraintType)

MethodInvokingConstraint

public MethodInvokingConstraint(Object targetObject,
                                String methodName,
                                Class parameterType)

MethodInvokingConstraint

public MethodInvokingConstraint(Object targetObject,
                                String methodName,
                                Class parameterType,
                                String constraintType)
Method Detail

getType

public String getType()
Description copied from interface: TypeResolvable
Returns this object's logical type identifier.

Specified by:
getType in interface TypeResolvable
Returns:
The type identifier

setType

public void setType(String type)

test

public boolean test(Object argument)
Description copied from interface: Constraint
Test the provided argument against this predicate's condition.

Specified by:
test in interface Constraint
Parameters:
argument - the argument value
Returns:
true if the condition was satisfied, false otherwise


Copyright © 2004-2008 The Spring Framework. All Rights Reserved.