001    /*
002     * Copyright 2002-2004 the original author or authors.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005     * use this file except in compliance with the License. You may obtain a copy of
006     * the License at
007     *
008     * http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012     * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013     * License for the specific language governing permissions and limitations under
014     * the License.
015     */
016    package org.springframework.rules.factory;
017    
018    import org.springframework.rules.constraint.Constraint;
019    import org.springframework.rules.closure.support.AlgorithmsAccessor;
020    import org.springframework.rules.constraint.property.PropertyConstraint;
021    import org.springframework.util.Assert;
022    
023    /**
024     * Helper class for creating and composing constraints for a single domain object property.
025     *
026     * @author Keith Donald
027     */
028    public class PropertyConstraints extends AlgorithmsAccessor {
029    
030            private Constraints c = Constraints.instance();
031    
032            private String propertyName;
033    
034            public PropertyConstraints(String propertyName) {
035                    setPropertyName(propertyName);
036            }
037    
038            public void setPropertyName(String propertyName) {
039                    Assert.notNull(propertyName, "The propertyName to create constraints for is required");
040                    this.propertyName = propertyName;
041            }
042    
043            public PropertyConstraint all(Constraint[] valueConstraints) {
044                    return c.all(propertyName, valueConstraints);
045            }
046    
047            public PropertyConstraint any(Constraint[] valueConstraints) {
048                    return c.any(propertyName, valueConstraints);
049            }
050    
051            public PropertyConstraint eq(Object value) {
052                    return c.eq(propertyName, value);
053            }
054    
055            public PropertyConstraint lt(Comparable value) {
056                    return c.lt(propertyName, value);
057            }
058    
059            public PropertyConstraint lte(Comparable value) {
060                    return c.lte(propertyName, value);
061            }
062    
063            public PropertyConstraint gt(Comparable value) {
064                    return c.gte(propertyName, value);
065            }
066    
067            public PropertyConstraint gte(Comparable value) {
068                    return c.gte(propertyName, value);
069            }
070    
071            public PropertyConstraint eqProperty(String otherPropertyName) {
072                    return c.eqProperty(propertyName, otherPropertyName);
073            }
074    
075            public PropertyConstraint ltProperty(String otherPropertyName) {
076                    return c.ltProperty(propertyName, otherPropertyName);
077            }
078    
079            public PropertyConstraint lteProperty(String otherPropertyName) {
080                    return c.lteProperty(propertyName, otherPropertyName);
081            }
082    
083            public PropertyConstraint gtProperty(String otherPropertyName) {
084                    return c.gtProperty(propertyName, otherPropertyName);
085            }
086    
087            public PropertyConstraint gteProperty(String otherPropertyName) {
088                    return c.gteProperty(propertyName, otherPropertyName);
089            }
090    
091            public PropertyConstraint inRange(Comparable min, Comparable max) {
092                    return c.inRange(propertyName, min, max);
093            }
094    
095            public PropertyConstraint inRangeProperties(String minProperty, String maxProperty) {
096                    return c.inRangeProperties(propertyName, minProperty, maxProperty);
097            }
098    
099    }