Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
_ExternalSpecifications |
|
| 5.333333333333333;5.333 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one | |
3 | * or more contributor license agreements. See the NOTICE file | |
4 | * distributed with this work for additional information | |
5 | * regarding copyright ownership. The ASF licenses this file | |
6 | * to you under the Apache License, Version 2.0 (the | |
7 | * "License"); you may not use this file except in compliance | |
8 | * with the License. You may obtain a copy of the License at | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
12 | * Unless required by applicable law or agreed to in writing, | |
13 | * software distributed under the License is distributed on an | |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
15 | * KIND, either express or implied. See the License for the | |
16 | * specific language governing permissions and limitations | |
17 | * under the License. | |
18 | */ | |
19 | package javax.faces.component; | |
20 | ||
21 | import java.util.logging.Level; | |
22 | import java.util.logging.Logger; | |
23 | import javax.faces.context.ExternalContext; | |
24 | ||
25 | /** | |
26 | * <p> | |
27 | * Package-private utility class for determining which specifications are available | |
28 | * in the current process. See JIRA issue: http://issues.apache.org/jira/browse/MYFACES-2386 | |
29 | * </p> | |
30 | * @since 2.0 | |
31 | */ | |
32 | final class _ExternalSpecifications | |
33 | { | |
34 | ||
35 | //private static final Log log = LogFactory.getLog(BeanValidator.class); | |
36 | 2 | private static final Logger log = Logger.getLogger(_ExternalSpecifications.class.getName()); |
37 | ||
38 | private static volatile Boolean beanValidationAvailable; | |
39 | //private static volatile Boolean unifiedELAvailable; | |
40 | private static volatile Boolean cdiAvailable; | |
41 | ||
42 | /** | |
43 | * This method determines if Bean Validation is present. | |
44 | * | |
45 | * Eager initialization is used for performance. This means Bean Validation binaries | |
46 | * should not be added at runtime after this variable has been set. | |
47 | * @return true if Bean Validation is available, false otherwise. | |
48 | */ | |
49 | public static boolean isBeanValidationAvailable() | |
50 | { | |
51 | 34 | if (beanValidationAvailable == null) |
52 | { | |
53 | try | |
54 | { | |
55 | try | |
56 | { | |
57 | 2 | beanValidationAvailable = (Class.forName("javax.validation.Validation") != null); |
58 | } | |
59 | 0 | catch (ClassNotFoundException e) |
60 | { | |
61 | 0 | beanValidationAvailable = Boolean.FALSE; |
62 | 2 | } |
63 | ||
64 | 2 | if (beanValidationAvailable) |
65 | { | |
66 | try | |
67 | { | |
68 | // Trial-error approach to check for Bean Validation impl existence. | |
69 | // If any Exception occurs here, we assume that Bean Validation is not available. | |
70 | // The cause may be anything, i.e. NoClassDef, config error... | |
71 | 2 | _ValidationUtils.tryBuildDefaultValidatorFactory(); |
72 | } | |
73 | 2 | catch (Throwable t) |
74 | { | |
75 | 2 | log.log(Level.FINE, "Error initializing Bean Validation (could be normal)", t); |
76 | 2 | beanValidationAvailable = false; |
77 | 0 | } |
78 | } | |
79 | } | |
80 | 0 | catch (Throwable t) |
81 | { | |
82 | 0 | log.log(Level.FINE, "Error loading class (could be normal)", t); |
83 | 0 | beanValidationAvailable = false; |
84 | 2 | } |
85 | ||
86 | 2 | log.info("MyFaces Bean Validation support " + (beanValidationAvailable ? "enabled" : "disabled")); |
87 | } | |
88 | 34 | return beanValidationAvailable; |
89 | } | |
90 | ||
91 | /** | |
92 | * This method determines if Unified EL is present. | |
93 | * | |
94 | * Eager initialization is used for performance. This means Unified EL binaries | |
95 | * should not be added at runtime after this variable has been set. | |
96 | * @return true if UEL is available, false otherwise. | |
97 | */ | |
98 | /* | |
99 | public static boolean isUnifiedELAvailable() | |
100 | { | |
101 | if (unifiedELAvailable == null) | |
102 | { | |
103 | try | |
104 | { | |
105 | // Check if the UEL classes are available. | |
106 | // If the JSP EL classes are loaded first, UEL will not work | |
107 | // properly, hence it will be disabled. | |
108 | unifiedELAvailable = ( | |
109 | Class.forName("javax.el.ValueReference") != null | |
110 | && Class.forName("javax.el.ValueExpression") | |
111 | .getMethod("getValueReference", ELContext.class) != null | |
112 | ); | |
113 | } | |
114 | catch (Throwable t) | |
115 | { | |
116 | log.log(Level.FINE, "Error loading class (could be normal)", t); | |
117 | unifiedELAvailable = false; | |
118 | } | |
119 | ||
120 | log.info("MyFaces Unified EL support " + (unifiedELAvailable ? "enabled" : "disabled")); | |
121 | } | |
122 | return unifiedELAvailable; | |
123 | }*/ | |
124 | ||
125 | public static boolean isCDIAvailable(ExternalContext externalContext) | |
126 | { | |
127 | 0 | if (cdiAvailable == null) |
128 | { | |
129 | try | |
130 | { | |
131 | 0 | cdiAvailable = Class.forName("javax.enterprise.inject.spi.BeanManager") != null; |
132 | } | |
133 | 0 | catch (Throwable t) |
134 | { | |
135 | //log.log(Level.FINE, "Error loading class (could be normal)", t); | |
136 | 0 | cdiAvailable = false; |
137 | 0 | } |
138 | ||
139 | 0 | if (cdiAvailable) |
140 | { | |
141 | 0 | cdiAvailable = externalContext.getApplicationMap().containsKey( |
142 | "oam.cdi.BEAN_MANAGER_INSTANCE"); | |
143 | } | |
144 | ||
145 | 0 | log.info("MyFaces CDI support " + (cdiAvailable ? "enabled" : "disabled")); |
146 | ||
147 | 0 | return cdiAvailable; |
148 | } | |
149 | else | |
150 | { | |
151 | 0 | if (Boolean.TRUE.equals(cdiAvailable)) |
152 | { | |
153 | 0 | return externalContext.getApplicationMap().containsKey( |
154 | "oam.cdi.BEAN_MANAGER_INSTANCE"); | |
155 | } | |
156 | 0 | return cdiAvailable; |
157 | } | |
158 | } | |
159 | ||
160 | /** | |
161 | * this class should not be instantiated. | |
162 | */ | |
163 | private _ExternalSpecifications() | |
164 | 0 | { |
165 | 0 | } |
166 | ||
167 | } |