01: /*******************************************************************************
02: * Portions created by Sebastian Thomschke are copyright (c) 2005-2007 Sebastian
03: * Thomschke.
04: *
05: * All Rights Reserved. This program and the accompanying materials
06: * are made available under the terms of the Eclipse Public License v1.0
07: * which accompanies this distribution, and is available at
08: * http://www.eclipse.org/legal/epl-v10.html
09: *
10: * Contributors:
11: * Sebastian Thomschke - initial implementation.
12: *******************************************************************************/package net.sf.oval.constraint;
13:
14: import java.util.Map;
15:
16: import net.sf.oval.Validator;
17: import net.sf.oval.configuration.annotation.AbstractAnnotationCheck;
18: import net.sf.oval.context.OValContext;
19: import net.sf.oval.internal.CollectionFactoryHolder;
20:
21: /**
22: * @author Sebastian Thomschke
23: */
24: public class MinLengthCheck extends AbstractAnnotationCheck<MinLength> {
25: private static final long serialVersionUID = 1L;
26:
27: private int min;
28:
29: @Override
30: public void configure(final MinLength constraintAnnotation) {
31: super .configure(constraintAnnotation);
32: setMin(constraintAnnotation.value());
33: }
34:
35: @Override
36: public Map<String, String> getMessageVariables() {
37: final Map<String, String> messageVariables = CollectionFactoryHolder
38: .getFactory().createMap(2);
39: messageVariables.put("min", Integer.toString(min));
40: return messageVariables;
41: }
42:
43: /**
44: * @return the min
45: */
46: public int getMin() {
47: return min;
48: }
49:
50: public boolean isSatisfied(final Object validatedObject,
51: final Object value, final OValContext context,
52: final Validator validator) {
53: if (value == null)
54: return true;
55:
56: final int len = value.toString().length();
57: return len >= min;
58: }
59:
60: /**
61: * @param min the min to set
62: */
63: public void setMin(final int min) {
64: this.min = min;
65: }
66: }
|