1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package javax.faces.internal; |
17 | |
|
18 | |
import javax.faces.application.FacesMessage; |
19 | |
import javax.faces.component.UIComponent; |
20 | |
import javax.faces.context.FacesContext; |
21 | |
import javax.faces.convert.Converter; |
22 | |
import javax.faces.convert.ConverterException; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | 0 | public class ConvertUtil { |
31 | |
|
32 | |
public static ConverterException wrappedByConverterException() { |
33 | 0 | return new ConverterException(); |
34 | |
} |
35 | |
|
36 | |
public static ConverterException wrappedByConverterException(String message) { |
37 | 0 | return new ConverterException(message); |
38 | |
} |
39 | |
|
40 | |
public static ConverterException wrappedByConverterException(Throwable t) { |
41 | 0 | return wrappedByConverterException(null, t); |
42 | |
} |
43 | |
|
44 | |
public static ConverterException wrappedByConverterException( |
45 | |
String message, Throwable t) { |
46 | 0 | return new ConverterException(message, t); |
47 | |
} |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
public static ConverterException wrappedByConverterException( |
53 | |
Converter converter, FacesContext context, Object[] args) { |
54 | 0 | return wrappedByConverterException(converter, context, args, null); |
55 | |
} |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
public static ConverterException wrappedByConverterException( |
61 | |
Converter converter, FacesContext context, Object[] args, |
62 | |
Throwable t) { |
63 | 2 | FacesMessage facesMessage = null; |
64 | 4 | for (Class c = converter.getClass(); c != null && c != Object.class; c = c |
65 | |
.getSuperclass()) { |
66 | 3 | String conversionMessage = createConversionMessage(c); |
67 | 3 | facesMessage = FacesMessageUtil.getMessage(context, |
68 | |
conversionMessage, args); |
69 | 3 | if (facesMessage.getSummary() != null |
70 | |
|| facesMessage.getDetail() != null) { |
71 | 0 | break; |
72 | |
} |
73 | |
} |
74 | 2 | return new ConverterException(facesMessage, t); |
75 | |
} |
76 | |
|
77 | |
public static String createConversionMessage(Class c) { |
78 | 3 | return c.getName() + ".CONVERSION"; |
79 | |
} |
80 | |
|
81 | |
public static String createConversionMessage(Converter converter) { |
82 | 1 | return converter.getClass().getName() + ".CONVERSION"; |
83 | |
} |
84 | |
|
85 | |
public static Object[] createExceptionMessageArgs(UIComponent component, |
86 | |
Object value) { |
87 | 39 | return new Object[] { UIComponentUtil.getLabel(component), value }; |
88 | |
} |
89 | |
} |