|
1 | 1 | package org.ocpsoft.rewrite.util; |
2 | 2 |
|
3 | 3 | import java.lang.reflect.Array; |
4 | | -import java.util.Collection; |
5 | 4 |
|
6 | | -import org.ocpsoft.common.services.ServiceLoader; |
7 | | -import org.ocpsoft.logging.Logger; |
8 | 5 | import org.ocpsoft.rewrite.bind.Converter; |
9 | 6 | import org.ocpsoft.rewrite.bind.Validator; |
10 | 7 | import org.ocpsoft.rewrite.context.EvaluationContext; |
11 | 8 | import org.ocpsoft.rewrite.event.Rewrite; |
12 | | -import org.ocpsoft.rewrite.exception.RewriteException; |
13 | 9 |
|
14 | 10 | public final class ValueHolderUtil |
15 | 11 | { |
16 | | - private static final Logger log = Logger.getLogger(ValueHolderUtil.class); |
17 | | - |
18 | | - public static Validator<?> resolveValidator(final Class<? extends Validator<?>> type) |
19 | | - { |
20 | | - try { |
21 | | - Collection<? extends Validator<?>> enriched = ServiceLoader.loadEnriched(type); |
22 | | - if (enriched != null) |
23 | | - { |
24 | | - if ((enriched.size() > 1) && log.isWarnEnabled()) |
25 | | - { |
26 | | - log.warn("Multiple Validator instances available for type [" + type.getName() + "], using first of " |
27 | | - + enriched + ""); |
28 | | - } |
29 | | - for (Validator<?> validator : enriched) { |
30 | | - if (validator != null) |
31 | | - { |
32 | | - return validator; |
33 | | - } |
34 | | - } |
35 | | - } |
36 | | - return null; |
37 | | - } |
38 | | - catch (Exception e) { |
39 | | - throw new RewriteException("Could not instantiate Validator of type [" + type.getName() + "]", e); |
40 | | - } |
41 | | - } |
42 | | - |
43 | | - public static final Converter<?> resolveConverter(final Class<? extends Converter<?>> type) |
44 | | - { |
45 | | - try { |
46 | | - Collection<? extends Converter<?>> enriched = ServiceLoader.loadEnriched(type); |
47 | | - if (enriched != null) |
48 | | - { |
49 | | - if ((enriched.size() > 1) && log.isWarnEnabled()) |
50 | | - { |
51 | | - log.warn("Multiple Converter instances available for type [" + type.getName() + "], using first of " |
52 | | - + enriched + ""); |
53 | | - } |
54 | | - for (Converter<?> converter : enriched) { |
55 | | - if (converter != null) |
56 | | - { |
57 | | - return converter; |
58 | | - } |
59 | | - } |
60 | | - } |
61 | | - return null; |
62 | | - } |
63 | | - catch (Exception e) { |
64 | | - throw new RewriteException("Could not instantiate Converter of type [" + type.getName() + "]", e); |
65 | | - } |
66 | | - } |
67 | | - |
68 | 12 | @SuppressWarnings({ "unchecked", "rawtypes" }) |
69 | 13 | public static boolean validates(final Rewrite event, final EvaluationContext context, Validator<?> validator, |
70 | 14 | final Object value) |
|
0 commit comments