org.springframework.rules.constraint.property
Class ConditionalPropertyConstraint

java.lang.Object
  extended by org.springframework.rules.constraint.property.AbstractPropertyConstraint
      extended by org.springframework.rules.constraint.property.ConditionalPropertyConstraint
All Implemented Interfaces:
Constraint, PropertyConstraint, TypeResolvable

public class ConditionalPropertyConstraint
extends AbstractPropertyConstraint
implements TypeResolvable

Provides a way to trigger rules for propertyB when propertyA satisfies a certain condition:

        if (propertyA satisfies the conditional constraint)
        {
                check the rules for propertyB
        }
 
with an optional part:
  else
  {
      check the rules for propertyC
  }
 

More complex situations are possible by using compound constraints which leverages the previous to:

 if (constraint(propertyA, propertyB,...) == true)
 {
     checkConstraint(property1, property2,...);
 }
 \\ optional part
 else
 {
     checkConstraint(propertyX, propertyY,...);
 }
 

This class can be compared to the IfTrue class: it applies the same pattern but on different properties instead of on a property value.

Author:
jh

Constructor Summary
ConditionalPropertyConstraint(PropertyConstraint ifConstraint, PropertyConstraint thenConstraint)
           
ConditionalPropertyConstraint(PropertyConstraint ifConstraint, PropertyConstraint thenConstraint, PropertyConstraint elseConstraint)
           
ConditionalPropertyConstraint(PropertyConstraint ifConstraint, PropertyConstraint thenConstraint, PropertyConstraint elseConstraint, String type)
          Create a constraint which simulates the if...then...else pattern applied on separate properties.
ConditionalPropertyConstraint(PropertyConstraint ifConstraint, PropertyConstraint thenConstraint, String type)
          Create a constraint which simulates the if...then pattern applied on separate properties.
 
Method Summary
 String getType()
          Returns this object's logical type identifier.
 boolean isCompoundRule()
          Does this property constraint effect more than one property?
 boolean isDependentOn(String propertyName)
          Returns true if this property constraint is dependent on the provided propertyName for test evaluation; that is, it should be retested when propertyName changes.
 void setType(String type)
           
protected  boolean test(PropertyAccessStrategy domainObjectAccessStrategy)
           
 
Methods inherited from class org.springframework.rules.constraint.property.AbstractPropertyConstraint
getPropertyName, setPropertyName, test, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConditionalPropertyConstraint

public ConditionalPropertyConstraint(PropertyConstraint ifConstraint,
                                     PropertyConstraint thenConstraint)
See Also:
ConditionalPropertyConstraint(PropertyConstraint, PropertyConstraint, String)

ConditionalPropertyConstraint

public ConditionalPropertyConstraint(PropertyConstraint ifConstraint,
                                     PropertyConstraint thenConstraint,
                                     String type)
Create a constraint which simulates the if...then pattern applied on separate properties.

Parameters:
ifConstraint - the PropertyConstraint that triggers the test (satisfying a certain condition).
thenConstraint - the PropertyConstraint to test in the specified condition.

ConditionalPropertyConstraint

public ConditionalPropertyConstraint(PropertyConstraint ifConstraint,
                                     PropertyConstraint thenConstraint,
                                     PropertyConstraint elseConstraint)
See Also:
ConditionalPropertyConstraint(PropertyConstraint, PropertyConstraint, PropertyConstraint, String)

ConditionalPropertyConstraint

public ConditionalPropertyConstraint(PropertyConstraint ifConstraint,
                                     PropertyConstraint thenConstraint,
                                     PropertyConstraint elseConstraint,
                                     String type)
Create a constraint which simulates the if...then...else pattern applied on separate properties.

Parameters:
ifConstraint - the PropertyConstraint that triggers the test (satisfying a certain condition).
thenConstraint - the PropertyConstraint to test in the specified condition.
elseConstraint - the PropertyConstraint to test if the condition is NOT satisfied. May be null.
type - the messageCode used to fetch the message.
Method Detail

isCompoundRule

public boolean isCompoundRule()
Description copied from interface: PropertyConstraint
Does this property constraint effect more than one property?

Specified by:
isCompoundRule in interface PropertyConstraint
Overrides:
isCompoundRule in class AbstractPropertyConstraint
Returns:
true if yes, false otherwise

isDependentOn

public boolean isDependentOn(String propertyName)
Description copied from interface: PropertyConstraint
Returns true if this property constraint is dependent on the provided propertyName for test evaluation; that is, it should be retested when propertyName changes.

Specified by:
isDependentOn in interface PropertyConstraint
Overrides:
isDependentOn in class AbstractPropertyConstraint
Returns:
true or false

test

protected boolean test(PropertyAccessStrategy domainObjectAccessStrategy)
Specified by:
test in class AbstractPropertyConstraint

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)


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