1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.util;
20
21 import java.util.logging.Level;
22 import java.util.logging.Logger;
23
24 import javax.el.ELContext;
25 import javax.faces.context.ExternalContext;
26 import org.apache.myfaces.webapp.AbstractFacesInitializer;
27
28
29
30
31
32
33
34
35
36
37
38
39 public final class ExternalSpecifications
40 {
41
42
43 private static final Logger log = Logger.getLogger(ExternalSpecifications.class.getName());
44
45 private static volatile Boolean beanValidationAvailable;
46 private static volatile Boolean unifiedELAvailable;
47 private static volatile Boolean cdiAvailable;
48 private static volatile Boolean el3Available;
49
50
51
52
53
54
55
56
57 public static boolean isBeanValidationAvailable()
58 {
59 if (beanValidationAvailable == null)
60 {
61 try
62 {
63 try
64 {
65 beanValidationAvailable = (Class.forName("javax.validation.Validation") != null);
66 }
67 catch(ClassNotFoundException e)
68 {
69 beanValidationAvailable = Boolean.FALSE;
70 }
71
72 if (beanValidationAvailable)
73 {
74 try
75 {
76
77
78
79 _ValidationUtils.tryBuildDefaultValidatorFactory();
80 }
81 catch (Throwable t)
82 {
83
84 beanValidationAvailable = false;
85 }
86 }
87 }
88 catch (Throwable t)
89 {
90 log.log(Level.FINE, "Error loading class (could be normal)", t);
91 beanValidationAvailable = false;
92 }
93
94 log.info("MyFaces Bean Validation support " + (beanValidationAvailable ? "enabled" : "disabled"));
95 }
96 return beanValidationAvailable;
97 }
98
99
100
101
102
103
104
105
106 public static boolean isUnifiedELAvailable()
107 {
108 if (unifiedELAvailable == null)
109 {
110 try
111 {
112
113
114
115 unifiedELAvailable = (
116 Class.forName("javax.el.ValueReference") != null
117 && Class.forName("javax.el.ValueExpression")
118 .getMethod("getValueReference", ELContext.class) != null
119 );
120 }
121 catch (Throwable t)
122 {
123
124 unifiedELAvailable = false;
125 }
126
127 log.info("MyFaces Unified EL support " + (unifiedELAvailable ? "enabled" : "disabled"));
128 }
129 return unifiedELAvailable;
130 }
131
132 public static boolean isCDIAvailable(ExternalContext externalContext)
133 {
134 if (cdiAvailable == null)
135 {
136 try
137 {
138 cdiAvailable = Class.forName("javax.enterprise.inject.spi.BeanManager") != null;
139 }
140 catch (Throwable t)
141 {
142
143 cdiAvailable = false;
144 }
145
146 log.info("MyFaces CDI support " + (cdiAvailable ? "enabled" : "disabled"));
147 }
148
149 return cdiAvailable &&
150 externalContext.getApplicationMap().containsKey(AbstractFacesInitializer.CDI_BEAN_MANAGER_INSTANCE);
151 }
152
153 public static boolean isEL3Available()
154 {
155 if (el3Available == null)
156 {
157 try
158 {
159 el3Available = Class.forName("javax.el.StaticFieldELResolver") != null ;
160 }
161 catch (Throwable t)
162 {
163 el3Available = false;
164 }
165 log.info("MyFaces EL 3.0 support " + (el3Available ? "enabled" : "disabled"));
166 }
167 return el3Available;
168 }
169
170
171
172
173 private ExternalSpecifications()
174 {
175 }
176
177 }