1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.tobago.util;
21
22 import javax.faces.application.Application;
23
24 public enum FacesVersion {
25
26 VERSION_11,
27 VERSION_12,
28 VERSION_20,
29 VERSION_21;
30
31 private static FacesVersion currentVersion;
32 private static boolean mojarra;
33 private static boolean myfaces;
34
35 static {
36 try {
37 currentVersion = VERSION_11;
38 Application.class.getMethod("getExpressionFactory");
39 currentVersion = VERSION_12;
40 Application.class.getMethod("getDefaultValidatorInfo");
41 currentVersion = VERSION_20;
42 Application.class.getMethod("getExceptionHandler");
43 currentVersion = VERSION_21;
44 } catch (NoSuchMethodException e) {
45
46 }
47
48 mojarra = isAvailable("com.sun.faces.application.ApplicationImpl");
49 myfaces = isAvailable("org.apache.myfaces.application.ApplicationImpl");
50
51 }
52
53 private static boolean isAvailable(String className) {
54 try {
55 try {
56 Class.forName(className, false, Thread.currentThread().getContextClassLoader());
57 return true;
58 } catch (ClassNotFoundException e) {
59
60 try {
61 Class.forName(className, false, FacesVersion.class.getClassLoader());
62 return true;
63 } catch (ClassNotFoundException e1) {
64
65 }
66 }
67 } catch (Exception e) {
68
69 }
70 return false;
71 }
72
73
74
75
76
77 public static boolean supports12() {
78 return currentVersion == VERSION_12 || currentVersion == VERSION_20 || currentVersion == VERSION_21;
79 }
80
81
82
83
84
85 public static boolean supports20() {
86 return currentVersion == VERSION_20 || currentVersion == VERSION_21;
87 }
88
89
90
91
92
93 public static boolean supports21() {
94 return currentVersion == VERSION_21;
95 }
96
97 public static boolean isMojarra() {
98 return mojarra;
99 }
100
101 public static boolean isMyfaces() {
102 return myfaces;
103 }
104 }