You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ja...@apache.org on 2010/01/29 22:02:29 UTC

svn commit: r904621 - in /myfaces/core/trunk: api/src/main/java/javax/faces/validator/ impl/src/main/java/org/apache/myfaces/config/ impl/src/main/java/org/apache/myfaces/util/ impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/

Author: jakobk
Date: Fri Jan 29 21:02:28 2010
New Revision: 904621

URL: http://svn.apache.org/viewvc?rev=904621&view=rev
Log:
MYFACES-2524 Change ExternalSpecifications to enable using it in automated tests

Modified:
    myfaces/core/trunk/api/src/main/java/javax/faces/validator/BeanValidator.java
    myfaces/core/trunk/api/src/main/java/javax/faces/validator/_ExternalSpecifications.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/util/ExternalSpecifications.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/validator/BeanValidator.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/validator/BeanValidator.java?rev=904621&r1=904620&r2=904621&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/validator/BeanValidator.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/validator/BeanValidator.java Fri Jan 29 21:02:28 2010
@@ -184,7 +184,7 @@
      */
     private ValueReferenceWrapper getValueReference(UIComponent component, FacesContext context)
     {
-        if (_ExternalSpecifications.isUnifiedELAvailable)
+        if (_ExternalSpecifications.isUnifiedELAvailable())
         {
             //TODO: Implement when Unified EL for Java EE6 is available.
             throw new FacesException("Unified EL for Java EE6 support is not yet implemented");
@@ -221,7 +221,7 @@
             }
             else
             {
-                if (_ExternalSpecifications.isBeanValidationAvailable)
+                if (_ExternalSpecifications.isBeanValidationAvailable())
                 {
                     ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
                     servletCtx.setAttribute(VALIDATOR_FACTORY_KEY, attr);

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/validator/_ExternalSpecifications.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/validator/_ExternalSpecifications.java?rev=904621&r1=904620&r2=904621&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/validator/_ExternalSpecifications.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/validator/_ExternalSpecifications.java Fri Jan 29 21:02:28 2010
@@ -18,10 +18,11 @@
  */
 package javax.faces.validator;
 
-import javax.validation.Validation;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import javax.validation.Validation;
+
 /**
  * <p>
  * Package-private utility class for determining which specifications are available
@@ -29,71 +30,85 @@
  * </p>
  *
  * @author Jan-Kees van Andel
+ * @author Jakob Korherr (latest modification by $Author$)
+ * @version $Revision$ $Date$
  * @since 2.0
  */
-class _ExternalSpecifications
+final class _ExternalSpecifications
 {
 
     //private static final Log log = LogFactory.getLog(BeanValidator.class);
     private static final Logger log = Logger.getLogger(_ExternalSpecifications.class.getName());
 
+    private static Boolean beanValidationAvailable;
+    private static Boolean unifiedELAvailable;
+
     /**
-     * This boolean indicates if Bean Validation is present.
+     * This method determines if Bean Validation is present.
      *
      * Eager initialization is used for performance. This means Bean Validation binaries
      * should not be added at runtime after this variable has been set.
      */
-    static final boolean isBeanValidationAvailable;
-    static
+    public static boolean isBeanValidationAvailable()
     {
-        boolean tmp = false;
-        try
+        if (beanValidationAvailable == null)
         {
-            tmp = (Class.forName("javax.validation.Validation") != null);
-
-            if (tmp)
+            try
             {
-                try
+                beanValidationAvailable = (Class.forName("javax.validation.Validation") != null);
+    
+                if (beanValidationAvailable)
                 {
-                    // Trial-error approach to check for Bean Validation impl existence.
-                    Validation.buildDefaultValidatorFactory().getValidator();
-                }
-                catch (Throwable t)
-                {
-                    log.log(Level.FINE, "Error initializing Bean Validation (could be normal)", t);
-                    tmp = false;
+                    try
+                    {
+                        // Trial-error approach to check for Bean Validation impl existence.
+                        Validation.buildDefaultValidatorFactory().getValidator();
+                    }
+                    catch (Throwable t)
+                    {
+                        log.log(Level.FINE, "Error initializing Bean Validation (could be normal)", t);
+                        beanValidationAvailable = false;
+                    }
                 }
             }
+            catch (Throwable t)
+            {
+                log.log(Level.FINE, "Error loading class (could be normal)", t);
+                beanValidationAvailable = false;
+            }
         }
-        catch (Throwable t)
-        {
-            log.log(Level.FINE, "Error loading class (could be normal)", t);
-            tmp = false;
-        }
-        isBeanValidationAvailable = tmp;
+        return beanValidationAvailable; 
     }
 
     /**
-     * This boolean indicates if Unified EL is present.
+     * This method determines if Unified EL is present.
      *
      * Eager initialization is used for performance. This means Unified EL binaries
      * should not be added at runtime after this variable has been set.
      */
-    static final boolean isUnifiedELAvailable;
-    static
+    public static boolean isUnifiedELAvailable()
     {
-        boolean tmp = false;
-        try
+        if (unifiedELAvailable == null)
         {
-            //TODO: Check this class name when Unified EL for Java EE6 is final.
-            tmp = (Class.forName("javax.el.ValueReference") != null);
-        }
-        catch (Throwable t)
-        {
-            log.log(Level.FINE, "Error loading class (could be normal)", t);
-            tmp = false;
+            try
+            {
+                //TODO: Check this class name when Unified EL for Java EE6 is final.
+                unifiedELAvailable = (Class.forName("javax.el.ValueReference") != null);
+            }
+            catch (Throwable t)
+            {
+                log.log(Level.FINE, "Error loading class (could be normal)", t);
+                unifiedELAvailable = false;
+            }
         }
-        isUnifiedELAvailable = tmp;
+        return unifiedELAvailable;
+    }
+    
+    /**
+     * this class should not be instantiable.
+     */
+    private _ExternalSpecifications()
+    {
     }
 
 }

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java?rev=904621&r1=904620&r2=904621&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java Fri Jan 29 21:02:28 2010
@@ -1729,7 +1729,7 @@
             {
                 if (validatorId.equals(BeanValidator.VALIDATOR_ID))
                 {
-                    if (!ExternalSpecifications.isBeanValidationAvailable)
+                    if (!ExternalSpecifications.isBeanValidationAvailable())
                     {
                         // do not add it as a default validator
                         continue;
@@ -1743,7 +1743,7 @@
             }
         
             // add the bean validator if it is available, not already added and not disabled
-            if (!beanValidatorAdded && ExternalSpecifications.isBeanValidationAvailable)
+            if (!beanValidatorAdded && ExternalSpecifications.isBeanValidationAvailable())
             {
                 String disabled = _externalContext.getInitParameter(BeanValidator.DISABLE_DEFAULT_BEAN_VALIDATOR_PARAM_NAME);
                 boolean defaultBeanValidatorDisabled = (disabled != null && disabled.toLowerCase().equals("true"));

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/util/ExternalSpecifications.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/util/ExternalSpecifications.java?rev=904621&r1=904620&r2=904621&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/util/ExternalSpecifications.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/util/ExternalSpecifications.java Fri Jan 29 21:02:28 2010
@@ -31,72 +31,85 @@
  * </p>
  *
  * @author Jan-Kees van Andel
- * @author Jakob Korherr
+ * @author Jakob Korherr (latest modification by $Author$)
+ * @version $Revision$ $Date$
  * @since 2.0
  */
-public class ExternalSpecifications
+public final class ExternalSpecifications
 {
 
     //private static final Log log = LogFactory.getLog(BeanValidator.class);
     private static final Logger log = Logger.getLogger(ExternalSpecifications.class.getName());
+    
+    private static Boolean beanValidationAvailable;
+    private static Boolean unifiedELAvailable;
 
     /**
-     * This boolean indicates if Bean Validation is present.
+     * This method determines if Bean Validation is present.
      *
      * Eager initialization is used for performance. This means Bean Validation binaries
      * should not be added at runtime after this variable has been set.
      */
-    public static final boolean isBeanValidationAvailable;
-    static
+    public static boolean isBeanValidationAvailable()
     {
-        boolean tmp = false;
-        try
+        if (beanValidationAvailable == null)
         {
-            tmp = (ClassUtils.classForName("javax.validation.Validation") != null);
-
-            if (tmp)
+            try
             {
-                try
-                {
-                    // Trial-error approach to check for Bean Validation impl existence.
-                    Validation.buildDefaultValidatorFactory().getValidator();
-                }
-                catch (Throwable t)
+                beanValidationAvailable = (ClassUtils.classForName("javax.validation.Validation") != null);
+    
+                if (beanValidationAvailable)
                 {
-                    log.log(Level.FINE, "Error initializing Bean Validation (could be normal)", t);
-                    tmp = false;
+                    try
+                    {
+                        // Trial-error approach to check for Bean Validation impl existence.
+                        Validation.buildDefaultValidatorFactory().getValidator();
+                    }
+                    catch (Throwable t)
+                    {
+                        log.log(Level.FINE, "Error initializing Bean Validation (could be normal)", t);
+                        beanValidationAvailable = false;
+                    }
                 }
             }
+            catch (Throwable t)
+            {
+                log.log(Level.FINE, "Error loading class (could be normal)", t);
+                beanValidationAvailable = false;
+            }
         }
-        catch (Throwable t)
-        {
-            log.log(Level.FINE, "Error loading class (could be normal)", t);
-            tmp = false;
-        }
-        isBeanValidationAvailable = tmp;
+        return beanValidationAvailable; 
     }
 
     /**
-     * This boolean indicates if Unified EL is present.
+     * This method determines if Unified EL is present.
      *
      * Eager initialization is used for performance. This means Unified EL binaries
      * should not be added at runtime after this variable has been set.
      */
-    public static final boolean isUnifiedELAvailable;
-    static
+    public static boolean isUnifiedELAvailable()
     {
-        boolean tmp = false;
-        try
-        {
-            //TODO: Check this class name when Unified EL for Java EE6 is final.
-            tmp = (ClassUtils.classForName("javax.el.ValueReference") != null);
-        }
-        catch (Throwable t)
+        if (unifiedELAvailable == null)
         {
-            log.log(Level.FINE, "Error loading class (could be normal)", t);
-            tmp = false;
+            try
+            {
+                //TODO: Check this class name when Unified EL for Java EE6 is final.
+                unifiedELAvailable = (ClassUtils.classForName("javax.el.ValueReference") != null);
+            }
+            catch (Throwable t)
+            {
+                log.log(Level.FINE, "Error loading class (could be normal)", t);
+                unifiedELAvailable = false;
+            }
         }
-        isUnifiedELAvailable = tmp;
+        return unifiedELAvailable;
+    }
+    
+    /**
+     * this class should not be instantiable.
+     */
+    private ExternalSpecifications()
+    {
     }
 
 }

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java?rev=904621&r1=904620&r2=904621&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java Fri Jan 29 21:02:28 2010
@@ -648,7 +648,7 @@
         // Some extra rules are required for Bean Validation.
         if (validatorId.equals(BeanValidator.VALIDATOR_ID))
         {
-            if (!ExternalSpecifications.isBeanValidationAvailable)
+            if (!ExternalSpecifications.isBeanValidationAvailable())
             {
                 return false;
             }