001    package org.apache.commons.contract.constraints;
002    
003    import org.apache.commons.contract.Context;
004    import org.apache.commons.i18n.bundles.ErrorBundle;
005    import org.apache.commons.i18n.bundles.TextBundle;
006    
007    public class BooleanConstraints implements Constraints {
008            public final static String TRUE = Boolean.toString(true);
009        public final static String FALSE = Boolean.toString(false);
010    
011        public Object cast(Object value, Context context) throws CastException {
012            if ( value instanceof Boolean) {
013                return value;
014            } 
015            try {
016                return Boolean.valueOf(StringConstraints.UNCONSTRAINED.cast(value, null).toString());
017            } catch ( CastException exception ) {
018                throw new CastException(new ErrorBundle("uncastableBooleanValue", new Object[] { value }));
019            }
020        }
021        
022        public void validate(Object value, Context context) throws ValidationException {
023        }
024        
025        public TextBundle verboseConstraints() {
026            return new TextBundle("unconstrainedBoolean");
027        }
028    }