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
24 /**
25 * <p>
26 * Package-private utility class for determining which specifications are available
27 * in the current process. See JIRA issue: http://issues.apache.org/jira/browse/MYFACES-2386
28 * </p>
29 *
30 * @author Jan-Kees van Andel
31 * @since 2.0
32 */
33 final class _ExternalSpecifications
34 {
35
36 //private static final Log log = LogFactory.getLog(BeanValidator.class);
37 private static final Logger log = Logger.getLogger(_ExternalSpecifications.class.getName());
38
39 private static volatile Boolean beanValidationAvailable;
40 //private static volatile Boolean unifiedELAvailable;
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 if (beanValidationAvailable == null)
52 {
53 try
54 {
55 try
56 {
57 beanValidationAvailable = (Class.forName("javax.validation.Validation") != null);
58 }
59 catch (ClassNotFoundException e)
60 {
61 beanValidationAvailable = Boolean.FALSE;
62 }
63
64 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 _ValidationUtils.tryBuildDefaultValidatorFactory();
72 }
73 catch (Throwable t)
74 {
75 log.log(Level.FINE, "Error initializing Bean Validation (could be normal)", t);
76 beanValidationAvailable = false;
77 }
78 }
79 }
80 catch (Throwable t)
81 {
82 log.log(Level.FINE, "Error loading class (could be normal)", t);
83 beanValidationAvailable = false;
84 }
85
86 log.info("MyFaces Bean Validation support " + (beanValidationAvailable ? "enabled" : "disabled"));
87 }
88 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 /**
126 * this class should not be instantiated.
127 */
128 private _ExternalSpecifications()
129 {
130 }
131
132 }