Coverage Report - javax.faces.validator._ExternalSpecifications
 
Classes in this File Line Coverage Branch Coverage Complexity
_ExternalSpecifications
0%
0/26
0%
0/12
3.667
 
 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.validator;
 20  
 
 21  
 import java.util.logging.Level;
 22  
 import java.util.logging.Logger;
 23  
 
 24  
 import javax.el.ELContext;
 25  
 
 26  
 /**
 27  
  * <p>
 28  
  * Package-private utility class for determining which specifications are available
 29  
  * in the current process. See JIRA issue: http://issues.apache.org/jira/browse/MYFACES-2386
 30  
  * </p>
 31  
  *
 32  
  * @since 2.0
 33  
  */
 34  
 final class _ExternalSpecifications
 35  
 {
 36  
 
 37  
     //private static final Log log = LogFactory.getLog(BeanValidator.class);
 38  0
     private static final Logger log = Logger.getLogger(_ExternalSpecifications.class.getName());
 39  
 
 40  
     private static volatile Boolean beanValidationAvailable;
 41  
     private static volatile Boolean unifiedELAvailable;
 42  
 
 43  
     /**
 44  
      * This method determines if Bean Validation is present.
 45  
      *
 46  
      * Eager initialization is used for performance. This means Bean Validation binaries
 47  
      * should not be added at runtime after this variable has been set.
 48  
      * @return true if Bean Validation is available, false otherwise.
 49  
      */
 50  
     public static boolean isBeanValidationAvailable()
 51  
     {
 52  0
         if (beanValidationAvailable == null)
 53  
         {
 54  
             try
 55  
             {
 56  
                 try
 57  
                 {
 58  0
                     beanValidationAvailable = (Class.forName("javax.validation.Validation") != null);
 59  
                 }
 60  0
                 catch(ClassNotFoundException e)
 61  
                 {
 62  0
                     beanValidationAvailable = Boolean.FALSE;
 63  0
                 }
 64  
     
 65  0
                 if (beanValidationAvailable)
 66  
                 {
 67  
                     try
 68  
                     {
 69  
                         // Trial-error approach to check for Bean Validation impl existence.
 70  
                         // If any Exception occurs here, we assume that Bean Validation is not available.
 71  
                         // The cause may be anything, i.e. NoClassDef, config error...
 72  0
                         _ValidationUtils.tryBuildDefaultValidatorFactory();
 73  
                     }
 74  0
                     catch (Throwable t)
 75  
                     {
 76  0
                         log.log(Level.FINE, "Error initializing Bean Validation (could be normal)", t);
 77  0
                         beanValidationAvailable = false;
 78  0
                     }
 79  
                 }
 80  
             }
 81  0
             catch (Throwable t)
 82  
             {
 83  0
                 log.log(Level.FINE, "Error loading class (could be normal)", t);
 84  0
                 beanValidationAvailable = false;
 85  0
             }
 86  
 
 87  
             //log.info("MyFaces Bean Validation support " + (beanValidationAvailable ? "enabled" : "disabled"));
 88  
         }
 89  0
         return beanValidationAvailable; 
 90  
     }
 91  
 
 92  
     /**
 93  
      * This method determines if Unified EL is present.
 94  
      *
 95  
      * Eager initialization is used for performance. This means Unified EL binaries
 96  
      * should not be added at runtime after this variable has been set.
 97  
      * @return true if UEL is available, false otherwise.
 98  
      */
 99  
     public static boolean isUnifiedELAvailable()
 100  
     {
 101  0
         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  0
                 unifiedELAvailable = (
 109  
                         Class.forName("javax.el.ValueReference") != null
 110  
                      && Class.forName("javax.el.ValueExpression")
 111  
                                 .getMethod("getValueReference", ELContext.class) != null
 112  
                 );
 113  
             }
 114  0
             catch (Throwable t)
 115  
             {
 116  0
                 log.log(Level.FINE, "Error loading class (could be normal)", t);
 117  0
                 unifiedELAvailable = false;
 118  0
             }
 119  
 
 120  
             //log.info("MyFaces Unified EL support " + (unifiedELAvailable ? "enabled" : "disabled"));
 121  
         }
 122  0
         return unifiedELAvailable;
 123  
     }
 124  
     
 125  
     /**
 126  
      * this class should not be instantiated.
 127  
      */
 128  
     private _ExternalSpecifications()
 129  0
     {
 130  0
     }
 131  
 
 132  
 }