1 | |
package org.apache.commons.contract.constraints; |
2 | |
|
3 | |
import java.util.Locale; |
4 | |
|
5 | |
import org.apache.commons.contract.Context; |
6 | |
import org.apache.commons.i18n.bundles.ErrorBundle; |
7 | |
import org.apache.commons.i18n.bundles.TextBundle; |
8 | |
|
9 | 0 | public class LocaleConstraints implements Constraints { |
10 | 0 | public static final LocaleConstraints UNCONSTRAINED = new LocaleConstraints(); |
11 | |
|
12 | |
public void validate(Object value, Context context) throws ValidationException { |
13 | 0 | } |
14 | |
|
15 | |
public Object cast(Object value, Context context) throws CastException { |
16 | 0 | if ( value instanceof Locale) { |
17 | 0 | return (Locale)value; |
18 | |
} |
19 | |
try { |
20 | 0 | return new Locale(StringConstraints.UNCONSTRAINED.cast(value, null).toString()); |
21 | 0 | } catch ( CastException exception ) { |
22 | 0 | throw new CastException(new ErrorBundle("uncastableLocale", new Object[] { value })); |
23 | |
} |
24 | |
} |
25 | |
|
26 | |
public TextBundle verboseConstraints() { |
27 | 0 | return new TextBundle("unconstrainedLocale"); |
28 | |
} |
29 | |
} |